blob: 6412022e0c68d69b6ecc675e427657d12b31171f [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;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
87 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070088 integer mp_trx1_arfcn := 873;
89 integer mp_trx2_arfcn := 875;
90 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_tolerance_rxqual := 1;
99 integer mp_tolerance_rxlev := 3;
100 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200101 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200102 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200103 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200104 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
105 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200106 integer mp_ms_actual_ta_exp := 0;
107 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100108 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200109 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200110 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200111 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
112 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700113 /* how many transceivers do we expect to connect */
114 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700115 /* frequency hopping status */
116 boolean mp_freq_hop_enabled := false;
117 /* frequency hopping parameters */
118 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100119}
120
Harald Welte629cc6b2018-03-11 17:19:05 +0100121type record of RslChannelNr ChannelNrs;
122
Harald Welte70767382018-02-21 12:16:40 +0100123type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100124 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100125 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100127 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100129 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100130
131 /* L1CTL port (for classic tests) */
132 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100133
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700134 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700135 port TRXC_CODEC_PT BTS_TRXC;
136 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100137
Harald Weltef50e3ae2018-09-10 10:27:56 +0200138 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100139 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100141
Harald Welte883340c2018-02-28 18:59:29 +0100142 /* PCU Interface of BTS */
143 port PCUIF_CODEC_PT PCU;
144 var integer g_pcu_conn_id;
145 /* Last PCU INFO IND we received */
146 var PCUIF_Message g_pcu_last_info;
147
Harald Welte48494ca2018-02-25 16:59:50 +0100148 /* SI configuration */
149 var SystemInformationConfig si_cfg := {
150 bcch_extended := false,
151 si1_present := false,
152 si2bis_present := false,
153 si2ter_present := false,
154 si2quater_present := false,
155 si7_present := false,
156 si8_present := false,
157 si9_present := false,
158 si13_present := false,
159 si13alt_present := false,
160 si15_present := false,
161 si16_present := false,
162 si17_present := false,
163 si2n_present := false,
164 si21_present := false,
165 si22_present := false
166 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100167
168 /* all logical channels available on the BTS */
169 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100170 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100171}
172
173/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200174type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100175 port L1CTL_PT L1CTL;
176
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700177 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700178 port TRXC_CODEC_PT BTS_TRXC;
179 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100180
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200181 /* port to be initialized optionally to access BSC VTY */
182 port TELNETasp_PT BSCVTY;
183
Harald Welte70767382018-02-21 12:16:40 +0100184 timer g_Tguard;
185 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
186
187 var ConnHdlrPars g_pars;
188 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100189 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200190
191 /* PCU Interface of BTS */
192 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100193}
194
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700195private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700196 var bitstring trx_mask := '00000000'B;
197 var integer trx_count := 0;
198 var RSLEm_Event ev;
199 timer T;
200
Harald Welte70767382018-02-21 12:16:40 +0100201 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
202 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
203
204 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
205 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
206 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
207
208 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
209 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700210
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700211 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700212 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700213 T.start(mp_ipa_up_timeout);
214 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700215 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
217 /* Make sure that all transceivers use unique stream ID */
218 if (trx_mask[enum2int(ev.sid)] == '1'B) {
219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
220 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
221 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700222
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 /* This message (RF RESource INDication) is sent by the IUT itself */
224 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
225 trx_mask[enum2int(ev.sid)] := '1'B;
226 trx_count := trx_count + 1;
227
228 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
229 if (trx_count < mp_transceiver_num) { repeat; }
230 }
231 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
232 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
233 [] T.timeout {
234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
235 "Timeout waiting for RSL bring up");
236 }
237 }
Harald Welte70767382018-02-21 12:16:40 +0100238}
239
240type record ConnHdlrPars {
241 RslChannelNr chan_nr,
242 RSL_IE_ChannelMode chan_mode,
243 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100244 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200245 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200246 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700247 BtsBand bts0_band optional,
248
249 /* Frequency hopping parameters (disabled if absent) */
250 MaioHsn maio_hsn optional,
251 /* MA bitmap to be indicated in RR Immediate Assignment */
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700252 MobileAllocationLV ma_map,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700253 /* The actual Mobile Allocation (ARFCN list) to be used */
254 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100255}
256
257/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700258private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100259 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100260}
261
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700262private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100263 max_retrans := RACH_MAX_RETRANS_7,
264 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100265 cell_barr_access := false,
266 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100267 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100268};
269
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700270private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100271 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200272 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100273 acs := '0'B,
274 neci := true,
275 rxlev_access_min := 0
276}
277
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700278private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100279 mcc_mnc := '262F42'H,
280 lac := 42
281}
282
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700283private template (value) GPRSIndicator ts_GPRSIndicator_def := {
284 ra_colour := 0,
285 si13_pos := '0'B
286}
287
288private template (value) SI3RestOctets ts_SI3RestOctets_def
289modifies ts_SI3RestOctets := {
290 gprs_ind := {
291 presence := CSN1_H,
292 ind := ts_GPRSIndicator_def
293 }
294}
295
296private template (value) SI4RestOctets ts_SI4RestOctets_def
297modifies ts_SI4RestOctets := {
298 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700299 presence := CSN1_H,
300 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700301 }
302}
303
Harald Welte7484fc42018-02-24 14:09:45 +0100304/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700305private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100306 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100307 payload := {
308 si3 := {
309 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100310 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100311 ctrl_chan_desc := {
312 msc_r99 := true,
313 att := true,
314 bs_ag_blks_res := 1,
315 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100316 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100317 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
318 spare := '00'B,
319 bs_pa_mfrms := 0, /* 2 multiframes */
320 t3212 := 1 /* 6 minutes */
321 },
Harald Welte82ccef72018-02-25 16:17:33 +0100322 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100323 dn_ind := false,
324 pwrc := false,
325 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100326 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100327 },
Harald Weltef10153f2018-02-25 16:34:05 +0100328 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100329 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200330 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100331 }
332 }
333}
Harald Welte70767382018-02-21 12:16:40 +0100334
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700335private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100336 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100337 payload := {
338 si2 := {
339 bcch_freq_list := '00000000000000000000000000000000'O,
340 ncc_permitted := '11111111'B,
341 rach_control := ts_RachCtrl_default
342 }
343 }
344}
345
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700346private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100347 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100348 payload := {
349 si4 := {
350 lai := ts_LAI_default,
351 cell_sel_par := ts_CellSelPar_default,
352 rach_control := ts_RachCtrl_default,
353 cbch_chan_desc := omit,
354 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200355 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100356 }
357 }
358}
359
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700360private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100361runs on test_CT {
362 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700363 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100364}
365
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700366private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100367runs on test_CT {
368 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
369 log("Setting ", rsl_si_type, ": ", si_dec);
370 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
371}
372
Harald Welte505cf9b2018-09-15 17:47:23 +0300373friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100374 map(self:BTSVTY, system:BTSVTY);
375 f_vty_set_prompts(BTSVTY);
376 f_vty_transceive(BTSVTY, "enable");
377}
378
Harald Welte505cf9b2018-09-15 17:47:23 +0300379friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200380 map(self:BSCVTY, system:BSCVTY);
381 f_vty_set_prompts(BSCVTY, "OsmoBSC");
382 f_vty_transceive(BSCVTY, "enable");
383}
384
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200385friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
386 map(self:BSCVTY, system:BSCVTY);
387 f_vty_set_prompts(BSCVTY, "OsmoBSC");
388 f_vty_transceive(BSCVTY, "enable");
389}
390
Harald Welte883340c2018-02-28 18:59:29 +0100391/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200392private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
393 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100394 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200395 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
396 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100397 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200398 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100400 }
401}
402
Harald Weltef26de0b2018-04-04 20:28:05 +0200403private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
404 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100405 timer T := 2.0;
406 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100407 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200408 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100409 return;
410 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200411 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100412
413 T.start;
414 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200415 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100416 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100418 }
419 }
420}
421
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700422private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
423 out integer trxc_conn_id) {
424 var Result res;
425
426 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
427 "", -1, -1, { udp := {} }, {});
428 if (not ispresent(res.connId)) {
429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
430 "Could not connect to the control (TRXC) interface " &
431 "of FakeTRX, check your configuration");
432 }
433 trxc_conn_id := res.connId;
434}
435
Harald Welte70767382018-02-21 12:16:40 +0100436/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700437friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200438 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100439 g_AllChannels := {
440 /* TS 1..4: TCH/F */
441 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
442 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
443 /* TS 5: TCH/H */
444 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
445 /* TS 0: SDCCH/4 */
446 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
447 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
448 /* TS 6: SDCCH/8 */
449 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
450 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
451 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
452 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
453 };
454
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200455 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700456 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200457 g_AllChanTypes := {
458 /* TS 1..4: TCH/F */
459 valueof(ts_RslChanNr_Bm(1)),
460 /* TS 5: TCH/H */
461 valueof(ts_RslChanNr_Lm(5,1)),
462 /* TS 0: SDCCH/4 */
463 valueof(ts_RslChanNr_SDCCH4(0,2)),
464 /* TS 6: SDCCH/8 */
465 valueof(ts_RslChanNr_SDCCH8(6,4))
466 };
467 } else {
468 g_AllChanTypes := {
469 /* TS 1..4: TCH/F */
470 valueof(ts_RslChanNr_Bm(1)),
471 /* TS 0: SDCCH/4 */
472 valueof(ts_RslChanNr_SDCCH4(0,2)),
473 /* TS 6: SDCCH/8 */
474 valueof(ts_RslChanNr_SDCCH8(6,4))
475 };
476 }
Harald Welte70767382018-02-21 12:16:40 +0100477 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100478 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100479 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200480 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100481
482 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100483 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
484 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
485 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
486 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100487
Harald Weltef26de0b2018-04-04 20:28:05 +0200488 map(self:PCU, system:PCU);
489 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100490
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700491 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100492 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700493
494 /* Init TRXC interface to FakeTRX */
495 map(self:BTS_TRXC, system:BTS_TRXC);
496 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
497
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700498 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700499 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700500 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700501 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
502 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100503 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200504
505 /* Wait some extra time to make sure the BTS emits a stable carrier.
506 * (this is only relevant when running the tests with a physical BTS.) */
507 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100508}
509
Harald Welte68e495b2018-02-25 00:05:57 +0100510/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700511friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100512 map(self:L1CTL, system:L1CTL);
513 f_connect_reset(L1CTL);
514}
515
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700516private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100517
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700518private type record length(8) of FreqHopGroups FreqHopConfig;
519
520private type record of FreqHopGroup FreqHopGroups;
521private type record FreqHopGroup {
522 uint6_t hsn,
523 FreqHopGroupItems trx_maio
524};
525
526private type record of FreqHopGroupItem FreqHopGroupItems;
527private type record FreqHopGroupItem {
528 uint8_t trx_nr,
529 uint6_t maio
530};
531
532friend function f_resolve_fh_params(inout ConnHdlrPars pars, uint8_t trx_nr := 0)
533{
534 var FreqHopGroups groups := mp_fh_config[pars.chan_nr.tn];
535 var integer i, j;
536
537 for (i := 0; i < lengthof(groups); i := i + 1) {
538 var FreqHopGroup g := groups[i];
539 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
540 var FreqHopGroupItem gi := g.trx_maio[j];
541 if (gi.trx_nr == trx_nr) {
542 pars.maio_hsn := valueof(ts_HsnMaio(g.hsn, gi.maio));
543 pars.ma := { }; /* to be composed below */
544 break;
545 }
546 }
547
548 if (ispresent(pars.maio_hsn)) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700549 /* Prepare the Mobile Allocation bitmask (length & padding) */
550 pars.ma_map.len := mp_transceiver_num / 8;
551 if (mp_transceiver_num mod 8 > 0)
552 { pars.ma_map.len := pars.ma_map.len + 1; }
553 pars.ma_map.ma := f_pad_bit('0'B, pars.ma_map.len * 8, '0'B);
554
555 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700556 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
557 var FreqHopGroupItem gi := g.trx_maio[j];
558 pars.ma := pars.ma & { l1ctl_ma_def[gi.trx_nr] };
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700559 pars.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560 }
561
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700562 log("Freq. hopping parameters: maio_hsn := ", pars.maio_hsn,
563 ", ma := ", pars.ma, ", ma_map := ", pars.ma_map);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700564 break; /* We're done */
565 }
566 }
567}
568
Harald Welte70767382018-02-21 12:16:40 +0100569/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700570friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
571 boolean pcu_comp := false,
572 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100573runs on test_CT return ConnHdlr {
574 var charstring id := testcasename();
575 var ConnHdlr vc_conn;
576
577 vc_conn := ConnHdlr.create(id);
578 /* connect to RSL Emulation main component */
579 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
580 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700581
582 /* The ConnHdlr component may want to talk to some ports directly,
583 * so we disconnect it from the test_CT and connect it to the component.
584 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200585 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200586 unmap(self:PCU, system:PCU);
587 map(vc_conn:PCU, system:PCU);
588 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700589 if (trxc_comp) {
590 unmap(self:BTS_TRXC, system:BTS_TRXC);
591 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
592 }
Harald Welte70767382018-02-21 12:16:40 +0100593
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700594 /* Obtain frequency hopping parameters for a given timeslot */
595 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
596 f_resolve_fh_params(pars);
597 }
598
Harald Welte70767382018-02-21 12:16:40 +0100599 vc_conn.start(f_handler_init(fn, id, pars));
600 return vc_conn;
601}
602
Harald Welte70767382018-02-21 12:16:40 +0100603private altstep as_Tguard() runs on ConnHdlr {
604 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100606 }
607}
608
Harald Welte990a3612019-05-27 14:02:13 +0200609friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
610 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100611}
612
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700613private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100614 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700615 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100616}
617
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700618private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100619 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700620 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100621}
622
623/* first function started in ConnHdlr component */
624private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
625runs on ConnHdlr {
626 g_pars := pars;
627 g_chan_nr := pars.chan_nr;
628
629 map(self:L1CTL, system:L1CTL);
630 f_connect_reset(L1CTL);
631
Harald Welted48c0c72019-06-05 10:01:15 +0200632 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700633 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100634 }
Harald Welte70767382018-02-21 12:16:40 +0100635
636 g_Tguard.start(pars.t_guard);
637 activate(as_Tguard());
638
639 f_rslem_register(0, pars.chan_nr);
640
641 /* call the user-supplied test case function */
642 fn.apply(id);
643}
644
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700645private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
646 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200647runs on ConnHdlr return RSL_Message {
648 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100649 timer T := 3.0;
650 RSL.send(tx);
651 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100652 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200653 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100654 T.stop;
655 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100656 }
Harald Welte1eba3742018-02-25 12:48:14 +0100657 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100659 }
Harald Welte21240e62018-03-11 21:43:35 +0100660 [not ignore_other] as_l1_sacch();
661 [not ignore_other] as_meas_res();
662 [not ignore_other] as_l1_dcch();
663 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100665 }
Harald Welte21240e62018-03-11 21:43:35 +0100666 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100667 }
Harald Welteb1726c92018-03-30 11:56:38 +0200668 return rx;
669}
670
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700671friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
672 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200673runs on ConnHdlr {
674 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100675}
676
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700677friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
678 boolean encr_enable := false,
679 RSL_IE_List more_ies := {},
680 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
681runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200682 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200683 if (encr_enable) {
684 /* append encryption related IEs, if requested */
685 var RSL_IE_EncryptionInfo encr_info;
686 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
687 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
688encr_info})) };
689 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200690 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200691 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100692}
693
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700694friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100695 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 +0100696 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100697}
698
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700699/* Default Mobile Allocation to be used for frequency hopping */
700private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
701 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
702
Harald Welte2f2b2b72019-05-31 22:24:57 +0200703friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100704 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700705 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100706 float t_guard := 20.0) := {
707 chan_nr := valueof(chan_nr),
708 chan_mode := valueof(chan_mode),
709 t_guard := t_guard,
710 l1_pars := {
711 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100712 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100713 meas_ul := {
714 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200715 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100716 rxqual := 0
717 },
718 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200719 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100720 rxqual := 0
721 }
722 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200723 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100724 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200725 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200726 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100727 },
Harald Weltee613f962018-04-18 22:38:16 +0200728 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200729 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700730 bts0_band := omit,
731 maio_hsn := maio_hsn,
732 ma_map := c_MA_null,
733 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100734}
735
Harald Welte93640c62018-02-25 16:59:33 +0100736/***********************************************************************
737 * Channel Activation / Deactivation
738 ***********************************************************************/
739
Harald Welte70767382018-02-21 12:16:40 +0100740/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700741private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100742 for (var integer i := 0; i < 500; i := i+1) {
743 f_rsl_chan_act(g_pars.chan_mode);
744 f_rsl_chan_deact();
745 }
746 setverdict(pass);
747}
748testcase TC_chan_act_stress() runs on test_CT {
749 var ConnHdlr vc_conn;
750 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200751 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100752 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
753 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100755}
756
757/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700758private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100759 f_rsl_chan_act(g_pars.chan_mode);
760 /* attempt to activate the same lchan again -> expect reject */
761 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
762 alt {
763 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100765 }
766 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
767 setverdict(pass);
768 }
769 }
770 f_rsl_chan_deact();
771}
772testcase TC_chan_act_react() runs on test_CT {
773 var ConnHdlr vc_conn;
774 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100775 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100776 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
777 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100779}
780
781/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700782private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100783 timer T := 3.0;
784 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
785 T.start;
786 alt {
787 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
788 setverdict(pass);
789 }
790 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100792 }
793 }
794}
795testcase TC_chan_deact_not_active() runs on test_CT {
796 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100797 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100798 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
799 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100801}
802
803/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700804private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100805 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
806 alt {
807 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100809 }
810 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
811 setverdict(pass);
812 }
813 }
814}
815private type record WrongChanNrCase {
816 RslChannelNr chan_nr,
817 charstring description
818}
819private type record of WrongChanNrCase WrongChanNrCases;
820private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
821 chan_nr := chan_nr,
822 description := desc
823}
824
825testcase TC_chan_act_wrong_nr() runs on test_CT {
826 var ConnHdlr vc_conn;
827 var ConnHdlrPars pars;
828
Harald Welte294b0a22018-03-10 23:26:48 +0100829 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100830
831 var WrongChanNrCases wrong := {
832 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
833 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
834 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
835 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
836 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
837 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
838 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
839 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
840 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
841 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
842 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
843 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
844 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
845 };
846
847 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
848 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
849 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
850 vc_conn.done;
851 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100853}
854
Harald Weltee613f962018-04-18 22:38:16 +0200855/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200856friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200857 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200858 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200859
860 /* test on each of the channels we have */
861 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
862 pars.chan_nr := valueof(g_AllChanTypes[i]);
863
864 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
865 vc_conn := f_start_handler(fn, pars);
866 vc_conn.done;
867 }
868
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200870}
871
Harald Welte93640c62018-02-25 16:59:33 +0100872/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100873 * SACCH handling
874 ***********************************************************************/
875
876private function f_exp_sacch(boolean exp) runs on ConnHdlr {
877 timer T_sacch := 3.0;
878 T_sacch.start;
879 alt {
880 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100882 }
883 [not exp] T_sacch.timeout {
884 setverdict(pass);
885 }
886 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
887 setverdict(pass);
888 }
889 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100891 }
892 [] L1CTL.receive { repeat; }
893 [] RSL.receive { repeat; }
894 }
895}
896
897/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
898private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
899 f_l1_tune(L1CTL);
900 RSL.clear;
901
902 /* activate the logical channel */
903 f_est_dchan();
904 L1CTL.clear;
905
906 /* check that SACCH actually are received as expected */
907 f_exp_sacch(true);
908
909 /* deactivate SACCH on the logical channel */
910 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
911 f_sleep(1.0);
912 L1CTL.clear;
913
914 /* check that no SACCH are received anymore */
915 f_exp_sacch(false);
916
917 /* release the channel */
918 f_rsl_chan_deact();
919 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
920}
921testcase TC_deact_sacch() runs on test_CT {
922 var ConnHdlr vc_conn;
923 var ConnHdlrPars pars;
924 f_init();
925 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
926 //for (var integer i := 0; i < 1; i := i+1) {
927 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
928 log(testcasename(), ": Starting for ", g_AllChannels[i]);
929 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
930 vc_conn.done;
931 }
932 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100934}
935
Harald Welte55700662018-03-12 13:15:43 +0100936/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100937private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
938 var L1ctlDlMessage dl;
939 /* check that the specified SI5 value is actually sent */
940 timer T_sacch := 3.0;
941 L1CTL.clear;
942 T_sacch.start;
943 alt {
944 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
945 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
946 if (match(l3, l3_exp)) {
947 setverdict(pass);
948 } else {
949 repeat;
950 }
951 }
952 [] L1CTL.receive { repeat; }
953 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100955 }
956 }
957}
958
Harald Welte55700662018-03-12 13:15:43 +0100959/* verify that given SACCH payload is not present */
960private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
961 var L1ctlDlMessage dl;
962 /* check that the specified SI5 value is actually sent */
963 timer T_sacch := 3.0;
964 L1CTL.clear;
965 T_sacch.start;
966 alt {
967 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
968 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
969 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100971 } else {
972 repeat;
973 }
974 }
975 [] L1CTL.receive { repeat; }
976 [] T_sacch.timeout {
977 setverdict(pass);
978 }
979 }
980}
981
Harald Welte629cc6b2018-03-11 17:19:05 +0100982/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100983private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
984 /* Set a known default SACCH filling for SI5 */
985 var octetstring si5 := f_rnd_octstring(19);
986 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
987
988 f_l1_tune(L1CTL);
989 RSL.clear;
990
991 /* activate the logical channel */
992 f_est_dchan();
993
994 /* check that the specified SI5 value is actually sent */
995 f_sacch_present(si5);
996
997 /* release the channel */
998 RSL.clear;
999 f_rsl_chan_deact();
1000 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1001}
1002testcase TC_sacch_filling() 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_filling), 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 Welteea17b912018-03-11 22:29:31 +01001014}
1015
Harald Welte629cc6b2018-03-11 17:19:05 +01001016/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001017private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1018 /* Set a known default SACCH filling for SI5 */
1019 var octetstring si5 := f_rnd_octstring(19);
1020 var octetstring si5_diff := f_rnd_octstring(19);
1021 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1022
1023 f_l1_tune(L1CTL);
1024 RSL.clear;
1025
1026 log("Activating channel, expecting standard SI5");
1027 /* activate the logical channel */
1028 f_est_dchan();
1029 /* check that the specified SI5 value is actually sent */
1030 f_sacch_present(si5);
1031
1032 /* set channel-specific different SI5 */
1033 log("Setting channel specific SACCH INFO, expecting it");
1034 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1035 /* check that the specified lchan-specific value is now used */
1036 f_sacch_present(si5_diff);
1037
1038 /* deactivate the channel and re-activate it, this should result in default SI5 */
1039 log("De-activating and re-activating channel, expecting standard SI5");
1040 f_rsl_chan_deact();
1041 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1042 /* Verify that the TRX-wide default SACCH filling is present again */
1043 f_sacch_present(si5);
1044
1045 /* release the channel */
1046 RSL.clear;
1047 f_rsl_chan_deact();
1048 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1049}
1050testcase TC_sacch_info_mod() runs on test_CT {
1051 var ConnHdlr vc_conn;
1052 var ConnHdlrPars pars;
1053 f_init();
1054 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1055 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1056 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1057 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1058 vc_conn.done;
1059 }
1060 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001062}
1063
Harald Welte075d84c2018-03-12 13:07:24 +01001064/* Test SACCH scheduling of multiple different SI message types */
1065private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1066 var octetstring si5 := f_rnd_octstring(19);
1067 var octetstring si5bis := f_rnd_octstring(19);
1068 var octetstring si5ter := f_rnd_octstring(19);
1069 var octetstring si6 := f_rnd_octstring(19);
1070
1071 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1072 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1073 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1074 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1075
1076 f_l1_tune(L1CTL);
1077 RSL.clear;
1078
1079 /* activate the logical channel */
1080 f_est_dchan();
1081 L1CTL.clear;
1082
1083 /* check that SACCH actually are received as expected */
1084 f_sacch_present(si5);
1085 f_sacch_present(si5bis);
1086 f_sacch_present(si5ter);
1087 f_sacch_present(si6);
1088
1089 /* release the channel */
1090 f_rsl_chan_deact();
1091 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1092}
1093testcase TC_sacch_multi() runs on test_CT {
1094 var ConnHdlr vc_conn;
1095 var ConnHdlrPars pars;
1096 f_init();
1097 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1098 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1099 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1100 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1101 vc_conn.done;
1102 }
1103 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001105}
1106
Harald Welte55700662018-03-12 13:15:43 +01001107/* Test if SACH information is modified as expected */
1108private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1109 var octetstring si5 := f_rnd_octstring(19);
1110 var octetstring si6 := f_rnd_octstring(19);
1111
1112 /* First, configure both SI5 and SI6 to be transmitted */
1113 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1114 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1115
1116 f_l1_tune(L1CTL);
1117 RSL.clear;
1118
1119 /* activate the logical channel */
1120 f_est_dchan();
1121 L1CTL.clear;
1122
1123 /* check that SACCH actually are received as expected */
1124 f_sacch_present(si5);
1125 f_sacch_present(si6);
1126
1127 /* disable SI6 */
1128 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1129
1130 /* check that SI5 is still transmitted */
1131 f_sacch_present(si5);
1132 /* check if SI6 is now gone */
1133 f_sacch_missing(si6);
1134
1135 /* release the channel */
1136 f_rsl_chan_deact();
1137 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1138}
1139testcase TC_sacch_multi_chg() runs on test_CT {
1140 var ConnHdlr vc_conn;
1141 var ConnHdlrPars pars;
1142 f_init();
1143 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1144 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1145 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1146 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1147 vc_conn.done;
1148 }
1149 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001151}
1152
Harald Weltec8d363c2019-05-19 20:36:48 +02001153/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1154private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1155 var octetstring si5 := f_rnd_octstring(19);
1156 var octetstring si6 := f_rnd_octstring(19);
1157 var octetstring si5_specific := f_rnd_octstring(19);
1158 var octetstring si6_specific := f_rnd_octstring(19);
1159
1160 /* First, configure both SI5 and SI6 to be transmitted */
1161 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1162 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1163
1164 f_l1_tune(L1CTL);
1165 RSL.clear;
1166
1167 /* activate channel with different SACCH filling */
1168 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1169 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1170 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1171 }));
1172 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1173 RSL_IE_Body:{sacch_info := sacch_info})) };
1174 f_est_dchan(more_ies := addl_ies);
1175
1176 /* check that SACCH actually are received as expected */
1177 f_sacch_present(si5_specific);
1178 f_sacch_present(si6_specific);
1179
1180 /* release the channel */
1181 f_rsl_chan_deact();
1182 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1183}
1184testcase TC_sacch_chan_act() runs on test_CT {
1185 var ConnHdlr vc_conn;
1186 var ConnHdlrPars pars;
1187 f_init();
1188
1189 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1190 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1191 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1192 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1193 vc_conn.done;
1194 }
1195 /* TODO: do the above in parallel, rather than sequentially? */
1196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1197}
1198
Harald Welte8b01c792019-05-19 22:51:25 +02001199/* verify that SACCH DL transmission is started only if MS power IE present
1200 * see section 4.1.3 of 3GPP TS 48.058 */
1201private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1202 var octetstring si5 := f_rnd_octstring(19);
1203
1204 f_l1_tune(L1CTL);
1205 RSL.clear;
1206
1207 /* Step 1: Activate ASYNC HO channel without MS power IE */
1208
1209 /* Activate channel on BTS side */
1210 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1211 /* don't perform immediate assignment here, as we're testing non-IA case */
1212 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001213 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001214
1215 /* Verify that no DL SACCH is being received */
1216 f_sacch_missing(?);
1217
1218 f_rsl_chan_deact();
1219 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1220
1221
1222 /* Step 2: Activate ASYNC HO channel with MS power IE */
1223
1224 /* Activate channel on BTS side */
1225 var RSL_IE_List addl_ies := {
1226 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1227 };
1228 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1229 /* don't perform immediate assignment here, as we're testing non-IA case */
1230 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001231 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001232
1233 /* Verify that DL SACCH is being received */
1234 f_sacch_present(si5);
1235
1236 f_rsl_chan_deact();
1237 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1238}
1239testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1240 var ConnHdlr vc_conn;
1241 var ConnHdlrPars pars;
1242 f_init();
1243
1244 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1245 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1246 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1247 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1248 vc_conn.done;
1249 }
1250 /* TODO: do the above in parallel, rather than sequentially? */
1251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1252}
1253
1254/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1255 * see section 4.1.4 of 3GPP TS 48.058 */
1256private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1257 var octetstring si5 := f_rnd_octstring(19);
1258 var RSL_IE_List addl_ies;
1259
1260 f_l1_tune(L1CTL);
1261 RSL.clear;
1262
1263 /* Step 1: Activate SYNC HO channel without MS power IE */
1264
1265 /* Activate channel on BTS side */
1266 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1267 /* don't perform immediate assignment here, as we're testing non-IA case */
1268 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001269 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001270
1271 /* Verify that no DL SACCH is being received */
1272 f_sacch_missing(?);
1273
1274 f_rsl_chan_deact();
1275 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1276
1277
1278 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1279
1280 /* Activate channel on BTS side */
1281 addl_ies := {
1282 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1283 };
1284 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1285 /* don't perform immediate assignment here, as we're testing non-IA case */
1286 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001287 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001288
1289 /* Verify that no DL SACCH is being received */
1290 f_sacch_missing(?);
1291
1292 f_rsl_chan_deact();
1293 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1294
1295
1296 /* Step 2b: Activate SYNC HO channel with TA IE */
1297
1298 /* Activate channel on BTS side */
1299 addl_ies := {
1300 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1301 };
1302 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1303 /* don't perform immediate assignment here, as we're testing non-IA case */
1304 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001305 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001306
1307 /* Verify that no DL SACCH is being received */
1308 f_sacch_missing(?);
1309
1310 f_rsl_chan_deact();
1311 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1312
1313
1314 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1315
1316 /* Activate channel on BTS side */
1317 addl_ies := {
1318 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1319 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1320 };
1321 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1322 /* don't perform immediate assignment here, as we're testing non-IA case */
1323 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001324 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001325
1326 /* Verify that DL SACCH is being received */
1327 f_sacch_present(si5);
1328
1329 f_rsl_chan_deact();
1330 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1331}
1332testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1333 var ConnHdlr vc_conn;
1334 var ConnHdlrPars pars;
1335 f_init();
1336
1337 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1338 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1339 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1340 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1341 vc_conn.done;
1342 }
1343 /* TODO: do the above in parallel, rather than sequentially? */
1344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1345}
Harald Welte629cc6b2018-03-11 17:19:05 +01001346
1347
1348/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001349 * RACH Handling
1350 ***********************************************************************/
1351
Harald Welte8c24c2b2018-02-26 08:31:31 +01001352/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001353private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001354 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001355 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001356 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001357
Harald Welte8c24c2b2018-02-26 08:31:31 +01001358 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001359 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001360 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001361 var OCT1 ra := f_rnd_ra_emerg();
1362 if (emerg == true) {
1363 ra := f_rnd_ra_emerg();
1364 } else {
1365 ra := f_rnd_ra_cs();
1366 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001367 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1368 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001370 }
1371 fn_last := fn;
1372
1373 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001374 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001375 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001376 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001377 T.stop;
1378 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001379 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381 }
1382 [] RSL_CCHAN.receive { repeat; }
1383 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001384 test_failed := true;
1385 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 }
1387 }
1388 }
Maxba06feb2019-03-05 10:52:46 +01001389 if (test_failed) {
1390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001391 }
Maxba06feb2019-03-05 10:52:46 +01001392 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001394}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001395
Philipp Maier16ade782020-07-08 21:36:00 +02001396/* Normal variant */
1397testcase TC_rach_content() runs on test_CT {
1398 f_TC_rach_content(emerg := false);
1399}
1400
1401/* Emergency call variant */
1402testcase TC_rach_content_emerg() runs on test_CT {
1403 f_TC_rach_content(emerg := true);
1404}
1405
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1407testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001408 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001409 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001410 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001411 f_l1_tune(L1CTL);
1412
1413 var GsmFrameNumber fn_last := 0;
1414 for (var integer i := 0; i < 1000; i := i+1) {
1415 var OCT1 ra := f_rnd_ra_cs();
1416 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1417 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001419 }
1420 fn_last := fn;
1421 }
1422 var integer rsl_chrqd := 0;
1423 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001424 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001425 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001426 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001427 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001428 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001429 repeat;
1430 }
1431 [] RSL_CCHAN.receive { repeat; }
1432 [] T.timeout { }
1433 }
1434 if (rsl_chrqd == 1000) {
1435 setverdict(pass);
1436 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001440}
1441
Harald Welte3453ab42019-05-24 21:19:58 +02001442private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1443 var charstring bts_str := "bts " & int2str(bts_nr);
1444 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1445}
1446
1447/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1448private template integer tr_rach_slots_per_interval := (90 .. 130);
1449
1450/* Expect 0 RACH load on an idle BTS that has just started up */
1451testcase TC_rach_load_idle_thresh0() runs on test_CT {
1452 var ASP_RSL_Unitdata rx_ud;
1453
1454 f_init_vty_bsc();
1455 /* send load indications even at 0% load */
1456 f_vty_load_ind_thresh(0);
1457 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1458 f_sleep(2.0);
1459
1460 f_init();
1461
1462 timer T := 5.0;
1463 T.start;
1464 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001465 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001466 setverdict(pass);
1467 repeat;
1468 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001469 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001470 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1471 repeat;
1472 }
1473 [] RSL_CCHAN.receive {
1474 repeat;
1475 }
1476 [] T.timeout { }
1477 }
1478
1479 f_vty_load_ind_thresh(10);
1480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1481}
1482
1483/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1484testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1485 var ASP_RSL_Unitdata rx_ud;
1486
1487 f_init_vty_bsc();
1488 f_init();
1489
1490 timer T := 5.0;
1491 T.start;
1492 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001493 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001494 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1495 repeat;
1496 }
1497 [] RSL_CCHAN.receive {
1498 repeat;
1499 }
1500 [] T.timeout {
1501 setverdict(pass);
1502 }
1503 }
1504
1505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1506}
1507
1508/* Expect 0 RACH load on an idle BTS that has just started up */
1509testcase TC_rach_load_count() runs on test_CT {
1510 var ASP_RSL_Unitdata rx_ud;
1511 var integer load_access_count := 0;
1512
1513 f_init_vty_bsc();
1514 /* send load indications even at 0% load */
1515 f_vty_load_ind_thresh(0);
1516 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1517 f_sleep(2.0);
1518 f_init();
1519
1520 f_init_l1ctl();
1521 f_sleep(1.0);
1522 f_l1_tune(L1CTL);
1523
1524 var GsmFrameNumber fn_last := 0;
1525 for (var integer i := 0; i < 1000; i := i+1) {
1526 var OCT1 ra := f_rnd_ra_cs();
1527 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1528 if (fn == fn_last) {
1529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1530 }
1531 fn_last := fn;
1532 }
1533
1534 timer T := 5.0;
1535 T.start;
1536 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001537 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001538 -> value rx_ud {
1539 var RSL_IE_Body ie;
1540 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1541 load_access_count := load_access_count + ie.rach_load.access_count;
1542 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1543 setverdict(fail, "Access count cannot be < Busy count");
1544 }
1545 repeat;
1546 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001547 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001548 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1549 repeat;
1550 }
1551 [] RSL_CCHAN.receive {
1552 repeat;
1553 }
1554 [] T.timeout { }
1555 }
1556 if (load_access_count == 1000) {
1557 setverdict(pass);
1558 } else {
1559 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1560 }
1561
1562 f_vty_load_ind_thresh(10);
1563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1564}
1565
Harald Welte54a2a2d2018-02-26 09:14:05 +01001566private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001567 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001568 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001569 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001570 f_sleep(0.5);
1571
1572 /* Transmit RACH request + wait for confirmation */
1573 var OCT1 ra := f_rnd_ra_cs();
1574 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1575
1576 /* Check for expected result */
1577 timer T := 1.5;
1578 T.start;
1579 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001580 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001581 setverdict(pass);
1582 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001583 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001585 }
1586 [] RSL_CCHAN.receive { repeat; }
1587 [not expect_pass] T.timeout {
1588 setverdict(pass);
1589 }
1590 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001592 }
1593 }
1594}
1595
1596/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1597testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001598 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001599 f_init_l1ctl();
1600 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001601 f_sleep(1.0);
1602
1603 /* default max-ta is 63 (full range of GSM timing advance */
1604
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001605 /* We allow early arrival up to 2 symbols */
1606 f_rach_toffs(-1*256, true);
1607 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608 f_rach_toffs(-10*256, false);
1609
1610 /* 0 / 32 / 63 bits is legal / permitted */
1611 f_rach_toffs(0, true);
1612 f_rach_toffs(32*256, true);
1613 f_rach_toffs(63*256, true);
1614
1615 /* more than 63 bits is not legal / permitted */
1616 f_rach_toffs(64*256, false);
1617 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001619}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001620
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001621private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001622 var GsmFrameNumber fn;
1623 var RSL_Message rm;
1624
1625 f_l1_tune(L1CTL);
1626 RSL.clear;
1627
1628 /* Generate a random Handover Reference */
1629 var integer ho_ref := oct2int(f_rnd_octstring(1));
1630
1631 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1632 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1633 RSL_IE_Body:{ handover_ref := ho_ref }));
1634
1635 /* Activate a channel on the BTS side (no encryption) */
1636 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1637 act_type := t_RSL_IE_ActType_HO_SYNC);
1638
1639 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1640 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001641 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001642
1643 /* Send handover Access Burst */
1644 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1645
1646 /* TODO: test mismatching Handover Reference, and missing IE */
1647
1648 /* Wait for handover detection */
1649 timer T := 3.0;
1650 T.start;
1651 alt {
1652 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1653 log("Handover RACH has been detected: ", rm);
1654 setverdict(pass);
1655 }
1656 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1658 log2str("RSL_CHAN_RQD was not expected: ", rm));
1659 }
1660 [] RSL.receive { repeat; }
1661 [] T.timeout {
1662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1663 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1664 }
1665 }
1666
1667 /* Release the channel */
1668 f_rsl_chan_deact();
1669 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1670}
1671
1672/* Test handover RACH detection */
1673testcase TC_ho_rach() runs on test_CT {
1674 var ConnHdlrPars pars;
1675 var ConnHdlr vc_conn;
1676
1677 f_init();
1678
1679 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1680 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1681 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1682 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1683 vc_conn.done;
1684 }
1685
1686 /* TODO: do the above in parallel, rather than sequentially? */
1687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1688}
1689
Harald Welte93640c62018-02-25 16:59:33 +01001690/***********************************************************************
1691 * Measurement Processing / Reporting
1692 ***********************************************************************/
1693
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001694private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001695 spare := '0'B,
1696 lpd := 0,
1697 sapi := sapi,
1698 c_r := c_r,
1699 ea := true
1700}
1701
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001702private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001703 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001704 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001705 len := 0, /* overwritten */
1706 m := false,
1707 el := 1,
1708 payload := pl
1709}
1710
1711/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001712private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001713 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001714 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001715 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001716 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 +01001717 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001718 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001719
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001720 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1721 g_pars.l1_pars.ms_power_level, false,
1722 g_pars.l1_pars.ms_actual_ta);
1723
1724 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1725 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1726
1727 log("Sending Measurement Report: ", l1h, l2);
1728 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001729 repeat;
1730 }
1731}
1732
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001733private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001734 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001735 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001736 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1737 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001738 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1739 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001740 repeat;
1741 }
1742}
1743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001744private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001745 uint6_t rxlev,
1746 uint3_t rxqual
1747}
1748
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001749private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001750 MeasElem full,
1751 MeasElem sub
1752}
1753
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001754private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001755 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001756 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001757 MeasElemFS meas_ul,
1758 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001759 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001760 uint5_t ms_power_level,
1761 uint8_t ms_actual_ta
1762}
1763
1764/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1765private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1766 return 63 + (toffs256s/256);
1767}
1768
Harald Welted5684392018-03-10 18:22:04 +01001769private function f_max(integer a, integer b) return integer {
1770 if (a > b) {
1771 return a;
1772 } else {
1773 return b;
1774 }
1775}
1776
1777private function f_min(integer a, integer b) return integer {
1778 if (a < b) {
1779 return a;
1780 } else {
1781 return b;
1782 }
1783}
1784
1785/* compute negative tolerance val-tolerance, ensure >= min */
1786private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1787 val := val - tolerance;
1788 return f_max(val, min);
1789}
1790
1791/* compute positive tolerance val+tolerance, ensure <= max */
1792private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1793 val := val + tolerance;
1794 return f_min(val, max);
1795}
1796
1797/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1798private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1799return template integer {
1800 var template integer ret;
1801 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1802 return ret;
1803}
1804
1805
Harald Welte70767382018-02-21 12:16:40 +01001806/* build a template for matching measurement results against */
1807private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1808 var ConnL1Pars l1p := g_pars.l1_pars;
1809 var template RSL_IE_UplinkMeas ul_meas := {
1810 len := 3,
1811 rfu := '0'B,
1812 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001813 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001814 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001815 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001816 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001817 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1818 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001819 supp_meas_info := omit
1820 };
Harald Welte685d5982018-02-27 20:42:05 +01001821 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001822 ul_meas.len := (3+8);
1823 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001824 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001825 toa256_min := ?,
1826 toa256_max := ?,
1827 toa256_std_dev := ?
1828 }
Harald Welte685d5982018-02-27 20:42:05 +01001829 }
Harald Welte70767382018-02-21 12:16:40 +01001830 var template RSL_IE_BS_Power bs_power := {
1831 reserved := 0,
1832 epc := false,
1833 fpc := false,
1834 power_level := l1p.bs_power_level
1835 };
1836 var template RSL_IE_L1Info l1_info := {
1837 ms_power_lvl := l1p.ms_power_level,
1838 fpc := false,
1839 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001840 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001841 };
1842 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001843 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001844 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1845 ?, t_toffs);
1846}
1847
Philipp Maierdd841d32019-12-17 14:44:54 +01001848/* build a template for matching measurement results that do not contain any
1849 * MS related measurement (l1_info, l3_info and ms timing offset). */
1850private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1851 var ConnL1Pars l1p := g_pars.l1_pars;
1852 var template RSL_IE_UplinkMeas ul_meas := {
1853 len := 3,
1854 rfu := '0'B,
1855 dtx_d := l1p.dtx_enabled,
1856 rxlev_f_u := ?,
1857 reserved1 := '00'B,
1858 rxlev_s_u := ?,
1859 reserved2 := '00'B,
1860 rxq_f_u := ?,
1861 rxq_s_u := ?,
1862 supp_meas_info := omit
1863 };
1864 if (l1p.toa256_enabled) {
1865 ul_meas.len := (3+8);
1866 ul_meas.supp_meas_info := {
1867 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1868 toa256_min := ?,
1869 toa256_max := ?,
1870 toa256_std_dev := ?
1871 }
1872 }
1873 var template RSL_IE_BS_Power bs_power := {
1874 reserved := 0,
1875 epc := false,
1876 fpc := false,
1877 power_level := l1p.bs_power_level
1878 };
1879
1880 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1881}
1882
Harald Welte70767382018-02-21 12:16:40 +01001883/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001884private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001885 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001886 var boolean chan_est := false;
1887
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001888 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001889
1890 /* Receive osmocom specific measurement reports. This is the normal
1891 * case. Here we verify that the measurement reports we sent are
1892 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001893 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1894 /* increment counter of next to-be-expected meas rep */
1895 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1896 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001897 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001898
1899 /* The following two cases may only happen in the beginning
1900 * of the channel establishment phase. Once we have received
1901 * the "our" measurement report the first time, the channel
1902 * is established and empty or hardcoded TRXCON reports must
1903 * not occur anymore. */
1904 chan_est := true;
1905
1906 repeat;
1907 }
1908
1909 /* When the BTS has established the channel, the MS might need slightly
1910 * more time to establish the channel and actually start sending. The
1911 * result is then a measurement report that just lacks the measurement
1912 * information of the MS. This is normal and we tolerate this behavior. */
1913 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1914 /* increment counter of next to-be-expected meas rep */
1915 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1916 /* Re-start the timer expecting the next MEAS RES */
1917 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001918 repeat;
1919 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001920
1921 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1922 * measurements if the TTCN3 side does not supply measurement input in
1923 * time. In those cases TRXCON will either use a cached measurement
1924 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1925 * report the templates above will not match. We tolerate this
1926 * behavior, but only once. */
1927 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001928 /* increment counter of next to-be-expected meas rep */
1929 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1930 if (g_first_meas_res) {
1931 g_first_meas_res := false;
1932 repeat;
1933 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001935 }
Harald Welte70767382018-02-21 12:16:40 +01001936 }
1937 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001939 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001940 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001941 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001942 }
1943}
1944
Harald Weltee613f962018-04-18 22:38:16 +02001945private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1946 select (rsl_alg_id) {
1947 case (RSL_ALG_ID_A5_0) { return 0; }
1948 case (RSL_ALG_ID_A5_1) { return 1; }
1949 case (RSL_ALG_ID_A5_2) { return 2; }
1950 case (RSL_ALG_ID_A5_3) { return 3; }
1951 case (RSL_ALG_ID_A5_4) { return 4; }
1952 case (RSL_ALG_ID_A5_5) { return 5; }
1953 case (RSL_ALG_ID_A5_6) { return 6; }
1954 case (RSL_ALG_ID_A5_7) { return 7; }
1955 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1957 /* Make compiler happy by calling mtc.stop here. It is already
1958 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001959 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001960 }
1961 }
1962}
1963
1964private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1965 select (rsl_alg_id) {
1966 case (RSL_ALG_ID_A5_1) { return '000'B; }
1967 case (RSL_ALG_ID_A5_2) { return '001'B; }
1968 case (RSL_ALG_ID_A5_3) { return '010'B; }
1969 case (RSL_ALG_ID_A5_4) { return '011'B; }
1970 case (RSL_ALG_ID_A5_5) { return '100'B; }
1971 case (RSL_ALG_ID_A5_6) { return '101'B; }
1972 case (RSL_ALG_ID_A5_7) { return '110'B; }
1973 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1975 /* Make compiler happy by calling mtc.stop here. It is already
1976 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001977 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001978 }
1979 }
1980}
1981
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001982/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1983private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1984 var GsmFrameNumber fn;
1985 timer T := 8.0;
1986
1987 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1988 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1989
1990 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1991 /* Send the actual RACH */
1992 fn := f_L1CTL_RACH(L1CTL, ra);
1993
1994 T.start;
1995 alt {
1996 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1997 [] T.timeout {
1998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1999 }
2000 }
2001 T.stop
2002 return fn;
2003}
Harald Weltee613f962018-04-18 22:38:16 +02002004
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002005/* Tune to a dedicated channel: L1CTL only */
2006private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
2007 if (not ispresent(pars.maio_hsn)) {
2008 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2009 7 /* TODO: mp_tsc */,
2010 mp_trx0_arfcn));
2011 } else {
2012 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2013 7 /* TODO: mp_tsc */,
2014 pars.maio_hsn.hsn,
2015 pars.maio_hsn.maio,
2016 pars.ma));
2017 }
2018}
2019
Harald Welte70767382018-02-21 12:16:40 +01002020/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002021private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002022 var GsmFrameNumber fn;
2023 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002024 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002025 var integer ra := 23;
2026
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002027 /* Send RACH request and wait for ChanReq */
2028 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002029
2030 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002031 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002032
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002033 /* Craft channel description (with or without frequency hopping parameters) */
2034 if (ispresent(g_pars.maio_hsn)) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002035 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002036 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002037 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002038 }
2039
Harald Welte70767382018-02-21 12:16:40 +01002040 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002041 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002042 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2043
2044 /* receive IMM.ASS on MS side */
2045 var ImmediateAssignment ia_um;
2046 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002047
2048 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2049 if (ch_desc.h != ia_um.chan_desc.h) {
2050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2051 }
2052
Harald Welte70767382018-02-21 12:16:40 +01002053 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002054 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002055 /* enable encryption, if requested */
2056 if (encr_enable) {
2057 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2058 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2059 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002060
2061 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002062}
2063
2064/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002065private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002066 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002067 RSL.clear;
2068
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002069 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002070 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002071 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002072 }
Harald Welte70767382018-02-21 12:16:40 +01002073
2074 f_est_dchan();
2075
2076 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2077 * RSL measurement reports on Abis side */
2078 timer T := 8.0;
2079 T.start;
2080 alt {
2081 [] as_l1_sacch();
2082 [] as_meas_res();
2083 [] as_l1_dcch();
2084 [] L1CTL.receive { repeat; }
2085 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002086 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002087 * of any earlier errors, so if we reach this timeout, we're good */
2088 setverdict(pass);
2089 }
2090 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002092 }
2093 }
2094 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002095 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002096}
Harald Welte0472ab42018-03-12 15:02:26 +01002097
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002098/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2099private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002100 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002101 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2102 timer Tup := 10.0;
2103 Tup.start;
2104 alt {
2105 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2106 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2107 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002108
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002109 if (rx_lvl != max_rx_lvl) {
2110 repeat;
2111 }
2112 Tup.stop;
2113 }
2114 [] L1CTL.receive { repeat; }
2115 [] Tup.timeout {
2116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2117 log2str("Didn't reach full power ", max_rx_lvl));
2118 }
2119 }
2120 return max_rx_lvl;
2121}
2122
2123/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2124private function f_verify_ramp_up() runs on ConnHdlr {
2125 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002126 var integer initial_rx_lvl := -1;
2127 var integer last_rx_lvl := -1;
2128 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2129
2130 timer T := 2.0;
2131 alt {
2132 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2133 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2134 log("Received rx_level=", rx_lvl);
2135 if (initial_rx_lvl == -1) {
2136 initial_rx_lvl := rx_lvl;
2137 last_rx_lvl := rx_lvl;
2138
2139 /* Expect a somehow low value during first received messages */
2140 if (initial_rx_lvl >= max_rx_lvl / 2) {
2141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2142 log2str("Detected high initial tx power during ramp up: ",
2143 initial_rx_lvl , ", full power is", max_rx_lvl));
2144 }
2145 }
2146
2147 /* received Rx level bigger than maximum allowed power by CN */
2148 if (rx_lvl > max_rx_lvl) {
2149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2150 log2str("Detected Tx power higher than full power: ",
2151 rx_lvl , " > ", max_rx_lvl));
2152 }
2153
2154 /* Make sure it never decreases, since we are rumping up */
2155 if (last_rx_lvl > rx_lvl) {
2156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2157 log2str("Detected Tx power decrease during ramp up: ",
2158 last_rx_lvl , " -> ", rx_lvl));
2159 }
2160
2161 if (rx_lvl == max_rx_lvl and not T.running) {
2162 /* We reached the maximum power, start timer and receive
2163 /* a few more to make sure we don't surpass it */
2164 log("Reached full power, wating a bit more until success");
2165 T.start;
2166 }
2167
2168 last_rx_lvl := rx_lvl;
2169 repeat;
2170 }
2171 [] L1CTL.receive { repeat; }
2172 [] T.timeout { }
2173 }
2174
2175 /* We didn't increase tx power during ramp up */
2176 if (initial_rx_lvl < last_rx_lvl) {
2177 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2178 } else {
2179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2180 log2str("No Tx power increase during whole ramp up: ",
2181 initial_rx_lvl , " -> ", last_rx_lvl));
2182 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002183}
2184
2185/* verify BTS ramps power down to rx_level 0 */
2186private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2187 var L1ctlDlMessage l1_dl;
2188 var integer last_rx_lvl := max_rx_lvl;
2189
2190 timer Tdown := 5.0;
2191 Tdown.start;
2192 alt {
2193 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2194 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2195 log("Received rx_level=", rx_lvl);
2196
2197 /* received Rx level bigger than maximum allowed power by CN */
2198 if (rx_lvl > max_rx_lvl) {
2199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2200 log2str("Detected Tx power higher than full power: ",
2201 rx_lvl , " > ", max_rx_lvl));
2202 }
2203
2204 /* Make sure it never increases, since we are rumping down */
2205 if (last_rx_lvl < rx_lvl) {
2206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2207 log2str("Detected Tx power increase during ramp up: ",
2208 last_rx_lvl , " -> ", rx_lvl));
2209 }
2210
2211 last_rx_lvl := rx_lvl;
2212 if (last_rx_lvl != 0) {
2213 repeat;
2214 }
2215 /* we reached power level 0, we are done */
2216 Tdown.stop;
2217 }
2218 [] L1CTL.receive { repeat; }
2219 [] Tdown.timeout { }
2220 }
2221
2222 /* We didn't increase tx power during ramp down */
2223 if (max_rx_lvl > last_rx_lvl) {
2224 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2225 } else {
2226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2227 log2str("No Tx power decrease during whole ramp down: ",
2228 max_rx_lvl , " -> ", last_rx_lvl));
2229 }
2230}
2231
2232/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002233private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002234 f_l1_tune(L1CTL);
2235 RSL.clear;
2236
2237 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002238
2239 setverdict(pass);
2240}
2241testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2242 var ConnHdlr vc_conn;
2243 var ConnHdlrPars pars;
2244 f_init();
2245 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2246 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2247 pcu_comp := false, trxc_comp := true);
2248 vc_conn.done;
2249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2250}
2251
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002252/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002253private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002254 f_connhdlr_init_vty_bsc();
2255
2256 f_l1_tune(L1CTL);
2257 RSL.clear;
2258
2259 /* Wait until BTS is started and at full power */
2260 var integer max_rx_lvl := f_wait_ramp_up();
2261 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2262
2263 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2264 f_verify_ramp_down(max_rx_lvl);
2265
2266 setverdict(pass);
2267}
2268testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2269 var ConnHdlr vc_conn;
2270 var ConnHdlrPars pars;
2271 f_init();
2272 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2273 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2274 pcu_comp := false, trxc_comp := true);
2275 vc_conn.done;
2276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2277}
2278
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002279/* Verify Tx power:
2280 * + ramping down during ADM state UNLOCKED->LOCKED
2281 * + ramping up during ADM state LOCKED->UNLOCKED
2282 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002283private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002284 var L1ctlDlMessage l1_dl;
2285 var integer last_rx_lvl;
2286
2287 f_connhdlr_init_vty_bsc();
2288
2289 f_l1_tune(L1CTL);
2290 RSL.clear;
2291
2292 /* Wait until BTS is started and at full power */
2293 var integer max_rx_lvl := f_wait_ramp_up();
2294 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2295
2296 log("ADM STATE UNLOCKED->LOCKED");
2297 f_vty_enter_cfg_trx(BSCVTY);
2298 f_vty_transceive(BSCVTY, "rf_locked 1");
2299 last_rx_lvl := max_rx_lvl;
2300 f_verify_ramp_down(max_rx_lvl);
2301
2302 /* Let some time after we received 0dBm, then check we don't receive BCCH
2303 * anymore because scheduler has stopped after ramping down */
2304 f_sleep(2.0);
2305 L1CTL.clear;
2306 timer Tlocked := 2.0;
2307 Tlocked.start;
2308 alt {
2309 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2311 log2str("Received data_ind during rf_locked: ", l1_dl));
2312 }
2313 [] L1CTL.receive { repeat; }
2314 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2315 }
2316
2317 log("ADM STATE LOCKED->UNLOCKED");
2318 f_vty_transceive(BSCVTY, "rf_locked 0");
2319 f_verify_ramp_up();
2320 setverdict(pass);
2321}
2322testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2323 var ConnHdlr vc_conn;
2324 var ConnHdlrPars pars;
2325 f_init();
2326 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2327 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2328 pcu_comp := false, trxc_comp := true);
2329 vc_conn.done;
2330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2331}
2332
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002333private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002334 timer T := 8.0;
2335 T.start;
2336 var RSL_Message rsl;
2337 alt {
2338 [] as_l1_sacch();
2339 [] L1CTL.receive { repeat; }
2340 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2341 if (rsl.ies[3].body.bs_power.power_level == level) {
2342 setverdict(pass)
2343 } else {
2344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2345 }
2346 }
2347 [] T.timeout {
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2349 }
2350 }
2351}
2352
2353/* see if the rsl meas res contains our expeced bs power level
2354bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002355private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002356 f_l1_tune(L1CTL);
2357 RSL.clear;
2358
2359 if (mp_bts_trxc_port != -1) {
2360 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2361 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2362 }
2363
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002364 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002365 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2366 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2367
2368 f_est_dchan(more_ies :={valueof(pwr)});
2369
2370 f_check_meas_bs_power_level(pwr_var);
2371
2372 f_rsl_chan_deact();
2373 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2374}
2375
2376/* see if the rsl meas res contains our expeced bs power level
2377bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002378private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002379 f_l1_tune(L1CTL);
2380 RSL.clear;
2381
2382 if (mp_bts_trxc_port != -1) {
2383 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2384 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2385 }
2386
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002387 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002388 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2389
2390 f_est_dchan();
2391
2392 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2393
2394 f_check_meas_bs_power_level(pwr_var);
2395
2396 f_rsl_chan_deact();
2397 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2398}
2399
2400testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2401 var ConnHdlr vc_conn;
2402 var ConnHdlrPars pars;
2403 f_init();
2404 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2405 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2406 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2407 pcu_comp := false, trxc_comp := true);
2408 vc_conn.done;
2409 }
2410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2411}
2412
2413testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2414 var ConnHdlr vc_conn;
2415 var ConnHdlrPars pars;
2416 f_init();
2417 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2418 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2419 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2420 pcu_comp := false, trxc_comp := true);
2421 vc_conn.done;
2422 }
2423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2424}
2425
Eric Wild61edb7e2019-06-03 12:38:31 +02002426/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2427second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2428These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002429private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002430 var uint5_t pwr_var := 7;
2431 var L1ctlDlMessage l1_dl;
2432
2433 f_trxc_fake_rssi(rxlev2dbm(10));
2434 f_l1_tune(L1CTL);
2435 RSL.clear;
2436
2437 var RSL_IE_List addl_ies;
2438 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2439
2440 addl_ies := {
2441 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2442 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2443 };
2444
2445 /* establish with power parameters */
2446 f_est_dchan(more_ies := addl_ies);
2447
2448 /* set a high value to ensure L1 power control level increases */
2449 f_trxc_fake_rssi(rxlev2dbm(20));
2450
2451 timer T2 := 6.0;
2452 T2.start;
2453 alt {
2454 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002455 /* Update sent MS power to follow what BTS requests */
2456 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2457 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002458 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002459 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002460 T2.stop;
2461 }
2462 [] L1CTL.receive { repeat; }
2463 [] T2.timeout {
2464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2465 "Power Level in L1 header has not increased sufficiently");
2466 }
2467 }
2468
2469 /* set a low value to ensure L1 power control level decreases */
2470 f_trxc_fake_rssi(rxlev2dbm(0));
2471
2472 timer T4 := 6.0;
2473 T4.start;
2474 alt {
2475 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002476 /* Update sent MS power to follow what BTS requests */
2477 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2478 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002479 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002480 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002481 T4.stop;
2482 setverdict(pass, "Power level in L1 decreased/increased as expected");
2483 }
2484 [] L1CTL.receive { repeat; }
2485 [] T4.timeout {
2486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2487 "Power Level in L1 header has not decreased sufficiently");
2488 }
2489 }
2490
2491 f_rsl_chan_deact();
2492 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2493
2494}
2495
2496/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002497private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002498 var uint5_t pwr_var := 7;
2499 var L1ctlDlMessage l1_dl;
2500
2501 /* set a low value to ensure power increases */
2502 f_trxc_fake_rssi(rxlev2dbm(10));
2503 f_l1_tune(L1CTL);
2504 RSL.clear;
2505
2506 var RSL_IE_List addl_ies;
2507 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2508
2509 addl_ies := {
2510 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2511 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2512 };
2513
2514 /* establish with power parameters */
2515 f_est_dchan(more_ies := addl_ies);
2516
2517 timer T1 := 10.0;
2518 T1.start;
2519 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002520 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2521 /* Update sent MS power to follow what BTS requests */
2522 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2523 repeat;
2524 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002525 [] L1CTL.receive { repeat; }
2526 [] T1.timeout {
2527 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2528 setverdict(fail, "Power level in L1 header should not have changed");
2529 }
2530 }
2531 }
2532
2533 f_rsl_chan_deact();
2534 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2535
2536}
2537
2538/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002539private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002540 var L1ctlDlMessage l1_dl;
2541 var uint5_t pwr_var := 15;
2542 var uint5_t pwr_max_var := f_get_max_power_from_band();
2543
2544 /* set a low value to ensure power increases */
2545 f_trxc_fake_rssi(rxlev2dbm(10));
2546 f_l1_tune(L1CTL);
2547 RSL.clear;
2548
2549 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2550 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2551
2552 /* establish with fixed power level */
2553 f_est_dchan(more_ies :={valueof(pwr)});
2554
2555 /* check our initial power level */
2556 f_wait_for_l1_power_level(pwr_var);
2557
2558 /* update power param to enable power loop
2559 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2560 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2561
2562 /* wait, then check that our power level was reduced */
2563 timer T1 := 10.0;
2564 T1.start;
2565 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002566 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2567 /* Update sent MS power to follow what BTS requests */
2568 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2569 repeat;
2570 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002571 [] L1CTL.receive { repeat; }
2572 [] T1.timeout {
2573 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2574 if( f_power_level_is_highest_dbm(rcv) ){
2575 setverdict(pass, "Power level in L1 header reduced as expected");
2576 } else {
2577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2578 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2579 }
2580 }
2581 }
2582
2583 f_rsl_chan_deact();
2584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2585
2586}
2587
2588/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002589private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002590 var L1ctlDlMessage l1_dl;
2591
2592 /* set a high value to ensure power decreases */
2593 f_trxc_fake_rssi(rxlev2dbm(50));
2594 f_l1_tune(L1CTL);
2595 RSL.clear;
2596
2597 var uint5_t pwr_var := 5;
2598 var uint5_t pwr_target_val := 15;
2599
2600 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2601 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2602
2603 /* establish with fixed power level */
2604 f_est_dchan(more_ies :={valueof(pwr)});
2605
2606 /* check our initial power level */
2607 f_wait_for_l1_power_level(pwr_var);
2608
2609 /* update power param to enable power loop
2610 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002611 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002612
2613 /* wait, then check that our power level was increased */
2614 timer T1 := 10.0;
2615 T1.start;
2616 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002617 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2618 /* Update sent MS power to follow what BTS requests */
2619 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2620 repeat;
2621 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002622 [] L1CTL.receive { repeat; }
2623 [] T1.timeout {
2624 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2625 setverdict(pass, "Power level in L1 header increased to lowest power value");
2626 } else {
2627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2628 "Power level in L1 header NOT increased to lowest power value");
2629 }
2630 }
2631 }
2632
2633 f_rsl_chan_deact();
2634 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2635
2636}
2637
Eric Wild095024b2019-06-17 15:08:57 +02002638/* see if we change the power level without receiving power parameters, which should not happen
2639rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002640private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002641 var L1ctlDlMessage l1_dl;
2642
2643 /* set a high value to ensure power decreases */
2644 f_trxc_fake_rssi(rxlev2dbm(50));
2645 f_l1_tune(L1CTL);
2646 RSL.clear;
2647
2648 var uint5_t pwr_var := 5;
2649
2650 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2651 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2652
2653 /* establish with fixed power level */
2654 f_est_dchan(more_ies :={valueof(pwr)});
2655
2656 /* check our initial power level */
2657 f_wait_for_l1_power_level(pwr_var);
2658
2659 /* wait, then check that our power level did not change */
2660 timer T1 := 10.0;
2661 T1.start;
2662 alt {
2663 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2664 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2666 "BS power control should not be active unless we receive a power parameters IE!");
2667 }
2668 repeat;
2669 }
2670 [] L1CTL.receive { repeat; }
2671 [] T1.timeout { setverdict(pass); }
2672 }
2673
2674 f_rsl_chan_deact();
2675 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2676
2677}
2678
Eric Wild095024b2019-06-17 15:08:57 +02002679/* see if we change the power level without receiving power parameters, which should not happen
2680ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002681private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002682 var L1ctlDlMessage l1_dl;
2683
2684 /* set a high value to ensure power decreases */
2685 f_trxc_fake_rssi(rxlev2dbm(50));
2686 f_l1_tune(L1CTL);
2687 RSL.clear;
2688
2689 var uint5_t pwr_var := 5;
2690
2691 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2692 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2693
2694 /* establish with fixed power level */
2695 f_est_dchan(more_ies :={valueof(pwr)});
2696
2697 /* check our initial power level */
2698 f_wait_for_l1_power_level(pwr_var);
2699
2700 /* pwr control without power params IE, should NOT activate MS power control*/
2701 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2702
2703 /* wait, then check that our power level did not change */
2704 timer T1 := 10.0;
2705 T1.start;
2706 alt {
2707 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2708 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2710 "BS power control should not be active unless we receive a power parameters IE!");
2711 }
2712 repeat;
2713 }
2714 [] L1CTL.receive { repeat; }
2715 [] T1.timeout { setverdict(pass); }
2716 }
2717
2718 f_rsl_chan_deact();
2719 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2720
2721}
2722
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002723private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002724 var L1ctlDlMessage l1_dl;
2725 timer T0 := 10.0;
2726 T0.start;
2727 alt {
2728 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2729 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2731 "Power level in L1 header != signaled (RSL) power level.");
2732 }
2733 }
2734 [] L1CTL.receive { repeat; }
2735 [] T0.timeout {
2736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2737 "Timeout waiting for initial power level");
2738 }
2739 }
2740 T0.stop;
2741}
2742
2743private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2744 var IntegerRecord min_dbm_level;
2745 var IntegerRecord max_dbm_level;
2746 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2747
2748 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2749 if (min_dbm_level[i] == level) {
2750 return true;
2751 }
2752 }
2753 return false;
2754}
2755
2756private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2757 var IntegerRecord min_dbm_level;
2758 var IntegerRecord max_dbm_level;
2759 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2760
2761 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2762 if (max_dbm_level[i] == level) {
2763 return true;
2764 }
2765 }
2766 return false;
2767}
2768
2769private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2770 var IntegerRecord min_dbm_level;
2771 var IntegerRecord max_dbm_level;
2772 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2773 return max_dbm_level[0];
2774}
2775
2776type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002777private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002778private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2779 // 45.005 4.1.1
2780 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2781 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2782 2, 1, 0};
2783 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2784 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2785 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2786 var IntegerRecord rv;
2787
2788 select(band){
2789 case (BtsBand_allGSM){
2790 rv := gsm_power;
2791 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2792 max_dbm_level := {2, 1, 0};
2793 }
2794 case("DCS1800"){
2795 rv := dcs_power;
2796 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2797 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2798 }
2799 case("PCS1900"){
2800 rv := pcs_power;
2801 min_dbm_level := {15};
2802 max_dbm_level := {30};
2803 }
2804 }
2805
2806 return rv;
2807}
2808
2809private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2810 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2811}
2812
2813testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2814 var ConnHdlr vc_conn;
2815 var ConnHdlrPars pars;
2816 f_init();
2817 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2818 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2819 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2820 pars.bts0_band := f_vty_get_bts0_band();
2821 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2822 vc_conn.done;
2823 }
2824 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2826}
2827
2828testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2829 var ConnHdlr vc_conn;
2830 var ConnHdlrPars pars;
2831 f_init();
2832 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2833 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2834 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2835 pars.bts0_band := f_vty_get_bts0_band();
2836 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2837 vc_conn.done;
2838 }
2839 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2841}
2842
2843testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2844 var ConnHdlr vc_conn;
2845 var ConnHdlrPars pars;
2846 f_init();
2847 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2848 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2849 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2850 pars.bts0_band := f_vty_get_bts0_band();
2851 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2852 vc_conn.done;
2853 }
2854 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2856}
2857
2858testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2859 var ConnHdlr vc_conn;
2860 var ConnHdlrPars pars;
2861 f_init();
2862 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2863 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2864 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2865 pars.bts0_band := f_vty_get_bts0_band();
2866 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2867 vc_conn.done;
2868 }
2869 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2871}
2872
Eric Wild280ccb82019-06-17 11:11:52 +02002873testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2874 var ConnHdlr vc_conn;
2875 var ConnHdlrPars pars;
2876 f_init();
2877 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2878 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2879 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2880 pars.bts0_band := f_vty_get_bts0_band();
2881 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2882 vc_conn.done;
2883 }
2884 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2886}
2887
Eric Wild095024b2019-06-17 15:08:57 +02002888testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2889 var ConnHdlr vc_conn;
2890 var ConnHdlrPars pars;
2891 f_init();
2892 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2893 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2894 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2895 pars.bts0_band := f_vty_get_bts0_band();
2896 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2897 vc_conn.done;
2898 }
2899 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2901}
2902
Harald Welte70767382018-02-21 12:16:40 +01002903testcase TC_meas_res_sign_tchf() runs on test_CT {
2904 var ConnHdlr vc_conn;
2905 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002906 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002907 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2908 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002909 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2910 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002911 vc_conn.done;
2912 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002914}
2915testcase TC_meas_res_sign_tchh() runs on test_CT {
2916 var ConnHdlr vc_conn;
2917 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002918 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002919 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2920 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002921 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2922 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002923 vc_conn.done;
2924 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002926}
2927testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2928 var ConnHdlr vc_conn;
2929 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002930 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002931 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2932 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002933 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2934 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002935 vc_conn.done;
2936 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002938}
2939testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2940 var ConnHdlr vc_conn;
2941 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002942 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002943 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2944 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002945 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2946 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002947 vc_conn.done;
2948 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002950}
Harald Welte685d5982018-02-27 20:42:05 +01002951testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2952 var ConnHdlr vc_conn;
2953 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002954 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002955 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2956 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2957 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2958 pars.l1_pars.toa256_enabled := true;
2959 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2960 vc_conn.done;
2961 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002963}
2964
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002965/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2966 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002967private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002968 var L1ctlDlMessage l1_dl;
2969 var RSL_IE_MS_Power ms_power;
2970 var RSL_Message rsl;
2971 var uint5_t power_level := 0;
2972
2973 f_l1_tune(L1CTL);
2974 RSL.clear;
2975
2976 f_est_dchan();
2977
2978 ms_power.reserved := 0;
2979 ms_power.fpc_epc := false;
2980
2981 /* Send the first power control command. This will disable any BTS/TRX
2982 * internal power control and switch the MS (which is not in scope of
2983 * this test) to a constant power level. We start with a power level
2984 * of 0 */
2985 ms_power.power_level := power_level;
2986 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2987 RSL.send(rsl);
2988
2989 alt {
2990
2991 /* Pick all SACCH blocks for checking */
2992 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2993
2994 /* The first byte of the L1 header contains the power level.
2995 * The reserved bits and the fpc bit is set to 0, so we may
2996 * compare directly. */
2997 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2998 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2999 }
3000
3001 /* Signal a new power level via RSL for the next turn. */
3002 if (power_level < 31) {
3003 power_level := power_level + 1;
3004 ms_power.power_level := power_level;
3005 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3006 RSL.send(rsl);
3007 repeat;
3008 }
3009
3010 }
3011
3012 /* Ignore all other blocks */
3013 [] L1CTL.receive { repeat; }
3014
3015 }
3016
3017 f_rsl_chan_deact();
3018 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3019
3020 setverdict(pass);
3021}
3022
3023testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3024 var ConnHdlr vc_conn;
3025 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003026 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003027
3028 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3029 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3030 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3031 vc_conn.done;
3032 }
3033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3034}
Harald Welte70767382018-02-21 12:16:40 +01003035
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003036/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003037TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003038private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003039 var L1ctlDlMessage l1_dl;
3040 var uint5_t ta_to_test := 16;
3041
3042
3043 f_l1_tune(L1CTL);
3044 RSL.clear;
3045
3046 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003047 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003048
3049 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3050
3051
3052 alt {
3053
3054 /* Pick all SACCH blocks for checking */
3055 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3056
3057 /* The second byte of the L1 header contains the TA. */
3058 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3059 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3060 }
3061
3062 }
3063
3064 /* Ignore all other blocks */
3065 [] L1CTL.receive { repeat; }
3066
3067 }
3068
3069 f_rsl_chan_deact();
3070 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3071
3072 setverdict(pass);
3073}
3074
3075testcase TC_rsl_chan_initial_ta() runs on test_CT {
3076 var ConnHdlr vc_conn;
3077 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003078 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003079 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003080 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3081 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003082 vc_conn.done;
3083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3084}
3085
Eric Wilde57e1a62019-05-28 13:30:55 +02003086/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003087private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003088 var L1ctlDlMessage l1_dl;
3089 var uint5_t ms_power_level := 7;
3090
3091 var RSL_IE_MS_Power ms_power;
3092 ms_power.reserved := 0;
3093 ms_power.fpc_epc := false;
3094 ms_power.power_level := ms_power_level;
3095
3096 f_l1_tune(L1CTL);
3097 RSL.clear;
3098
3099 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3100
3101 timer T := 1.0;
3102 T.start;
3103 alt {
3104 /* Pick all SACCH blocks for checking */
3105 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3106 /* The first byte of the L1 header contains the power level.. */
3107 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3108 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3109 }
3110 }
3111 /* Ignore all other blocks */
3112 [] L1CTL.receive { repeat; }
3113 [] T.timeout {
3114 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3115 }
3116 }
3117
3118 f_rsl_chan_deact();
3119 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3120 setverdict(pass);
3121}
3122
3123testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3124 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3125 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3126}
3127
Harald Welte0472ab42018-03-12 15:02:26 +01003128/* 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 +01003129private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003130 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003131 RSL.clear;
3132
3133 f_est_dchan();
3134 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003135 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003136
3137 timer T := 40.0;
3138 T.start;
3139 alt {
3140 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3141 setverdict(pass)
3142 }
3143 [] RSL.receive { repeat };
3144 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003146 }
3147 }
3148 f_rsl_chan_deact();
3149}
3150testcase TC_conn_fail_crit() runs on test_CT {
3151 var ConnHdlr vc_conn;
3152 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003153 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003154 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3155 pars.t_guard := 60.0;
3156 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3157 vc_conn.done;
3158}
3159
Harald Welte93640c62018-02-25 16:59:33 +01003160/***********************************************************************
3161 * Paging
3162 ***********************************************************************/
3163
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003164private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003165 if (tmsi == 'FFFFFFFF'O) {
3166 return true;
3167 } else {
3168 return false;
3169 }
3170}
Harald Welte70767382018-02-21 12:16:40 +01003171
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003172private type record allowedFn { integer frame_nr }
3173private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3174private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3175private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3176private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3177private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3178private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3179private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3180private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3181private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003182{
3183 var integer frame_nr_51;
3184 frame_nr_51 := frame_nr mod 51
3185
3186 var allowedFn fn_check;
3187 fn_check.frame_nr := frame_nr_51;
3188
3189 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003191 return;
3192 }
3193
3194 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3195 return;
3196 }
3197 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3198 return;
3199 }
3200 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3201 return;
3202 }
3203 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3204 return;
3205 }
3206 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3207 return;
3208 }
3209 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3210 return;
3211 }
3212 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3213 return;
3214 }
3215 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3216 return;
3217 }
3218
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003220 return;
3221}
3222
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003223private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3224 inout integer num_paging_rcv_ids,
3225 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003226runs on test_CT {
3227 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003228 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003229 repeat;
3230 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003231 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003232 var octetstring without_plen :=
3233 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3234 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003235
3236 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3237
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003238 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3239 /* Ignore empty RR Paging Request (PCH filling) messages.
3240 * TODO: does it make sense to count them? */
3241 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003242 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3243 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003244 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003245 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3246 }
3247 } else if (match(rr, tr_PAGING_REQ2)) {
3248 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3249 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3250 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3251 }
3252 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3253 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3254 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003255 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003256 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3257 }
3258 } else if (match(rr, tr_PAGING_REQ3)) {
3259 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3260 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3261 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3262 }
3263 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3264 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3265 }
3266 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3267 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3268 }
3269 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3270 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3271 }
3272 }
3273 repeat;
3274 }
3275}
3276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003277private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003278 boolean combined_ccch,
3279 integer bs_ag_blks_res,
3280 float load_factor,
3281 boolean exp_load_ind,
3282 boolean exp_overload,
3283 boolean use_tmsi
3284}
3285
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003286private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003287 integer num_paging_sent,
3288 integer num_paging_rcv_msgs,
3289 integer num_paging_rcv_ids,
3290 integer num_overload
3291}
3292
Harald Welte68e495b2018-02-25 00:05:57 +01003293/* Helper function for paging related testing */
3294private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003295 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003296 f_init_l1ctl();
3297 f_l1_tune(L1CTL);
3298
3299 var PagingTestState st := {
3300 num_paging_sent := 0,
3301 num_paging_rcv_msgs := 0,
3302 num_paging_rcv_ids := 0,
3303 num_overload := 0
3304 };
3305
3306 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3307 var float max_pch_imsi_per_sec;
3308 if (cfg.use_tmsi) {
3309 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3310 } else {
3311 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3312 }
3313 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3314 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003315 var float time_total := 20.0;
3316 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3317 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003318
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003319 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3320 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003321
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003322 timer T_itv := 0.0;
3323 T_itv.start;
3324 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003325 alt {
3326 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003327 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003328 st.num_overload := st.num_overload + 1;
3329 repeat;
3330 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003331 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003333 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003334 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003335 log("Rx LOAD_IND");
3336 /* FIXME: analyze/verify interval + contents */
3337 repeat;
3338 }
3339 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003340 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003341 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003342 [] T_itv.timeout {
3343 /* Send paging cmds based on elapsed time */
3344 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3345 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003346 var MobileIdentityV mi;
3347
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003348 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003349 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003350 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003351 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003352 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003353 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003354
3355 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003356 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, st.num_paging_sent mod 4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003357
3358 st.num_paging_sent := st.num_paging_sent + 1;
3359 }
3360 if (st.num_paging_sent < pkt_total) {
3361 /* Wait for interval to next PAGING COMMAND */
3362 var float time_now := T_total.read;
3363 var float next_sched := int2float(st.num_paging_sent)*interval;
3364 if (next_sched > time_now) {
3365 T_itv.start(next_sched - time_now);
3366 } else {
3367 T_itv.start(0.0);
3368 }
3369 } else {
3370 /* We are done, no need to keep counting */
3371 T_total.stop;
3372 }
3373 }
3374 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003375 }
3376 }
3377
3378 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3379 timer T_wait := 18.0;
3380 T_wait.start;
3381 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003382 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003383 [] L1CTL.receive { repeat; }
3384 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003385 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3386 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003387 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003389 }
Harald Welte68e495b2018-02-25 00:05:57 +01003390 }
3391
3392 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3393 " rcvd_ids=", st.num_paging_rcv_ids);
3394 return st;
3395}
3396
3397/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3398 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3399 * - that CCCH LOAD IND (PCH) are being generated
3400 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3401testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003402 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003403 var PagingTestCfg cfg := {
3404 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003405 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003406 load_factor := 0.8,
3407 exp_load_ind := true,
3408 exp_overload := false,
3409 use_tmsi := false
3410 };
3411 var PagingTestState st := f_TC_paging(cfg);
3412 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3414 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003415 } else {
3416 setverdict(pass);
3417 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003419}
3420
3421/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3422 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3423 * - that CCCH LOAD IND (PCH) are being generated
3424 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3425testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003426 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003427 var PagingTestCfg cfg := {
3428 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003429 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003430 load_factor := 0.8,
3431 exp_load_ind := true,
3432 exp_overload := false,
3433 use_tmsi := true
3434 };
3435 var PagingTestState st := f_TC_paging(cfg);
3436 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3438 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003439 } else {
3440 setverdict(pass);
3441 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003443}
3444
3445/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3446 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3447 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3448 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3449testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003450 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003451 var PagingTestCfg cfg := {
3452 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003453 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003454 load_factor := 2.0,
3455 exp_load_ind := true,
3456 exp_overload := true,
3457 use_tmsi := false
3458 };
3459 var PagingTestState st := f_TC_paging(cfg);
3460 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3461 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003462 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003463 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 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 +01003465 } else {
3466 setverdict(pass);
3467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003469}
3470
3471/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3472 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3473 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3474 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3475testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003476 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003477 var PagingTestCfg cfg := {
3478 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003479 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003480 load_factor := 2.0,
3481 exp_load_ind := true,
3482 exp_overload := true,
3483 use_tmsi := true
3484 };
3485 var PagingTestState st := f_TC_paging(cfg);
3486 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3487 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003488 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003489 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003490 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 +01003491 } else {
3492 setverdict(pass);
3493 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003495}
3496
3497
Harald Welte93640c62018-02-25 16:59:33 +01003498/***********************************************************************
3499 * Immediate Assignment / AGCH
3500 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003501private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003502 len := 0,
3503 ma := ''B
3504}
Harald Welte93640c62018-02-25 16:59:33 +01003505
Harald Weltee8d750e2018-06-10 21:41:35 +02003506private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3507 return int2str(num_tx) & " sent, "
3508 & int2str(num_rx) & " received, "
3509 & int2str(num_del) & " deleted";
3510}
3511
3512private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3513 var L1ctlDlMessage l1_dl;
3514 timer T := 10.0;
3515 var integer num_tx := 0;
3516 var integer num_rx := 0;
3517 var integer num_del := 0;
3518 var charstring res_str;
3519 var float rx_ratio;
3520
Harald Welte10474062019-05-30 16:48:17 +02003521 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003522 f_init_l1ctl();
3523 f_l1_tune(L1CTL);
3524
3525 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003526 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003527 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3528 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003529 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003530 num_tx := num_tx+1;
3531 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003532 }
3533 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003534 T.start;
3535 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003536 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003537 num_del := num_del+1;
3538 repeat;
3539 }
3540 [] RSL_CCHAN.receive {
3541 repeat;
3542 }
3543 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003544 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3545 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3546 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003547 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003548 } else {
3549 num_rx := num_rx+1;
3550 }
3551 repeat;
3552 }
3553 [] L1CTL.receive { repeat; }
3554 [] T.timeout { }
3555 }
3556 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3557 log("AGCH test: " & res_str);
3558 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003560 }
3561 rx_ratio := int2float(num_rx) / int2float(num_tx);
3562 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003563 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 +02003564 } else {
3565 setverdict(pass);
3566 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003568}
3569
Harald Weltee8d750e2018-06-10 21:41:35 +02003570/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3571testcase TC_imm_ass_1000_20ms() runs on test_CT {
3572 f_TC_imm_ass(1000, 0.02, 0.25);
3573}
3574
3575/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3576testcase TC_imm_ass_200_0ms() runs on test_CT {
3577 f_TC_imm_ass(200, 0.0, 0.05);
3578}
3579
3580/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3581testcase TC_imm_ass_200_76ms() runs on test_CT {
3582 f_TC_imm_ass(150, 0.076, 1.00);
3583}
3584
3585
3586
Harald Welte48494ca2018-02-25 16:59:50 +01003587/***********************************************************************
3588 * BCCH
3589 ***********************************************************************/
3590
3591/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003592private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003593 GsmFrameNumber frame_number,
3594 SystemInformation si
3595}
3596
3597/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003598private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003599
3600/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003601private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003602
3603/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003604private function f_si_vecslot_contains(SystemInformationVector arr,
3605 RrMessageType key,
3606 boolean bcch_ext := false)
3607return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003608 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3609 var integer fn_mod51 := arr[i].frame_number mod 51;
3610 if (not bcch_ext and fn_mod51 == 2 or
3611 bcch_ext and fn_mod51 == 6) {
3612 if (arr[i].si.header.message_type == key) {
3613 return true;
3614 }
3615 }
3616 }
3617 return false;
3618}
3619
3620/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003621private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3622 integer tc, RrMessageType key,
3623 boolean ext_bcch := false)
3624{
Harald Welte48494ca2018-02-25 16:59:50 +01003625 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003627 }
3628}
3629
3630/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003631private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3632 RrMessageType key)
3633return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003634 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3635 if (f_si_vecslot_contains(arr[tc], key) or
3636 f_si_vecslot_contains(arr[tc], key, true)) {
3637 return true;
3638 }
3639 }
3640 return false;
3641}
3642
3643/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003644private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3645 RrMessageType key,
3646 boolean bcch_ext := false,
3647 integer n := 1, integer m := 4)
3648return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003649 var integer count := 0;
3650 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003652 }
3653 for (var integer i:= 0; i < m; i := i + 1) {
3654 var integer fn_mod51 := arr[i].frame_number mod 51;
3655 if (not bcch_ext and fn_mod51 == 2 or
3656 bcch_ext and fn_mod51 == 6) {
3657 if (arr[i].si.header.message_type == key) {
3658 count := count + 1;
3659 }
3660 }
3661 }
3662 if (count >= n) {
3663 return true;
3664 } else {
3665 return false;
3666 }
3667}
3668
3669/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003670private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3671 integer tc, RrMessageType key,
3672 boolean ext_bcch := false,
3673 integer n, integer m)
3674{
Harald Welte48494ca2018-02-25 16:59:50 +01003675 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003677 }
3678}
3679
3680/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003681private function f_si_vecslot_contains_only(SystemInformationVector arr,
3682 RrMessageType key,
3683 boolean bcch_ext := false)
3684return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003685 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3686 var integer fn_mod51 := arr[i].frame_number mod 51;
3687 if (not bcch_ext and fn_mod51 == 2 or
3688 bcch_ext and fn_mod51 == 6) {
3689 if (arr[i].si.header.message_type != key) {
3690 return false;
3691 }
3692 }
3693 }
3694 return true;
3695}
3696
3697/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003698private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3699 integer tc, RrMessageType key,
3700 boolean ext_bcch := false)
3701{
Harald Welte48494ca2018-02-25 16:59:50 +01003702 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003704 }
3705}
3706
3707/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003708private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003709 boolean bcch_extended,
3710 boolean si1_present,
3711 boolean si2bis_present,
3712 boolean si2ter_present,
3713 boolean si2quater_present,
3714 boolean si7_present,
3715 boolean si8_present,
3716 boolean si9_present,
3717 boolean si13_present,
3718 boolean si13alt_present,
3719 boolean si15_present,
3720 boolean si16_present,
3721 boolean si17_present,
3722 boolean si2n_present,
3723 boolean si21_present,
3724 boolean si22_present
3725}
3726
3727/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003728private function f_validate_si_scheduling(SystemInformationConfig cfg,
3729 SystemInformationVectorPerTc si_per_tc)
3730{
Harald Welte48494ca2018-02-25 16:59:50 +01003731 var integer i;
3732 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3733 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003735 }
3736 }
3737 if (cfg.si1_present) {
3738 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3739 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3740 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3741 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3742 /* make sure *ALL* contain SI1 */
3743 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3744 }
3745 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3746 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3747 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3748 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3749 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3750 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3751
3752 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3753 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3754 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3755 * consecutive occurrences of TC = 4. */
3756 if (cfg.si2bis_present and not cfg.si2ter_present) {
3757 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3758 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3759 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3760 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3761 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3762 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3763 }
3764
3765 if (cfg.si7_present or cfg.si8_present) {
3766 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3767 * if System Information type 4 does not contain all information needed for cell
3768 * selection and reselection. */
3769 if (not cfg.bcch_extended) {
3770 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3771 }
3772 if (cfg.si7_present) {
3773 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3774 }
3775 if (cfg.si8_present) {
3776 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3777 }
3778 }
3779
3780 if (cfg.si2quater_present) {
3781 /* iii) System information type 2 quater is sent if needed, as determined by the system
3782 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3783 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3784 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3785 * within any of 4 consecutive occurrences of TC = 5. */
3786 if (not (cfg.bcch_extended)) {
3787 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3788 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3789 } else {
3790 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3791 }
3792 } else {
3793 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3794 }
3795 }
3796 if (cfg.si9_present) {
3797 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3798 * in system information type 3 as defined in 3GPP TS 44.018. */
3799 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3800 }
3801 if (cfg.si13_present) {
3802 /* vii) System Information type 13 is only related to the GPRS service. System Information
3803 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3804 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3805 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3806 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3807 * within any of 4 consecutive occurrences of TC=4. */
3808 if (not cfg.bcch_extended) {
3809 log("not-bccch-extended");
3810 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3811 } else {
3812 log("bccch-extended");
3813 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3814 }
3815 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003817 }
3818 }
3819 if (cfg.si16_present or cfg.si17_present) {
3820 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3821 * should not be sent in a cell where network sharing is used (see rule xv). */
3822 if (cfg.si22_present) {
3823 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3824 }
3825 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003827 }
3828 if (not cfg.bcch_extended) {
3829 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3830 }
3831 if (cfg.si16_present) {
3832 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3833 }
3834 if (cfg.si17_present) {
3835 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3836 }
3837 }
3838
3839 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3840 * broadcast information. The frequency with which they are sent is determined by the
3841 * system operator. System Information type 9 identifies the scheduling of System
3842 * Information type 18 and 20 messages. */
3843
3844 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3845 * Information Type 19 is present, then its scheduling shall be indicated in System
3846 * Information Type 9. */
3847
3848 if (cfg.si15_present) {
3849 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3850 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3851 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3852 * 4 consecutive occurrences of TC = 1. */
3853 if (not cfg.bcch_extended) {
3854 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3855 } else {
3856 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3857 }
3858 }
3859 if (cfg.si13alt_present) {
3860 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3861 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3862 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3863 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3864 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3865 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3866 * of TC = 4. */
3867 if (cfg.si13_present) {
3868 testcase.stop("Error: Cannot have SI13alt and SI13");
3869 }
3870 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003872 }
3873 if (not cfg.bcch_extended) {
3874 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3875 } else {
3876 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3877 }
3878 }
3879 if (cfg.si2n_present) {
3880 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3881 * as determined by the system operator. In the case that the message is sent on the
3882 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3883 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3884 * consecutive occurrences of TC = 4. */
3885 if (not cfg.bcch_extended) {
3886 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3887 } else {
3888 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3889 }
3890 }
3891 if (cfg.si21_present) {
3892 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3893 * determined by the system operator. If Extended Access Barring is in use in the cell
3894 * then this message is sent at least once within any of 4 consecutive occurrences of
3895 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3896 * cell then this message shall only be sent on BCCH Ext. */
3897 if (not cfg.bcch_extended) {
3898 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3899 } else {
3900 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3901 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003903 }
3904 }
3905 }
3906 if (cfg.si22_present) {
3907 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3908 * should not be sent in a cell where SoLSA is used (see rule viii). System
3909 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3910 * =2 and TC=6. */
3911 if (cfg.si16_present or cfg.si17_present) {
3912 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3913 }
3914 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3915 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003917 }
3918 if (not cfg.bcch_extended) {
3919 testcase.stop("Error: SI22 requires BCCH Extd!");
3920 } else {
3921 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3922 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3923 }
3924 }
3925}
3926
3927/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003928private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3929return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003930 timer T := duration;
3931 var SystemInformationVectorPerTc si_per_tc;
3932 var L1ctlDlMessage l1_dl;
3933
3934 /* initialize all per-TC vectors empty */
3935 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3936 si_per_tc[i] := {};
3937 }
3938
3939 /* flush all previous L1 queued msgs */
3940 pt.clear;
3941
3942 T.start;
3943 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003944 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003945 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3946 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3947 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003948 repeat;
3949 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003950
Harald Welte48494ca2018-02-25 16:59:50 +01003951 var integer tc := f_gsm_compute_tc(sig.frame_number);
3952 log("SI received at TC=", tc, ": ", sig.si);
3953 /* append to the per-TC bucket */
3954 si_per_tc[tc] := si_per_tc[tc] & { sig };
3955 repeat;
3956 }
3957 [] pt.receive { repeat; }
3958 [] T.timeout { }
3959 }
3960
3961 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3962 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3963 }
3964 log("si_per_tc=", si_per_tc);
3965 return si_per_tc;
3966}
3967
3968/* helper function: Set given SI via RSL + validate scheduling.
3969 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003970private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003971 var SystemInformationVectorPerTc si_per_tc;
3972 f_init_l1ctl();
3973 f_l1_tune(L1CTL);
3974
3975 /* Sample + Validate Scheduling */
3976 si_per_tc := f_l1_sample_si(L1CTL);
3977 f_validate_si_scheduling(si_cfg, si_per_tc);
3978
3979 setverdict(pass);
3980}
3981
3982testcase TC_si_sched_default() runs on test_CT {
3983 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003984 /* 2+3+4 are mandatory and set in f_init() */
3985 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003987}
3988
3989testcase TC_si_sched_1() runs on test_CT {
3990 f_init();
3991 si_cfg.si1_present := true;
3992 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003993 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003995}
3996
3997testcase TC_si_sched_2bis() runs on test_CT {
3998 f_init();
3999 si_cfg.si2bis_present := true;
4000 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4001 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004003}
4004
4005testcase TC_si_sched_2ter() runs on test_CT {
4006 f_init();
4007 si_cfg.si2ter_present := true;
4008 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4009 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004011}
4012
4013testcase TC_si_sched_2ter_2bis() runs on test_CT {
4014 f_init();
4015 si_cfg.si2bis_present := true;
4016 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4017 si_cfg.si2ter_present := true;
4018 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4019 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004021}
4022
4023testcase TC_si_sched_2quater() runs on test_CT {
4024 f_init();
4025 si_cfg.si2quater_present := true;
4026 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4027 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004029}
4030
4031testcase TC_si_sched_13() runs on test_CT {
4032 f_init();
4033 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004034 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004035 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004037}
4038
4039testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4040 f_init();
4041 si_cfg.si2bis_present := true;
4042 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4043 si_cfg.si2ter_present := true;
4044 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4045 si_cfg.si2quater_present := true;
4046 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4047 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004048 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004049 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004051}
4052
4053
Harald Welte68e495b2018-02-25 00:05:57 +01004054testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004055 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004056 /* FIXME: enable / disable individual BCCH info */
4057 //ts_RSL_BCCH_INFO(si_type, info);
4058 /* expect no ERROR REPORT after either of them *
4059 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004061}
4062
Harald Welte93640c62018-02-25 16:59:33 +01004063/***********************************************************************
4064 * Low-Level Protocol Errors / ERROR REPORT
4065 ***********************************************************************/
4066
Harald Welte01d982c2018-02-25 01:31:40 +01004067private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4068 timer T := 5.0;
4069 T.start;
4070 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004071 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004072 setverdict(pass);
4073 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004074 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004075 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004076 }
4077 [] RSL_CCHAN.receive {
4078 repeat;
4079 }
4080 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004082 }
4083 }
4084}
4085
4086/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4087testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004088 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004089 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4090 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004091 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004092
4093 f_exp_err_rep(RSL_ERR_PROTO);
4094}
4095
4096/* Provoke a mandatory IE error and match on ERROR REPORT */
4097testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004098 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004099
4100 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4101 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004102 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004103
4104 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4105}
4106
4107/* Provoke an IE content error and match on ERROR REPORT */
4108testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004109 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004110 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4111 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004112 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004113
4114 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4115}
4116
Harald Welteee25aae2019-05-19 14:32:37 +02004117/* attempt to activate channel with wrong RSL Message Discriminator IE */
4118function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4119 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4120 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4121 RSL.send(rsl);
4122 f_rslem_unregister(0, g_chan_nr);
4123}
4124testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4125 var ConnHdlr vc_conn;
4126 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4127
Harald Welte10474062019-05-30 16:48:17 +02004128 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004129
4130 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4131 vc_conn.done;
4132 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4133
4134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4135}
4136
4137/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004138private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004139 var template (value) RSL_Message rsl_tx;
4140 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4141 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4142 RSL.send(rsl_tx);
4143 f_rslem_unregister(0, g_chan_nr);
4144}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004145private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004146 var template (value) RSL_Message rsl_tx;
4147 /* we first have to activate the dedicated channel */
4148 f_rsl_chan_act(g_pars.chan_mode);
4149 /* ... to then send an invalid RLL message */
4150 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4151 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4152 RSL.send(rsl_tx);
4153 f_rslem_unregister(0, g_chan_nr);
4154}
4155testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4156 var ConnHdlr vc_conn;
4157 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4158 var template (value) RSL_Message rsl_tx;
4159
Harald Welte10474062019-05-30 16:48:17 +02004160 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004161
4162 /* Common Channel with wrong message type */
4163 RSL_CCHAN.clear;
4164 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4165 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004166 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004167 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4168
4169 /* TRX Management */
4170 RSL_CCHAN.clear;
4171 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4172 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004173 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004174 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4175
4176 /* Dedicated Channel */
4177 RSL_CCHAN.clear;
4178 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4179 vc_conn.done;
4180 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4181
4182 /* RLL */
4183 RSL_CCHAN.clear;
4184 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4185 vc_conn.done;
4186 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4187}
4188
4189/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004190private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004191 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4192 f_rslem_unregister(0, g_chan_nr);
4193}
4194testcase TC_err_rep_wrong_sequence() runs on test_CT {
4195 var ConnHdlr vc_conn;
4196 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4197
Harald Welte10474062019-05-30 16:48:17 +02004198 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004199
4200 RSL_CCHAN.clear;
4201 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4202 vc_conn.done;
4203 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4204}
4205
Harald Welte93640c62018-02-25 16:59:33 +01004206/***********************************************************************
4207 * IPA CRCX/MDCX/DLCS media stream handling
4208 ***********************************************************************/
4209
Harald Weltea871a382018-02-25 02:03:14 +01004210/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004211private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004212 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4213 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004214}
4215testcase TC_ipa_dlcx_not_active() runs on test_CT {
4216 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004217 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004218 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4219 vc_conn.done;
4220}
Harald Welte68e495b2018-02-25 00:05:57 +01004221
Harald Weltea3f1df92018-02-25 12:49:55 +01004222/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004223private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004224 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4225 "IPA CRCX ACK");
4226 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4227 "IPA CRCX NACK");
4228}
4229testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4230 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004231 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004232 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4233 vc_conn.done;
4234}
4235
4236/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004237private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004238 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4239 "IPA CRCX ACK");
4240 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4241 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4242 var uint7_t rtp_pt2 := f_rnd_int(127);
4243 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4244 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4245 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4246 "IPA MDCX ACK");
4247 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4248 "IPA DLCX ACK");
4249}
4250testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4251 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004252 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004253 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4254 vc_conn.done;
4255}
4256
Harald Welte3ae11da2018-02-25 13:36:06 +01004257/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004258private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004259 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4260 "IPA CRCX ACK");
4261 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4262 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4263 var uint7_t rtp_pt2 := f_rnd_int(127);
4264 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4265 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4266 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4267 "IPA MDCX ACK");
4268 /* Second MDCX */
4269 remote_ip := f_rnd_int(c_UINT32_MAX);
4270 remote_port := f_rnd_int(c_UINT16_MAX);
4271 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4272 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4273 "IPA MDCX ACK");
4274 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4275 "IPA DLCX ACK");
4276}
4277testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4278 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004279 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004280 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4281 vc_conn.done;
4282}
4283
Harald Welte9912eb52018-02-25 13:30:15 +01004284/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004285private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004286 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4287 "IPA CRCX NACK");
4288}
4289testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4290 var ConnHdlrPars pars;
4291 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004292 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004293
4294 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4295 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4296 vc_conn.done;
4297
4298 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4299 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4300 vc_conn.done;
4301}
4302
Harald Weltea3f1df92018-02-25 12:49:55 +01004303
Harald Welte883340c2018-02-28 18:59:29 +01004304/***********************************************************************
4305 * PCU Socket related tests
4306 ***********************************************************************/
4307
Harald Welte07bd2d22019-05-25 11:03:30 +02004308/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004309friend 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 +01004310runs on test_CT {
4311 timer T := 3.0;
4312
4313 /* we don't expect any RTS.req before PDCH are active */
4314 T.start;
4315 alt {
4316 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004318 }
4319 [] PCU.receive { repeat; }
4320 [] T.timeout { }
4321 }
4322
4323 /* Send PDCH activate request for known PDCH timeslot */
4324 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4325
4326 /* we now expect RTS.req for this timeslot (only) */
4327 T.start;
4328 alt {
4329 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4330 setverdict(pass);
4331 }
4332 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4333 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004335 }
4336 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004338 }
4339 [] PCU.receive { repeat; }
4340 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004342 }
4343 [not exp_success] T.timeout {
4344 setverdict(pass);
4345 }
4346 }
4347}
4348
Harald Welte07bd2d22019-05-25 11:03:30 +02004349/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004350friend 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 +01004351runs on test_CT {
4352 timer T := 3.0;
4353
4354 /* Send PDCH activate request for known PDCH timeslot */
4355 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4356
4357 PCU.clear;
4358 /* we now expect no RTS.req for this timeslot */
4359 T.start;
4360 alt {
4361 [] 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 +02004362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004363 }
4364 [] PCU.receive { repeat; }
4365 [] T.timeout {
4366 setverdict(pass);
4367 }
4368 }
4369}
4370
Harald Weltead033dc2019-05-25 17:28:16 +02004371friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004372 f_init();
4373 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4374}
4375
Harald Welte883340c2018-02-28 18:59:29 +01004376/* PDCH activation via PCU socket; check for presence of RTS.req */
4377testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004378 f_init_pcu_test();
4379
Harald Welte883340c2018-02-28 18:59:29 +01004380 f_TC_pcu_act_req(0, 0, 7, true);
4381}
4382
4383/* PDCH activation via PCU socket on non-PDCU timeslot */
4384testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004385 f_init_pcu_test();
4386
Harald Welte883340c2018-02-28 18:59:29 +01004387 f_TC_pcu_act_req(0, 0, 1, false);
4388}
4389
4390/* PDCH activation via PCU socket on wrong BTS */
4391testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004392 f_init_pcu_test();
4393
Harald Welte883340c2018-02-28 18:59:29 +01004394 f_TC_pcu_act_req(23, 0, 7, false);
4395}
4396
4397/* PDCH activation via PCU socket on wrong TRX */
4398testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004399 f_init_pcu_test();
4400
Harald Welte883340c2018-02-28 18:59:29 +01004401 f_TC_pcu_act_req(0, 23, 7, false);
4402}
4403
4404/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4405testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004406 f_init_pcu_test();
4407
Harald Welte883340c2018-02-28 18:59:29 +01004408 /* Activate PDCH */
4409 f_TC_pcu_act_req(0, 0, 7, true);
4410 f_sleep(1.0);
4411 /* and De-Activate again */
4412 f_TC_pcu_deact_req(0, 0, 7);
4413}
4414
4415/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4416testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004417 f_init_pcu_test();
4418
Harald Welte883340c2018-02-28 18:59:29 +01004419 f_TC_pcu_deact_req(0, 0, 1);
4420}
4421
4422/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4423testcase TC_pcu_ver_si13() runs on test_CT {
4424 const octetstring si13 := '00010203040506070909'O;
4425 var PCUIF_send_data sd;
4426 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004427 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004428
4429 /* Set SI13 via RSL */
4430 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004431
Harald Welte883340c2018-02-28 18:59:29 +01004432 T.start;
4433 alt {
4434 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4435 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4436 setverdict(pass);
4437 } else {
4438 repeat;
4439 }
4440 }
4441 [] PCU.receive { repeat; }
4442 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004444 }
4445 }
4446}
4447
4448private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4449
4450/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004451friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004452 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4453runs on test_CT
4454{
4455 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4456 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4457}
4458
4459/* 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 +02004460friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4461 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004462runs on test_CT
4463{
4464 var PCUIF_send_data sd;
4465
4466 timer T := 3.0;
4467 T.start;
4468 alt {
4469 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4470 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4471 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4472 sd.data.u.rts_req.fn, sapi, data);
4473 }
4474 [] PCU.receive { repeat; }
4475 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004477 }
4478 }
4479}
4480
4481/* Send DATA.req on invalid BTS */
4482testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004483 var TfiUsfArr tua := f_TfiUsfArrInit();
4484 var octetstring data := '0000'O & f_rnd_octstring(21);
4485
4486 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004487
Harald Welte883340c2018-02-28 18:59:29 +01004488 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004489 f_TfiUsfArrSet(tua, 7, 0);
4490 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4491 f_sleep(1.0);
4492
4493 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004494}
4495
4496/* Send DATA.req on invalid TRX */
4497testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004498 var TfiUsfArr tua := f_TfiUsfArrInit();
4499 var octetstring data := '0000'O & f_rnd_octstring(21);
4500
4501 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004502
Harald Welte883340c2018-02-28 18:59:29 +01004503 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004504 f_TfiUsfArrSet(tua, 7, 0);
4505 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4506 f_sleep(1.0);
4507
4508 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004509}
4510
4511/* Send DATA.req on invalid timeslot */
4512testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004513 var TfiUsfArr tua := f_TfiUsfArrInit();
4514 var octetstring data := '0000'O & f_rnd_octstring(21);
4515
4516 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004517
Harald Welte883340c2018-02-28 18:59:29 +01004518 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004519 f_TfiUsfArrSet(tua, 7, 0);
4520 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4521 f_sleep(1.0);
4522
4523 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004524}
4525
4526/* Send DATA.req on timeslot that hasn't been activated */
4527testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004528 var TfiUsfArr tua := f_TfiUsfArrInit();
4529 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004530
Harald Welte7162a612019-05-26 12:56:09 +02004531 f_virtphy_common();
4532
4533 f_TfiUsfArrSet(tua, 7, 0);
4534 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4535 f_sleep(1.0);
4536
4537 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004538}
4539
Harald Weltead033dc2019-05-25 17:28:16 +02004540private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004541 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4542 boolean wait_rts := true)
4543runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004544 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004545 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004546
4547 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004548 if (wait_rts) {
4549 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4550 } else {
4551 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4552 }
Harald Weltead033dc2019-05-25 17:28:16 +02004553
4554 T.start;
4555 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004556 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004557 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4558 setverdict(pass);
4559 }
Harald Welte7162a612019-05-26 12:56:09 +02004560 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4561 setverdict(fail, "Received unexpected ", rx_dl);
4562 }
Harald Weltead033dc2019-05-25 17:28:16 +02004563 [] L1CTL.receive {
4564 repeat;
4565 }
Harald Welte7162a612019-05-26 12:56:09 +02004566 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004567 setverdict(fail, "Timeout waiting for ", data);
4568 }
Harald Welte7162a612019-05-26 12:56:09 +02004569 [not expect_data] T.timeout {
4570 setverdict(pass);
4571 }
Harald Weltead033dc2019-05-25 17:28:16 +02004572 }
4573}
4574
4575private function f_disable_dynamic_ts() runs on test_CT
4576{
4577 f_init_vty_bsc();
4578 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4579 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4580 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4581 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004582 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004583}
4584
4585private function f_virtphy_common() runs on test_CT {
4586 f_disable_dynamic_ts();
4587 f_init_l1ctl();
4588 f_l1_tune(L1CTL);
4589}
4590
4591testcase TC_pcu_data_req_pdtch() runs on test_CT {
4592 var TfiUsfArr tua := f_TfiUsfArrInit();
4593 var octetstring data := '0000'O & f_rnd_octstring(21);
4594
4595 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004596
Harald Welte883340c2018-02-28 18:59:29 +01004597 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004598 f_TfiUsfArrSet(tua, 7, 0);
4599 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4600 f_sleep(1.0);
4601
4602 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004603}
4604
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004605/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004606testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004607 var TfiUsfArr tua := f_TfiUsfArrInit();
4608 var octetstring data := '0000'O & f_rnd_octstring(21);
4609
4610 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004611
Harald Welte883340c2018-02-28 18:59:29 +01004612 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004613 f_TfiUsfArrSet(tua, 7, 0);
4614 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4615 f_sleep(1.0);
4616
4617 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004618}
4619
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004620private function f_TC_pcu_ptcch_ul(uint16_t ra)
4621runs on test_CT {
4622 var template PCUIF_Message pcu_rach_ind;
4623 var PCUIF_send_data sd;
4624 var GsmFrameNumber fn;
4625 timer T;
4626
4627 /* Send an Access Burst on PTCCH/U over the Um-interface */
4628 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4629 chan_nr := ts_RslChanNr_PDCH(7),
4630 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4631
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004632 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4633 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004634
4635 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4636 T.start(52.0 * 4.615 / 1000.0);
4637 alt {
4638 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4639 log("Rx an Access Burst on the PCU interface: ", sd.data);
4640 setverdict(pass);
4641 T.stop;
4642 }
4643 [] PCU.receive { repeat; }
4644 [] T.timeout {
4645 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4646 /* Keep going, that's not the end of the world */
4647 }
4648 }
4649}
4650
4651testcase TC_pcu_ptcch() runs on test_CT {
4652 var L1ctlDlMessage dl;
4653 var octetstring data;
4654 timer T;
4655
4656 f_init_pcu_test();
4657 f_init_l1ctl();
4658 f_l1_tune(L1CTL);
4659
4660 /* Activate PDCH channel on TS7 */
4661 f_TC_pcu_act_req(0, 0, 7, true);
4662
4663 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004664 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004665 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4666 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004667 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004668
4669 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4670 for (var integer i := 0; i < 16; i := i + 1) {
4671 log("Sending an Access Burst towards the L1CTL interface");
4672 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4673 }
4674
4675 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4676 data := f_rnd_octstring(23);
4677
4678 /* Verify PTCCH/D: send a random data block, make sure it's received */
4679 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4680 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4681
4682 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4683 * let's give it more time in case if we miss the beginning. */
4684 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4685 alt {
4686 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4687 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4688 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4689 frame := data)) -> value dl {
4690 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4691 setverdict(pass);
4692 T.stop;
4693 }
4694 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4695 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4696 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4697 l2_data := data)) -> value dl {
4698 log("Rx PTCCH/D data block on L1CTL: ", dl);
4699 setverdict(pass);
4700 T.stop;
4701 }
4702 [] L1CTL.receive { repeat; }
4703 [] T.timeout {
4704 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4705 }
4706 }
4707}
4708
Harald Welte883340c2018-02-28 18:59:29 +01004709/* Send AGCH from PCU; check it appears on Um side */
4710testcase TC_pcu_data_req_agch() runs on test_CT {
4711 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004712 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004713 f_init_l1ctl();
4714 f_l1_tune(L1CTL);
4715
4716 f_TC_pcu_act_req(0, 0, 7, true);
4717 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4718
4719 T.start;
4720 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004721 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004722 setverdict(pass);
4723 }
4724 [] L1CTL.receive { repeat; }
4725 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004727 }
4728 }
4729}
4730
Harald Welte928622b2019-05-26 13:22:59 +02004731/* Send AGCH from PCU; check it appears on Um side */
4732testcase TC_pcu_data_req_pch() runs on test_CT {
4733 timer T := 3.0;
4734 f_init_pcu_test();
4735 f_init_l1ctl();
4736 f_l1_tune(L1CTL);
4737
4738 f_TC_pcu_act_req(0, 0, 7, true);
4739 /* three characters prefix: last 3 digits of IMSI as ASCII */
4740 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4741
4742 T.start;
4743 alt {
4744 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4745 setverdict(pass);
4746 }
4747 [] L1CTL.receive { repeat; }
4748 [] T.timeout {
4749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4750 }
4751 }
4752}
4753
Harald Welte883340c2018-02-28 18:59:29 +01004754/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4755testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4756 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004757 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004758 f_init_l1ctl();
4759 f_l1_tune(L1CTL);
4760
4761 /* append 3 last imsi digits so BTS can compute pagng group */
4762 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4763
4764 timer T := 0.5;
4765 T.start;
4766 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004767 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004768 /* TODO: verify paging group */
4769 setverdict(pass);
4770 }
4771 [] L1CTL.receive { repeat; }
4772 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004774 }
4775 }
4776}
4777
4778/* Send RACH from Um side, expect it to show up on PCU socket */
4779testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004780 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004781 f_init_l1ctl();
4782 f_l1_tune(L1CTL);
4783
4784 var GsmFrameNumber fn_last := 0;
4785 for (var integer i := 0; i < 1000; i := i+1) {
4786 var OCT1 ra := f_rnd_ra_ps();
4787 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4788 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004790 }
4791 fn_last := fn;
4792
4793 timer T := 2.0;
4794 T.start;
4795 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004796 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, 0, 0, oct2int(ra), 0, ?, fn))) {
Harald Welte883340c2018-02-28 18:59:29 +01004797 T.stop;
4798 }
4799 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004801 }
4802 [] PCU.receive { repeat; }
4803 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004805 }
4806 }
4807 }
4808 setverdict(pass);
4809}
4810
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004811/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4812 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4813testcase TC_pcu_ext_rach_content() runs on test_CT {
4814 var template PCUIF_Message pcu_rach_ind;
4815 var GsmFrameNumber fn_last := 0;
4816 var L1ctlRachSynchSeq synch_seq;
4817 var PCUIF_BurstType pcu_bt;
4818 var GsmFrameNumber fn;
4819 var BIT11 ra11;
4820
4821 f_init_pcu_test();
4822 f_init_l1ctl();
4823 f_l1_tune(L1CTL);
4824
4825 for (var integer i := 0; i < 1000; i := i+1) {
4826 /* We need to test both TS1 & TS2 */
4827 if (i rem 2 == 0) {
4828 synch_seq := RACH_SYNCH_SEQ_TS1;
4829 pcu_bt := BURST_TYPE_1;
4830 } else {
4831 synch_seq := RACH_SYNCH_SEQ_TS2;
4832 pcu_bt := BURST_TYPE_2;
4833 }
4834
4835 ra11 := f_rnd_ra11_ps();
4836 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4837 if (fn == fn_last) {
4838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4839 "Two RACH in same FN?!?");
4840 }
4841 fn_last := fn;
4842
4843 /* Compose the expected message */
4844 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004845 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004846 ra := bit2int(ra11),
4847 is_11bit := 1,
4848 burst_type := pcu_bt,
4849 fn := fn);
4850
4851 timer T := 2.0;
4852 T.start;
4853 alt {
4854 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4855 T.stop;
4856 }
4857 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4859 }
4860 [] PCU.receive { repeat; }
4861 [] T.timeout {
4862 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4863 }
4864 }
4865 }
4866 setverdict(pass);
4867}
4868
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004869private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4870runs on test_CT {
4871 var template PCUIF_send_data sdt;
4872 var PCUIF_send_data sd;
4873 var int16_t lqual_cb;
4874 timer T := 1.0;
4875
4876 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4877 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4878
4879 /* Send a random PDTCH frame over Um */
4880 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4881 '0000'O & f_rnd_octstring(21)));
4882
4883 T.start;
4884 alt {
4885 /* If expected link quality is above the threshold */
4886 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4887 lqual_cb := sd.data.u.data_ind.lqual_cb;
4888 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4889
4890 /* Make sure the actual link quality matches the expected value */
4891 if (not match(lqual_cb, lqual_cb_exp)) {
4892 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4893 "expected value ", lqual_cb_exp));
4894 } else {
4895 setverdict(pass);
4896 }
4897 }
4898 /* If expected link quality is below the threshold */
4899 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4901 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4902 }
4903 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4904 [] PCU.receive { repeat; }
4905 [lqual_cb_exp < thresh] T.timeout {
4906 log("Rx nothing, as expected");
4907 setverdict(pass);
4908 }
4909 [lqual_cb_exp >= thresh] T.timeout {
4910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4911 "Timeout waiting for PCUIF_DATA.ind");
4912 }
4913 }
4914}
4915
4916/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4917testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4918 f_init_pcu_test();
4919 PCU.clear;
4920
4921 f_init_l1ctl();
4922 f_l1_tune(L1CTL);
4923
4924 /* Activate a PDCH channel on TS7 */
4925 f_TC_pcu_act_req(0, 0, 7, true);
4926
4927 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004928 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004929 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4930 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004931 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004932
4933 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4934 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4935 var TrxcMessage ret;
4936
4937 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4938 valueof(ts_TRXC_FAKE_CI(i)));
4939
4940 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4941 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4942 }
4943}
4944
Harald Welte883340c2018-02-28 18:59:29 +01004945/* Send PAGING via RSL, expect it to shw up on PCU socket */
4946testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004947 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004948
4949 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004950 var MobileIdentityLV mi_lv;
4951 var octetstring mi_lv_enc;
4952 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004953 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004954
Harald Welte883340c2018-02-28 18:59:29 +01004955 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004956 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004957 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004958 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004959 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004960
4961 /* Fancy encoding for PCUIF */
4962 mi_lv := valueof(ts_MI_LV(mi));
4963 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4964 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004965
4966 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004967 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004968 T.start;
4969 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004970 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004971 }
4972 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004974 }
4975 [] PCU.receive { repeat; }
4976 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004978 }
4979 }
4980 }
4981 setverdict(pass);
4982}
4983
Harald Welted66c9b82019-05-25 09:03:15 +02004984/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4985testcase TC_pcu_time_ind() runs on test_CT {
4986 var PCUIF_send_data pcu_sd;
4987 var integer num_time_ind := 0;
4988 var integer first_fn, last_fn;
4989 var float test_duration := 5.0;
4990 timer T;
4991
4992 f_init_pcu_test();
4993 f_TC_pcu_act_req(0, 0, 7, true);
4994
4995 PCU.clear;
4996 T.start(test_duration);
4997 alt {
4998 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4999 num_time_ind := num_time_ind + 1;
5000 if (not isbound(first_fn)) {
5001 first_fn := pcu_sd.data.u.time_ind.fn;
5002 }
5003 last_fn := pcu_sd.data.u.time_ind.fn;
5004 repeat;
5005 }
5006 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5007 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5008 repeat;
5009 }
5010 [] PCU.receive {
5011 repeat;
5012 }
5013 [] T.timeout {}
5014 }
5015 var integer fn_expired := last_fn - first_fn;
5016 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5017
5018 /* verify the number of frames expired matches our expectation */
5019 const float c_GSM_FN_DURATION_MS := 4.61538;
5020 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005021 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005022 if (not match(fn_expired, t_fn_expected)) {
5023 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5024 }
5025
5026 /* There are three TIME.ind in every fn MOD 13 */
5027 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5028 /* Add some tolerance */
5029 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5030 if (not match(num_time_ind, t_time_ind_exp)) {
5031 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5032 }
5033
5034 setverdict(pass);
5035}
5036
Harald Welte4832c862019-05-25 14:57:18 +02005037/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5038testcase TC_pcu_rts_req() runs on test_CT {
5039 var PCUIF_send_data pcu_sd;
5040 var integer first_fn, last_fn;
5041 var integer num_rts_pdtch := 0;
5042 var integer num_rts_ptcch := 0;
5043 var float test_duration := 5.0;
5044 timer T;
5045
5046 f_init_pcu_test();
5047 f_TC_pcu_act_req(0, 0, 7, true);
5048
5049 PCU.clear;
5050 T.start(test_duration);
5051 alt {
5052 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5053 -> value pcu_sd {
5054 num_rts_pdtch := num_rts_pdtch + 1;
5055 if (not isbound(first_fn)) {
5056 first_fn := pcu_sd.data.u.rts_req.fn;
5057 }
5058 last_fn := pcu_sd.data.u.rts_req.fn;
5059 repeat;
5060 }
5061 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5062 -> value pcu_sd {
5063 num_rts_ptcch := num_rts_ptcch + 1;
5064 if (not isbound(first_fn)) {
5065 first_fn := pcu_sd.data.u.rts_req.fn;
5066 }
5067 last_fn := pcu_sd.data.u.rts_req.fn;
5068 repeat;
5069 }
5070 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5071 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5072 repeat;
5073 }
5074 [] PCU.receive {
5075 repeat;
5076 }
5077 [] T.timeout {}
5078 }
5079 var integer fn_expired := last_fn - first_fn;
5080 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5081 ", num_rts_ptcch=", num_rts_ptcch);
5082
5083 /* verify the number of frames expired matches our expectation */
5084 const float c_GSM_FN_DURATION_MS := 4.61538;
5085 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005086 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005087 if (not match(fn_expired, t_fn_expected)) {
5088 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5089 }
5090
5091 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5092 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5093 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5094 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5095 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5096 t_ptcch_exp);
5097 }
5098
5099 /* We have 12 PDTCH blocks every 52-multiframe */
5100 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5101 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5102 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5103 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5104 t_pdtch_exp);
5105 }
5106
5107 setverdict(pass);
5108}
5109
Harald Welte07bd2d22019-05-25 11:03:30 +02005110/* test for generating Abis side OML ALERT from the PCU */
5111testcase TC_pcu_oml_alert() runs on test_CT {
5112 var PCUIF_send_data pcu_sd;
5113 var integer num_time_ind := 0;
5114 var integer first_fn, last_fn;
5115 var float test_duration := 5.0;
5116 timer T;
5117
5118 f_init_pcu_test();
5119 f_TC_pcu_act_req(0, 0, 7, true);
5120
5121 /* re-connect CTRL port from BTS to BSC */
5122 f_ipa_ctrl_stop();
5123 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5124
5125 /* Send that OML Alert */
5126 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5127
5128 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5129 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5130 setverdict(pass);
5131}
5132
Harald Welteeaa9a862019-05-26 23:01:08 +02005133/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5134private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5135 var PCUIF_Message first_info;
5136 var integer pcu_conn_id := -1;
5137 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5138 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5139 var OCT4 tlli := '01020304'O;
5140 var OCT1 cause := '23'O;
5141 timer T := 5.0;
5142
5143 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5144
5145 f_l1_tune(L1CTL);
5146 RSL.clear;
5147
5148 f_est_dchan();
5149 L1CTL.clear;
5150
5151 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5152
5153 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5154 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5155 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5156
5157 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5158 T.start;
5159 alt {
5160 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5161 setverdict(pass);
5162 }
5163 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5164 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5165 }
5166 [] PCU.receive {
5167 repeat;
5168 }
5169 [] T.timeout {
5170 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5171 }
5172 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005173
5174 /* release the channel */
5175 f_rsl_chan_deact();
5176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5177 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005178}
5179testcase TC_pcu_rr_suspend() runs on test_CT {
5180 var ConnHdlrPars pars;
5181 var ConnHdlr vc_conn;
5182
5183 f_init();
5184
5185 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5186 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5187 vc_conn.done;
5188}
Harald Welte07bd2d22019-05-25 11:03:30 +02005189
Harald Weltea2e0e942019-05-27 18:12:53 +02005190/* Ensure that PCUIF socket can accept only a single connection */
5191testcase TC_pcu_socket_connect_multi() runs on test_CT {
5192 timer T := 5.0;
5193
5194 /* this (among other things) establishes the first connection to the PCUIF socket */
5195 f_init();
5196
5197 /* try to establish a second connection, expect it to fail */
5198 PCU.send(UD_connect:{mp_pcu_socket, -1});
5199 T.start;
5200 alt {
5201 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5202 setverdict(pass);
5203 }
5204 [] PCU.receive(UD_connect_result:?) {
5205 setverdict(fail, "Unexpected unix domain connect result");
5206 }
5207 [] T.timeout {
5208 setverdict(pass);
5209 }
5210 }
5211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5212}
5213
Harald Weltec8effb72019-05-27 18:23:04 +02005214/* Ensure that PCUIF socket can disconnect + reconnect */
5215testcase TC_pcu_socket_reconnect() runs on test_CT {
5216 /* this (among other things) establishes the first connection to the PCUIF socket */
5217 f_init();
5218
5219 f_sleep(1.0);
5220
5221 f_pcuif_close(PCU, g_pcu_conn_id);
5222 g_pcu_conn_id := -1;
5223
5224 f_sleep(1.0);
5225
5226 /* re-connect */
5227 PCU.clear;
5228 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5229 setverdict(pass);
5230
5231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5232}
5233
Harald Weltebe030482019-05-27 22:29:35 +02005234/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005235private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5236runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005237 var L1ctlDlMessage l1_dl;
5238 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005239 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005240 timer T := 5.0;
5241 T.start;
5242 alt {
5243 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005244 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5245 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005246 repeat;
5247 }
5248 }
5249 [] pt.receive {
5250 repeat;
5251 }
5252 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5254 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005255 }
5256 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005257 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005258}
5259
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005260/* Check if GPRS Indicator is present in RR System Information of a given type */
5261private function f_si_has_gprs_indicator(RrMessageType si_type)
5262runs on test_CT return boolean {
5263 var SystemInformation si := f_get_si(L1CTL, si_type);
5264
5265 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005266 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005267 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005268 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005269 }
5270
5271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5272 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005273}
5274
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005275/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5276private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5277runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005278 /* don't call f_init() as this would connect PCU socket */
5279 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005280
5281 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005282 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005283 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005284
5285 f_init_l1ctl();
5286 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005287 f_sleep(2.0);
5288 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005289
5290 if (f_si_has_gprs_indicator(si_type)) {
5291 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005292 } else {
5293 setverdict(pass);
5294 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005295
Harald Weltebe030482019-05-27 22:29:35 +02005296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5297}
5298
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005299testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5300 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5301}
Harald Weltebe030482019-05-27 22:29:35 +02005302
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005303testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5304 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5305}
5306
5307/* Ensure that GPRS capability is advertised after PCU socket connect */
5308private function f_TC_pcu_socket_connect(RrMessageType si_type)
5309runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005310 /* this (among other things) establishes the first connection to the PCUIF socket */
5311 f_init();
5312 f_init_l1ctl();
5313 f_l1_tune(L1CTL);
5314
5315 f_sleep(2.0);
5316 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005317
5318 if (not f_si_has_gprs_indicator(si_type)) {
5319 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005320 } else {
5321 setverdict(pass);
5322 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005323
Harald Weltebe030482019-05-27 22:29:35 +02005324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5325}
5326
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005327testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5328 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5329}
Harald Weltebe030482019-05-27 22:29:35 +02005330
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005331testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5332 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5333}
5334
5335/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5336private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5337runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005338 /* this (among other things) establishes the first connection to the PCUIF socket */
5339 f_init();
5340 f_init_l1ctl();
5341 f_l1_tune(L1CTL);
5342
5343 f_pcuif_close(PCU, g_pcu_conn_id);
5344 g_pcu_conn_id := -1;
5345
5346 f_sleep(1.0);
5347
5348 /* re-connect */
5349 PCU.clear;
5350 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5351
5352 f_sleep(2.0);
5353 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005354
5355 if (f_si_has_gprs_indicator(si_type)) {
5356 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005357 } else {
5358 setverdict(pass);
5359 }
5360
5361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5362}
5363
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005364testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5365 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5366}
5367
5368testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5369 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5370}
5371
Oliver Smithf5239c72019-08-28 10:01:25 +02005372/* Verify that the cell_id of SI3 (TS 04.08 9.1.35) and other values are passed properly to the PCU socket (OS#3854) */
5373testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5374 var SystemInformation si3 := valueof(ts_SI3_default);
5375
5376 f_init();
5377
5378 /* Verify cell_id */
5379 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5380 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5381 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005382 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5383 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5384 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005385 }
5386
5387 /* Verify LAC */
5388 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5389 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5390 if (lac_si3 != lac_pcu) {
5391 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5392 }
5393
5394 setverdict(pass);
5395}
Harald Welted66c9b82019-05-25 09:03:15 +02005396
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005397/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5398testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5399 var PCUIF_info_ind info_ind;
5400 var ConnHdlrPars pars;
5401
5402 f_init();
5403
5404 info_ind := g_pcu_last_info.u.info_ind;
5405
5406 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5407 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5408 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5409 /* Skip inactive timeslots */
5410 continue;
5411 }
5412
5413 pars := valueof(t_Pars(t_RslChanNr_PDCH(tn), ts_RSL_ChanMode_SIGN));
5414 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
5415 { f_resolve_fh_params(pars); }
5416
5417 var template PCUIF_InfoTrxTs tr_ts;
5418 if (ispresent(pars.maio_hsn)) {
5419 tr_ts := tr_PCUIF_InfoTrxTsH1(
5420 hsn := pars.maio_hsn.hsn,
5421 maio := pars.maio_hsn.maio,
5422 ma := f_pad_bit(pars.ma_map.ma, 64, '0'B));
5423 } else {
5424 tr_ts := tr_PCUIF_InfoTrxTsH0;
5425 }
5426
5427 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5428 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5429 if (not match(ts, tr_ts)) {
5430 setverdict(fail, "Hopping parameters do not match: ",
5431 "received ", ts, " vs expected ", tr_ts);
5432 } else {
5433 setverdict(pass);
5434 }
5435 }
5436 }
5437}
5438
Alexander Couzens5283f552020-07-28 15:39:04 +02005439/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5440testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5441 f_init_vty_bsc();
5442 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5443 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5444
5445 f_init();
5446
5447 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5448 if (not ischosen(remote_addr.v10)) {
5449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5450 log2str("Unexpected remote_addr: ", remote_addr));
5451 }
5452
5453 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5454 setverdict(fail, "Received address family is not IPv4");
5455 }
5456
5457 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5458 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5459 }
5460
5461 setverdict(pass);
5462}
5463
5464/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5465testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5466 f_init_vty_bsc();
5467 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5468
5469 f_init();
5470
5471 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5472 if (not ischosen(remote_addr.v10)) {
5473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5474 log2str("Unexpected remote_addr: ", remote_addr));
5475 }
5476
5477 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5478 setverdict(fail, "Received address family is not IPv6");
5479 }
5480
5481 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5482 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5483 }
5484
5485 setverdict(pass);
5486}
5487
Harald Welte3d04ae62018-04-04 20:29:05 +02005488/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005489 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005490 ***********************************************************************/
5491
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005492private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5493 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005494runs on ConnHdlr {
5495 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005496
5497 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005498 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005499 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5500 repeat;
5501 }
5502 }
5503}
5504
5505private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5506runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005507 /* Expect BTS to immediately acknowledge activation as PDCH */
5508 PCU.clear;
5509 f_rsl_chan_act(g_pars.chan_mode);
5510 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005511 timer T_wait := 2.0;
5512 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005513 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005514 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005515 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005516 [] T_wait.timeout {
5517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5518 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5519 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005520 }
5521 /* try to activate this PDCH from the PCU point of view */
5522 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5523 /* FIXME: is there a response? */
5524}
5525
5526private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5527runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005528 /* Send RSL CHAN REL (deactivate) */
5529 PCU.clear;
5530 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5531 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005532 timer T_wait := 2.0;
5533 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005534 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005535 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005536 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005537 [] T_wait.timeout {
5538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5539 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5540 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005541 }
5542 /* Emulate PCU asking BTS to deactivate PDCH */
5543 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5544 alt {
5545 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5546 setverdict(pass);
5547 }
5548 [] RSL.receive { repeat; }
5549 }
5550}
5551
5552/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005553private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005554 var PCUIF_Message first_info;
5555 var integer ts_nr := g_chan_nr.tn;
5556 var integer trx_nr := 0;
5557 var integer bts_nr := 0;
5558 var integer pcu_conn_id := -1;
5559
5560 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5561
5562 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5563 f_sleep(3.0);
5564 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5565 setverdict(pass);
5566}
5567testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5568 var ConnHdlrPars pars;
5569 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005570 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005571
5572 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5573 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5574 vc_conn.done;
5575}
5576
5577/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005578private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005579 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005580 var integer pcu_conn_id := -1;
5581
5582 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5583
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005584 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5585 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5586 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005587 setverdict(pass);
5588}
5589testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5590 var ConnHdlrPars pars;
5591 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005592 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005593
5594 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5595 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5596 vc_conn.done;
5597}
5598
5599/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005600private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005601 var PCUIF_Message first_info;
5602 var integer ts_nr := g_chan_nr.tn;
5603 var integer trx_nr := 0;
5604 var integer bts_nr := 0;
5605 var integer pcu_conn_id := -1;
5606
5607 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5608
5609 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005610 /* Send a second Chan Activ and expect it to be NACKed */
5611 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5612 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005613 setverdict(pass);
5614}
5615testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5616 var ConnHdlrPars pars;
5617 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005618 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005619
5620 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5621 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5622 vc_conn.done;
5623}
5624
5625/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005626private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005627 var PCUIF_Message first_info;
5628 var integer ts_nr := g_chan_nr.tn;
5629 var integer trx_nr := 0;
5630 var integer bts_nr := 0;
5631 var integer pcu_conn_id := -1;
5632 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5633
5634 /* register for the TCH/F channel number */
5635 f_rslem_register(0, chan_nr);
5636
5637 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5638
5639 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5640 "RSL CHAN ACT");
5641 setverdict(pass);
5642}
5643testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5644 var ConnHdlrPars pars;
5645 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005646 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005647
5648 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5649 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5650 vc_conn.done;
5651}
5652
5653/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005654private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005655 var PCUIF_Message first_info;
5656 var integer ts_nr := g_chan_nr.tn;
5657 var integer trx_nr := 0;
5658 var integer bts_nr := 0;
5659 var integer pcu_conn_id := -1;
5660 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5661 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5662
5663 /* register for the TCH/H channel numbers */
5664 f_rslem_register(0, chan_nr[0]);
5665 f_rslem_register(0, chan_nr[1]);
5666
5667 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5668
5669 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5670 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5671 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5672 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5673 setverdict(pass);
5674}
5675testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5676 var ConnHdlrPars pars;
5677 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005678 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005679
5680 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5681 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5682 vc_conn.done;
5683}
5684
Harald Welte9bbbfb52018-04-05 09:33:19 +02005685/***********************************************************************
5686 * IPA Style Dynamic Timeslot Support
5687 ***********************************************************************/
5688
5689private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5690runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005691 /* Expect BTS to immediately acknowledge activation as PDCH */
5692 PCU.clear;
5693 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5694 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005695 timer T_wait := 2.0;
5696 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005697 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005698 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005699 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005700 [] T_wait.timeout {
5701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5702 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5703 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005704 }
5705 /* try to activate this PDCH from the PCU point of view */
5706 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5707 /* FIXME: is there a response? */
5708
5709 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5710}
5711
5712private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5713runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005714 /* Send RSL CHAN REL (deactivate) */
5715 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5716 PCU.clear;
5717 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005718 timer T_wait := 2.0;
5719 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005720 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005721 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005722 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005723 [] T_wait.timeout {
5724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5725 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5726 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005727 }
5728 /* Emulate PCU asking BTS to deactivate PDCH */
5729 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5730 alt {
5731 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5732 setverdict(pass);
5733 }
5734 [] RSL.receive { repeat; }
5735 }
5736}
5737
5738/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005739private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005740 var PCUIF_Message first_info;
5741 var integer ts_nr := g_chan_nr.tn;
5742 var integer trx_nr := 0;
5743 var integer bts_nr := 0;
5744 var integer pcu_conn_id := -1;
5745
5746 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5747
5748 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5749 f_sleep(3.0);
5750 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5751
5752 setverdict(pass);
5753
5754}
5755testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5756 var ConnHdlrPars pars;
5757 var ConnHdlr vc_conn;
5758 f_init();
5759
5760 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5761 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5762 vc_conn.done;
5763}
5764
5765/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005766private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005767 var PCUIF_Message first_info;
5768 var integer ts_nr := g_chan_nr.tn;
5769 var integer trx_nr := 0;
5770 var integer bts_nr := 0;
5771 var integer pcu_conn_id := -1;
5772
5773 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5774
5775 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5776 "RSL CHAN ACT");
5777 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5778 "RF CHAN REL", true);
5779 setverdict(pass);
5780}
5781testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5782 var ConnHdlrPars pars;
5783 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005784 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005785
5786 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5787 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5788 vc_conn.done;
5789}
5790
5791/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005792private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005793 var PCUIF_Message first_info;
5794 var integer ts_nr := g_chan_nr.tn;
5795 var integer trx_nr := 0;
5796 var integer bts_nr := 0;
5797 var integer pcu_conn_id := -1;
5798
5799 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5800
5801 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5802 "RSL CHAN ACT");
5803
5804 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5805 alt {
5806 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5807 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005809 }
5810 [] RSL.receive { repeat; }
5811 }
5812
5813 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5814 "RF CHAN REL", true);
5815 setverdict(pass);
5816}
5817testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5818 var ConnHdlrPars pars;
5819 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005820 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005821
5822 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5823 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5824 vc_conn.done;
5825}
5826
5827/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005828private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005829 var PCUIF_Message first_info;
5830 var integer ts_nr := g_chan_nr.tn;
5831 var integer trx_nr := 0;
5832 var integer bts_nr := 0;
5833 var integer pcu_conn_id := -1;
5834
5835 /* register for the TCH/F channel number */
5836 f_rslem_register(0, g_chan_nr);
5837
5838 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5839
5840 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5841
5842 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5843 "RSL CHAN ACT");
5844
5845 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5846
5847 setverdict(pass);
5848}
5849testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5850 var ConnHdlrPars pars;
5851 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005852 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005853
5854 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5855 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5856 vc_conn.done;
5857}
5858
5859
Harald Welte0472ab42018-03-12 15:02:26 +01005860/***********************************************************************
5861 * LAPDm / RLL related
5862 ***********************************************************************/
5863
5864private function f_tx_lapdm(template (value) LapdmFrame l,
5865 template (value) RslLinkId link_id) runs on ConnHdlr {
5866 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005867 var template (value) SacchL1Header l1h;
5868
5869 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005870 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005871 /* Compose dummy L1 header */
5872 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5873 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 +02005874 } else {
5875 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005876 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 +01005877 }
Harald Welte0472ab42018-03-12 15:02:26 +01005878}
5879
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005880private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005881 uint3_t sapi,
5882 RslLinkId link_id,
5883 octetstring l3,
5884 boolean exp
5885}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005886private type record of RllTestCase RllTestCases;
5887private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5888 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005889 sapi := sapi,
5890 link_id := id,
5891 l3 := l3,
5892 exp := exp
5893}
5894
5895/* execute the same callback function with a set of different parameters (tcs) on a
5896 * variety of logical channels */
5897private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5898 var ConnHdlrPars pars;
5899 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005900 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005901
5902 /* test on each of the channels we have */
5903 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5904 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5905
5906 /* test each of the test cases on the current channel */
5907 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5908 pars.spec.rll := tcs[j];
5909 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5910 vc_conn := f_start_handler(fn, pars);
5911 vc_conn.done;
5912 }
5913 }
5914
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005916}
5917
5918/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5919private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5920 var RllTestCase tc := g_pars.spec.rll;
5921 timer T := 3.0;
5922
5923 f_l1_tune(L1CTL);
5924 RSL.clear;
5925
5926 /* activate the logical channel */
5927 f_est_dchan();
5928 L1CTL.clear;
5929
5930 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5931 T.start;
5932 alt {
5933 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5934 if (tc.exp) {
5935 setverdict(pass);
5936 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005938 }
5939 }
5940 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5941 if (tc.exp) {
5942 setverdict(pass);
5943 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005945 }
5946 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005947 /* We also expect to receive the measurements */
5948 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005949 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005951 }
5952 [not tc.exp] T.timeout {
5953 setverdict(pass);
5954 }
5955 }
5956
5957 f_rsl_chan_deact();
5958 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5959 f_rslem_unregister(0, g_chan_nr);
5960}
5961testcase TC_rll_est_ind() runs on test_CT {
5962 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005963 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005964 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005965 /* normal SAPI0 establishment */
5966 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005967 /* SAPI 3 doesn't support contention resolution */
5968 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5969 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5970 /* normal SAPI3 establishment on main DCCH */
5971 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5972 /* normal SAPI3 establishment on SACCH */
5973 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5974 };
5975 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5976}
5977
5978/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5979private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5980 var RllTestCase tc := g_pars.spec.rll;
5981 var L1ctlDlMessage dl;
5982 timer T := 3.0;
5983
5984 f_l1_tune(L1CTL);
5985 RSL.clear;
5986
5987 /* activate the logical channel */
5988 f_est_dchan();
5989 L1CTL.clear;
5990
5991 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5992 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5993 T.start;
5994 alt {
5995 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5996 var LapdmFrame lapdm;
5997 var octetstring l2 := dl.payload.data_ind.payload;
5998 if (dl.dl_info.link_id.c == SACCH) {
5999 /* remove L1 header */
6000 l2 := substr(l2, 2, lengthof(l2)-2);
6001 }
6002 lapdm.ab := dec_LapdmFrameAB(l2);
6003 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6004 setverdict(pass);
6005 } else {
6006 repeat;
6007 }
6008 }
6009 [] L1CTL.receive { repeat; }
6010 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006012 }
6013 }
6014
6015 f_rsl_chan_deact();
6016 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6017 f_rslem_unregister(0, g_chan_nr);
6018}
6019testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6020 var RllTestCases tcs := {
6021 /* normal SAPI3 establishment on main DCCH */
6022 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6023 };
6024 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6025}
6026testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6027 var RllTestCases tcs := {
6028 /* normal SAPI3 establishment on SACCH */
6029 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6030 }
6031 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6032}
6033
6034/* altstep to receive a LAPDm frame matching the given template */
6035private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6036 var L1ctlDlMessage dl;
6037 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6038 var LapdmFrame lapdm;
6039 var octetstring l2 := dl.payload.data_ind.payload;
6040 if (dl.dl_info.link_id.c == SACCH) {
6041 /* remove L1 header */
6042 l2 := substr(l2, 2, lengthof(l2)-2);
6043 }
6044 if (ischosen(exp.ab)) {
6045 lapdm.ab := dec_LapdmFrameAB(l2);
6046 } else if (ischosen(exp.b4)) {
6047 lapdm.b4 := dec_LapdmFrameB4(l2);
6048 } else if (ischosen(exp.bbis)) {
6049 lapdm.bbis := dec_LapdmFrameBbis(l2);
6050 }
6051 log("Rx LAPDm ", lapdm);
6052 if (match(lapdm, exp)) {
6053 setverdict(pass);
6054 } else {
6055 repeat;
6056 }
6057 }
6058 [] L1CTL.receive { repeat; }
6059}
6060private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6061 timer T := t;
6062 T.start;
6063 alt {
6064 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006066 }
6067 [] as_l1_exp_lapdm(exp);
6068 }
6069}
6070
6071/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6072private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6073 /* send SABM from MS -> BTS */
6074 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6075 /* expect RLL EST IND on Abis */
6076 alt {
6077 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6078 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6079 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006081 }
6082 [] RSL.receive { repeat; }
6083 }
6084 /* expect UA from BTS -> MS */
6085 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6086}
6087
6088/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6089private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6090 var RllTestCase tc := g_pars.spec.rll;
6091
6092 f_l1_tune(L1CTL);
6093 RSL.clear;
6094
6095 /* activate the logical channel */
6096 f_est_dchan();
6097 L1CTL.clear;
6098
6099 /* first establish the link-layer */
6100 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6101
6102 /* then send the DISC */
6103 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6104 /* ... and expect the REL IND on the RSL side */
6105 alt {
6106 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6107 setverdict(pass);
6108 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006109 /* We also expect to receive the measurements */
6110 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006111 }
6112
6113 /* release the channel */
6114 f_rsl_chan_deact();
6115 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6116 f_rslem_unregister(0, g_chan_nr);
6117}
6118testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6119 var RllTestCases tcs := {
6120 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6121 };
6122 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6123}
6124
6125testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6126 var RllTestCases tcs := {
6127 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6128 };
6129 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6130}
6131testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6132 var RllTestCases tcs := {
6133 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6134 };
6135 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6136}
6137testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6138 var RllTestCases tcs := {
6139 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6140 };
6141 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6142}
6143
6144/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6145private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6146 var RllTestCase tc := g_pars.spec.rll;
6147 f_l1_tune(L1CTL);
6148 RSL.clear;
6149
6150 /* activate the logical channel */
6151 f_est_dchan();
6152 L1CTL.clear;
6153
6154 /* first establish the link-layer */
6155 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6156
6157 /* then send the REL REQ via RSL */
6158 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6159 /* ... and expect the DISC on the Um side */
6160 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006161 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006162 /* FIXME: send a UA in resposne to the DISC */
6163 }
6164 }
6165
6166 /* release the channel */
6167 f_rsl_chan_deact();
6168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6169 f_rslem_unregister(0, g_chan_nr);
6170}
6171testcase TC_rll_rel_req() runs on test_CT {
6172 var RllTestCases tcs := {
6173 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6174 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6175 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6176 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6177 };
6178 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6179}
6180
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006181/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006182testcase TC_rll_data_req() runs on test_CT {
6183}
6184
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006185/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006186testcase TC_rll_data_ind() runs on test_CT {
6187}
6188
6189/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6190private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6191 var RllTestCase tc := g_pars.spec.rll;
6192
6193 f_l1_tune(L1CTL);
6194 RSL.clear;
6195
6196 f_est_dchan();
6197 L1CTL.clear;
6198
6199 /* Send UNITDATA REQ on RSL side */
6200 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6201 /* Expect it to arrive on the other side */
6202 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006203 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006204 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006205 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006206 }
6207
6208 /* release the channel */
6209 f_rsl_chan_deact();
6210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6211 f_rslem_unregister(0, g_chan_nr);
6212}
6213testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6214 var octetstring l3 := f_rnd_octstring(15);
6215 var RllTestCases tcs := {
6216 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6217 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6218 };
6219 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6220}
6221testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6222 var octetstring l3 := f_rnd_octstring(19);
6223 var RllTestCases tcs := {
6224 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6225 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6226 };
6227 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6228}
6229
6230/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6231private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6232 var RllTestCase tc := g_pars.spec.rll;
6233
6234 f_l1_tune(L1CTL);
6235 RSL.clear;
6236
6237 f_est_dchan();
6238 L1CTL.clear;
6239
6240 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006241 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006242 /* Expdct RLL UNITDATA IND on RSL side */
6243 alt {
6244 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6245 setverdict(pass);
6246 }
6247 [] RSL.receive { repeat; }
6248 }
6249
6250 /* release the channel */
6251 f_rsl_chan_deact();
6252 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6253 f_rslem_unregister(0, g_chan_nr);
6254}
6255testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006256 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006257 var RllTestCases tcs := {
6258 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6259 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6260 };
6261 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6262}
6263testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6264 var octetstring l3 := f_rnd_octstring(18);
6265 var RllTestCases tcs := {
6266 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6267 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6268 };
6269 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6270}
6271
Harald Weltee613f962018-04-18 22:38:16 +02006272/***********************************************************************
6273 * Encryption Related
6274 ***********************************************************************/
6275
6276/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006277private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006278 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6279 if (link_id.c == SACCH) {
6280 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6281 } else {
6282 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6283 }
6284}
6285
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006286/* Expect (or not expect) other kinds of messages */
6287private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6288 [exp_any] RSL.receive { repeat; }
6289 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006291 }
6292}
6293
Harald Weltee613f962018-04-18 22:38:16 +02006294/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006295private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006296 RslLinkId link_id,
6297 octetstring l3,
6298 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006299 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006300) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006301 timer T := 3.0;
6302 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6303 T.start;
6304 /* Expect RLL UNITDATA IND on RSL side */
6305 alt {
6306 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6307 setverdict(pass);
6308 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006309 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006310 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006311 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006313 }
Harald Weltee613f962018-04-18 22:38:16 +02006314 }
6315}
6316
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006317/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6318private function f_data_mo(
6319 RslLinkId link_id,
6320 boolean p, uint3_t nr, uint3_t ns,
6321 octetstring l3,
6322 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006323 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006324) runs on ConnHdlr {
6325 timer T := 3.0;
6326 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6327 T.start;
6328 /* Expect RLL DATA IND on RSL side */
6329 alt {
6330 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6331 setverdict(pass);
6332 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006333 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006334 [] as_rsl_any_ind(exp_any);
6335 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006337 }
6338 }
6339}
6340
Harald Weltee613f962018-04-18 22:38:16 +02006341/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006342private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006343 f_l1_tune(L1CTL);
6344 f_est_dchan(true);
6345
6346 /* now we actually need to transmit some data both ways to check if the encryption works */
6347 var L1ctlDlMessage dl;
6348
Stefan Sperling603d98e2018-07-25 16:47:28 +02006349 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006350 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6351
6352 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6353 f_unitdata_mt(link_id, l3);
6354
6355 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6356 f_unitdata_mo(link_id, l3);
6357
6358 /* release the channel */
6359 f_rsl_chan_deact();
6360 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6361 f_rslem_unregister(0, g_chan_nr);
6362}
6363testcase TC_chan_act_a51() runs on test_CT {
6364 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6365 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6366 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6367}
6368testcase TC_chan_act_a52() runs on test_CT {
6369 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6370 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6371 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6372}
6373testcase TC_chan_act_a53() runs on test_CT {
6374 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6375 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6376 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6377}
6378
Eric Wildf1827a72019-05-28 17:37:35 +02006379/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6380 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006381private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006382 f_l1_tune(L1CTL);
6383 f_est_dchan(true);
6384
6385 /* now we actually need to transmit some data both ways to check if the encryption works */
6386 var L1ctlDlMessage dl;
6387
6388 var octetstring l3 := f_rnd_octstring(20);
6389 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6390
6391 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6392 f_unitdata_mt(link_id, l3);
6393
6394 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6395 f_unitdata_mo(link_id, l3);
6396
6397 var RSL_Message rsl;
6398 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6399
6400 /* modify key to break proper encryption */
6401 g_pars.encr.key := f_rnd_octstring(8);
6402 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6403 rsl.ies := rsl.ies & { ei };
6404 RSL.send(rsl);
6405
6406 timer T0 := 1.0;
6407 T0.start;
6408 /* Expect RSL MODIFY ACK */
6409 alt {
6410 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6411 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6413 }
6414 [] T0.timeout {
6415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6416 }
6417 }
6418
6419 var octetstring l3msg := f_rnd_octstring(15);
6420 timer T1 := 3.0;
6421 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6422 due to broken encryption */
6423 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6424 T1.start;
6425 alt {
6426 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6428 }
6429 [] T1.timeout {
6430 setverdict(pass);
6431 }
6432 }
6433
6434 /* release the channel */
6435 f_rsl_chan_deact();
6436 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6437 f_rslem_unregister(0, g_chan_nr);
6438}
6439testcase TC_rsl_modify_encr() runs on test_CT {
6440 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6441 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6442 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6443}
Harald Weltee613f962018-04-18 22:38:16 +02006444
6445/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006446private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006447 /* L3 payload doesn't matter, as it is passed transparently */
6448 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6449 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6450 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6451
6452 f_l1_tune(L1CTL);
6453
6454 /* first establish a dedicated channel in the clear */
6455 f_est_dchan(false);
6456
6457 /* Establish ABM */
6458 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6459
6460 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6461 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6462 /* expect the L3 to arrive still unencrypted on the MS side */
6463 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6464
6465 /* configure L1 to apply ciphering */
6466 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6467 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6468
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006469 /* send first ciphered I-frame in response and expect it on RSL */
6470 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006471
6472 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6473 * and hence enable encryption also on the downlink */
6474
6475 /* expect bi-directional communication work in encrypted mode */
6476 f_unitdata_mo(link_id, f_rnd_octstring(15));
6477 f_unitdata_mt(link_id, f_rnd_octstring(15));
6478
6479 /* release the channel */
6480 f_rsl_chan_deact();
6481 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6482 f_rslem_unregister(0, g_chan_nr);
6483}
6484testcase TC_encr_cmd_a51() runs on test_CT {
6485 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6486 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6487 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6488}
6489testcase TC_encr_cmd_a52() runs on test_CT {
6490 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6491 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6492 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6493}
6494testcase TC_encr_cmd_a53() runs on test_CT {
6495 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6496 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6497 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6498}
6499
6500private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6501 var LapdmFrame lf;
6502 var octetstring reenc;
6503
6504 /* decode the LAPDm frame */
6505 if (ischosen(exp_match.ab)) {
6506 lf.ab := dec_LapdmFrameAB(enc);
6507 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006509 }
6510
6511 /* check if decoder result matches expectation */
6512 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006514 } else {
6515 log(name, ": matched");
6516 setverdict(pass);
6517 }
6518
6519 /* test if re-encoded frame equals original input */
6520 reenc := enc_LapdmFrame(lf);
6521 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006523 } else {
6524 setverdict(pass);
6525 }
6526}
6527
6528testcase TC_lapdm_selftest() runs on test_CT {
6529 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6530 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6531 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6532 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6533 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6534 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6535 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6536}
6537
Stefan Sperling4880be42018-08-07 18:12:59 +02006538/***********************************************************************
6539 * DTX Related (see GSM 05.08, section 8.3)
6540 ***********************************************************************/
6541
6542/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006543private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006544 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6545 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6546 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6547 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6548}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006549private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006550 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6551 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6552}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006553private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006554 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6555 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6556 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6557 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6558}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006559private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006560 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6561 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6562 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6563 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6564 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6565 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6566 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6567 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6568}
6569
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006570private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006571 var L1ctlDlMessage dl;
6572 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6573 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6574 var GsmFrameNumber first_fn;
6575 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006576 var integer nfill_frames_sacch := 0;
6577 var integer nfill_frames_nonsacch := 0;
6578 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006579 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6580 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006581 const integer frame_dtx_tchf_mod := 104;
6582 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6583 * which operates in terms of blocks rather than frames. */
6584 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6585 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006586 timer T := 5.0;
6587
6588 f_l1_tune(L1CTL);
6589 RSL.clear;
6590 L1CTL.clear;
6591
6592 /* activate TCHF signalling channel */
6593 f_est_dchan(false);
6594
6595 T.start;
6596 alt {
6597 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6598 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6599 var octetstring l2 := dl.payload.data_ind.payload;
6600
6601 if (is_first_frame) {
6602 is_first_frame := false;
6603 first_fn := dl.dl_info.frame_nr;
6604 }
6605
6606 if (dl.dl_info.link_id.c == SACCH) {
6607 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6608 if (not match(l2_fill_frame_sacch, l2)) {
6609 repeat;
6610 }
6611 } else if (not match(l2_fill_frame, l2)) {
6612 repeat;
6613 }
6614
6615 if (dtxd) {
6616 if (not f_g_chan_is_tchf()) {
6617 T.stop;
6618 f_rsl_chan_deact();
6619 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006620 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 +02006621 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006622 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006623 T.stop;
6624 f_rsl_chan_deact();
6625 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006626
6627 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6628 * 2 SACCH, 1 TCH/F */
6629 expected_fill_frames := 3;
6630
6631 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6632 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6633 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006635 } else {
6636 setverdict(pass);
6637 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006638 } else {
6639 if (dl.dl_info.link_id.c == SACCH) {
6640 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006641 repeat;
6642 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006643 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6644 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6645 * we should only see the subset of frames numbers which correspond to a block boundary.
6646 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6647 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6648 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6649 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6650 repeat;
6651 }
6652 }
6653 log("Received DTX TCH fill frame with bad frame number: ", fn,
6654 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6655 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6656 f_rsl_chan_deact();
6657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006659 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006660 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006661 if (dl.dl_info.link_id.c == SACCH) {
6662 nfill_frames_sacch := nfill_frames_sacch + 1;
6663 } else {
6664 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6665 }
6666 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006667 T.stop;
6668 if (f_g_chan_is_tchf()) {
6669 /* Without DTX we can expect 25 fill frames for every 104 frames.
6670 * (24 FACCH + 1 SACCH filling) */
6671 expected_fill_frames := 25;
6672 } else if (f_g_chan_is_tchh()) {
6673 /* We can expect 2 fill frames for every 104 frames. */
6674 expected_fill_frames := 2;
6675 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6676 /* We can expect 5 fill frames for every 104 frames. */
6677 expected_fill_frames := 5;
6678 } else {
6679 f_rsl_chan_deact();
6680 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006682 }
6683
6684 f_rsl_chan_deact();
6685 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006686
6687 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006688 setverdict(pass);
6689 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006690 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6691 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006693 }
6694 } else {
6695 repeat;
6696 }
6697 }
6698 }
6699 [] L1CTL.receive { repeat; }
6700 [] T.timeout {
6701 f_rsl_chan_deact();
6702 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006704 }
6705 }
6706}
6707
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006708private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006709 f_test_l2_fill_frames(false);
6710}
6711
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006712private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006713 f_test_l2_fill_frames(true);
6714}
6715
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006716private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006717 var ConnHdlr vc_conn;
6718 var ConnHdlrPars pars;
6719 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006720 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006721 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6722 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6723 if (dtxd) {
6724 if (i >= 4) { /* DTX is only allowed on TCH/F */
6725 break;
6726 }
6727 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6728 } else {
6729 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6730 }
6731 vc_conn.done;
6732 }
6733}
6734
6735/* Verify that L2 fill frames are sent on TCH in signaling mode if
6736 * there is nothing to transmit while DTX is disabled on downlink. */
6737testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6738 f_tch_sign_l2_fill_frame(false);
6739}
6740
6741/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6742 * there is nothing to transmit while DTX is enabled on downlink. */
6743testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6744 f_tch_sign_l2_fill_frame(true);
6745}
Harald Welte0472ab42018-03-12 15:02:26 +01006746
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006747testcase TC_chopped_ipa_ping() runs on test_CT {
6748 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6749}
6750
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006751testcase TC_chopped_ipa_payload() runs on test_CT {
6752 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6753}
6754
Harald Welte0472ab42018-03-12 15:02:26 +01006755/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6756/* protocol error as per 44.006 */
6757/* link layer failure (repetition of I-frame N200 times without ACK */
6758/* repetition of SABM or DISC N200 times without ACK */
6759/* receptiom of SABM in multi-frame established state */
6760
6761
Harald Welte68e495b2018-02-25 00:05:57 +01006762/* TODO Areas:
6763
6764* channel activation
6765** with BS_Power / MS_Power, bypassing power control loop
6766** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006767** with timing advance from initial activation on
6768* mode modify
6769** encryption
6770** multirate
6771* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006772** unsupported algorithm
6773* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006774* BS Power Control
6775* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006776* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006777* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006778** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006779* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006780** DATA_IND from BTS->PCU
6781** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006782
6783*/
Harald Welte70767382018-02-21 12:16:40 +01006784
6785control {
6786 execute( TC_chan_act_stress() );
6787 execute( TC_chan_act_react() );
6788 execute( TC_chan_deact_not_active() );
6789 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006790 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006791 execute( TC_sacch_filling() );
6792 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006793 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006794 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006795 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006796 execute( TC_sacch_chan_act_ho_async() );
6797 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006798 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006799 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006800 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006801 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006802 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006803 execute( TC_rach_load_idle_thresh0() );
6804 execute( TC_rach_load_idle_below_thresh() );
6805 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006806 execute( TC_meas_res_sign_tchf() );
6807 execute( TC_meas_res_sign_tchh() );
6808 execute( TC_meas_res_sign_sdcch4() );
6809 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006810 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006811 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006812 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006813 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006814 execute( TC_rsl_bs_pwr_static_ass() );
6815 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006816 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006817 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006818 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006819 execute( TC_rsl_ms_pwr_dyn_up() );
6820 execute( TC_rsl_ms_pwr_dyn_down() );
6821 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6822 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006823 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006824 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006825 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006826 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006827 execute( TC_paging_imsi_80percent() );
6828 execute( TC_paging_tmsi_80percent() );
6829 execute( TC_paging_imsi_200percent() );
6830 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006831 execute( TC_rsl_protocol_error() );
6832 execute( TC_rsl_mand_ie_error() );
6833 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006834 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006835 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006836 execute( TC_si_sched_2bis() );
6837 execute( TC_si_sched_2ter() );
6838 execute( TC_si_sched_2ter_2bis() );
6839 execute( TC_si_sched_2quater() );
6840 execute( TC_si_sched_13() );
6841 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006842 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006843 execute( TC_ipa_crcx_twice_not_active() );
6844 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006845 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006846 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006847
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006848 if (mp_pcu_socket != "") {
6849 execute( TC_pcu_act_req() );
6850 execute( TC_pcu_act_req_wrong_ts() );
6851 execute( TC_pcu_act_req_wrong_bts() );
6852 execute( TC_pcu_act_req_wrong_trx() );
6853 execute( TC_pcu_deact_req() );
6854 execute( TC_pcu_deact_req_wrong_ts() );
6855 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006856 if (mp_l1_supports_gprs) {
6857 execute( TC_pcu_data_req_pdtch() );
6858 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006859 execute( TC_pcu_data_req_wrong_bts() );
6860 execute( TC_pcu_data_req_wrong_trx() );
6861 execute( TC_pcu_data_req_wrong_ts() );
6862 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006863 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006864 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006865 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006866 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006867 execute( TC_pcu_data_req_imm_ass_pch() );
6868 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006869 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006870 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006871 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006872 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006873 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006874 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006875 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006876 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006877 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006878 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006879 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006880 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006881 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006882 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006883 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006884 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006885 execute( TC_dyn_osmo_pdch_act_deact() );
6886 execute( TC_dyn_osmo_pdch_double_act() );
6887 execute( TC_dyn_ipa_pdch_act_deact() );
6888 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6889
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006890 if (PCUIF_Types.mp_pcuif_version >= 10) {
6891 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006892 execute( TC_pcu_socket_nsvc_ipv4() );
6893 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006894 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006895 } else {
6896 log("PCU socket path not available, skipping PCU tests");
6897 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006898
Harald Welte3d04ae62018-04-04 20:29:05 +02006899 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006900 execute( TC_dyn_osmo_pdch_tchf_act() );
6901 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006902 execute( TC_dyn_ipa_pdch_tchf_act() );
6903 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006904
6905 execute( TC_rll_est_ind() );
6906 execute( TC_rll_est_req_DCCH_3() );
6907 execute( TC_rll_est_req_ACCH_3() );
6908 execute( TC_rll_rel_ind_DCCH_0() );
6909 execute( TC_rll_rel_ind_DCCH_3() );
6910 execute( TC_rll_rel_ind_ACCH_0() );
6911 execute( TC_rll_rel_ind_ACCH_3() );
6912 execute( TC_rll_rel_req() );
6913 execute( TC_rll_unit_data_req_DCCH() );
6914 execute( TC_rll_unit_data_req_ACCH() );
6915 execute( TC_rll_unit_data_ind_DCCH() );
6916 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006917
6918 execute( TC_chan_act_a51() );
6919 execute( TC_chan_act_a52() );
6920 execute( TC_chan_act_a53() );
6921 execute( TC_encr_cmd_a51() );
6922 execute( TC_encr_cmd_a52() );
6923 execute( TC_encr_cmd_a53() );
6924
Harald Welteee25aae2019-05-19 14:32:37 +02006925 execute( TC_err_rep_wrong_mdisc() );
6926 execute( TC_err_rep_wrong_msg_type() );
6927 execute( TC_err_rep_wrong_sequence() );
6928
Harald Weltee613f962018-04-18 22:38:16 +02006929 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006930
6931 execute( TC_tch_sign_l2_fill_frame() );
6932 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006933
6934 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006935 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006936}
6937
6938
6939}