blob: 3100d03397bf9b56808713962c39cdc20d43baf5 [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
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700240friend type record FreqHopPars {
241 /* Whether frequency hopping is in use */
242 boolean enabled,
243 /* Mobile Allocation Index Offset / Hopping Sequence Number */
244 MaioHsn maio_hsn,
245 /* MA bitmap to be indicated in RR Immediate Assignment */
246 MobileAllocationLV ma_map,
247 /* The actual Mobile Allocation (ARFCN list) to be used */
248 L1ctlMA ma
249};
250
Harald Welte70767382018-02-21 12:16:40 +0100251type record ConnHdlrPars {
252 RslChannelNr chan_nr,
253 RSL_IE_ChannelMode chan_mode,
254 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100255 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200256 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200257 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700258 BtsBand bts0_band optional,
259
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700260 /* Frequency hopping parameters */
261 FreqHopPars fhp
262};
Harald Welte0472ab42018-03-12 15:02:26 +0100263
264/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700265private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100266 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100267}
268
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700269private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100270 max_retrans := RACH_MAX_RETRANS_7,
271 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100272 cell_barr_access := false,
273 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100274 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100275};
276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700277private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100278 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200279 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100280 acs := '0'B,
281 neci := true,
282 rxlev_access_min := 0
283}
284
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700285private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100286 mcc_mnc := '262F42'H,
287 lac := 42
288}
289
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700290private template (value) GPRSIndicator ts_GPRSIndicator_def := {
291 ra_colour := 0,
292 si13_pos := '0'B
293}
294
295private template (value) SI3RestOctets ts_SI3RestOctets_def
296modifies ts_SI3RestOctets := {
297 gprs_ind := {
298 presence := CSN1_H,
299 ind := ts_GPRSIndicator_def
300 }
301}
302
303private template (value) SI4RestOctets ts_SI4RestOctets_def
304modifies ts_SI4RestOctets := {
305 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700306 presence := CSN1_H,
307 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700308 }
309}
310
Harald Welte7484fc42018-02-24 14:09:45 +0100311/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700312private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100313 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100314 payload := {
315 si3 := {
316 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100317 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100318 ctrl_chan_desc := {
319 msc_r99 := true,
320 att := true,
321 bs_ag_blks_res := 1,
322 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100323 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100324 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
325 spare := '00'B,
326 bs_pa_mfrms := 0, /* 2 multiframes */
327 t3212 := 1 /* 6 minutes */
328 },
Harald Welte82ccef72018-02-25 16:17:33 +0100329 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100330 dn_ind := false,
331 pwrc := false,
332 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100333 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100334 },
Harald Weltef10153f2018-02-25 16:34:05 +0100335 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100336 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200337 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100338 }
339 }
340}
Harald Welte70767382018-02-21 12:16:40 +0100341
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700342private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100343 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100344 payload := {
345 si2 := {
346 bcch_freq_list := '00000000000000000000000000000000'O,
347 ncc_permitted := '11111111'B,
348 rach_control := ts_RachCtrl_default
349 }
350 }
351}
352
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700353private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100354 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100355 payload := {
356 si4 := {
357 lai := ts_LAI_default,
358 cell_sel_par := ts_CellSelPar_default,
359 rach_control := ts_RachCtrl_default,
360 cbch_chan_desc := omit,
361 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200362 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100363 }
364 }
365}
366
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700367private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100368runs on test_CT {
369 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700370 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100371}
372
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700373private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100374runs on test_CT {
375 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
376 log("Setting ", rsl_si_type, ": ", si_dec);
377 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
378}
379
Harald Welte505cf9b2018-09-15 17:47:23 +0300380friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100381 map(self:BTSVTY, system:BTSVTY);
382 f_vty_set_prompts(BTSVTY);
383 f_vty_transceive(BTSVTY, "enable");
384}
385
Harald Welte505cf9b2018-09-15 17:47:23 +0300386friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200387 map(self:BSCVTY, system:BSCVTY);
388 f_vty_set_prompts(BSCVTY, "OsmoBSC");
389 f_vty_transceive(BSCVTY, "enable");
390}
391
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200392friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
393 map(self:BSCVTY, system:BSCVTY);
394 f_vty_set_prompts(BSCVTY, "OsmoBSC");
395 f_vty_transceive(BSCVTY, "enable");
396}
397
Harald Welte883340c2018-02-28 18:59:29 +0100398/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200399private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
400 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100401 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200402 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
403 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100404 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200405 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100407 }
408}
409
Harald Weltef26de0b2018-04-04 20:28:05 +0200410private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
411 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100412 timer T := 2.0;
413 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100414 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200415 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100416 return;
417 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200418 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100419
420 T.start;
421 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200422 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100423 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100425 }
426 }
427}
428
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700429private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
430 out integer trxc_conn_id) {
431 var Result res;
432
433 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
434 "", -1, -1, { udp := {} }, {});
435 if (not ispresent(res.connId)) {
436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
437 "Could not connect to the control (TRXC) interface " &
438 "of FakeTRX, check your configuration");
439 }
440 trxc_conn_id := res.connId;
441}
442
Harald Welte70767382018-02-21 12:16:40 +0100443/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700444friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200445 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100446 g_AllChannels := {
447 /* TS 1..4: TCH/F */
448 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
449 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
450 /* TS 5: TCH/H */
451 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
452 /* TS 0: SDCCH/4 */
453 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
454 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
455 /* TS 6: SDCCH/8 */
456 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
457 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
458 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
459 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
460 };
461
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200462 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700463 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200464 g_AllChanTypes := {
465 /* TS 1..4: TCH/F */
466 valueof(ts_RslChanNr_Bm(1)),
467 /* TS 5: TCH/H */
468 valueof(ts_RslChanNr_Lm(5,1)),
469 /* TS 0: SDCCH/4 */
470 valueof(ts_RslChanNr_SDCCH4(0,2)),
471 /* TS 6: SDCCH/8 */
472 valueof(ts_RslChanNr_SDCCH8(6,4))
473 };
474 } else {
475 g_AllChanTypes := {
476 /* TS 1..4: TCH/F */
477 valueof(ts_RslChanNr_Bm(1)),
478 /* TS 0: SDCCH/4 */
479 valueof(ts_RslChanNr_SDCCH4(0,2)),
480 /* TS 6: SDCCH/8 */
481 valueof(ts_RslChanNr_SDCCH8(6,4))
482 };
483 }
Harald Welte70767382018-02-21 12:16:40 +0100484 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100485 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100486 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200487 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100488
489 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100490 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
491 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
492 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
493 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100494
Harald Weltef26de0b2018-04-04 20:28:05 +0200495 map(self:PCU, system:PCU);
496 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100497
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700498 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100499 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700500
501 /* Init TRXC interface to FakeTRX */
502 map(self:BTS_TRXC, system:BTS_TRXC);
503 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
504
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700505 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700506 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 +0700507 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700508 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
509 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100510 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200511
512 /* Wait some extra time to make sure the BTS emits a stable carrier.
513 * (this is only relevant when running the tests with a physical BTS.) */
514 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100515}
516
Harald Welte68e495b2018-02-25 00:05:57 +0100517/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700518friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100519 map(self:L1CTL, system:L1CTL);
520 f_connect_reset(L1CTL);
521}
522
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700523private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100524
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700525private type record length(8) of FreqHopGroups FreqHopConfig;
526
527private type record of FreqHopGroup FreqHopGroups;
528private type record FreqHopGroup {
529 uint6_t hsn,
530 FreqHopGroupItems trx_maio
531};
532
533private type record of FreqHopGroupItem FreqHopGroupItems;
534private type record FreqHopGroupItem {
535 uint8_t trx_nr,
536 uint6_t maio
537};
538
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700539friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
540 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700541{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700542 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700543 var integer i, j;
544
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700545 fhp.enabled := false;
546
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700547 for (i := 0; i < lengthof(groups); i := i + 1) {
548 var FreqHopGroup g := groups[i];
549 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
550 var FreqHopGroupItem gi := g.trx_maio[j];
551 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700552 fhp.maio_hsn.maio := gi.maio;
553 fhp.maio_hsn.hsn := g.hsn;
554 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700555 break;
556 }
557 }
558
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700559 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700560 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
562 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
563 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700564
565 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
567 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700568 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
569 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700570 }
571
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700572 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700573 break; /* We're done */
574 }
575 }
576}
577
Harald Welte70767382018-02-21 12:16:40 +0100578/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700579friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
580 boolean pcu_comp := false,
581 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100582runs on test_CT return ConnHdlr {
583 var charstring id := testcasename();
584 var ConnHdlr vc_conn;
585
586 vc_conn := ConnHdlr.create(id);
587 /* connect to RSL Emulation main component */
588 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
589 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700590
591 /* The ConnHdlr component may want to talk to some ports directly,
592 * so we disconnect it from the test_CT and connect it to the component.
593 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200594 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200595 unmap(self:PCU, system:PCU);
596 map(vc_conn:PCU, system:PCU);
597 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700598 if (trxc_comp) {
599 unmap(self:BTS_TRXC, system:BTS_TRXC);
600 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
601 }
Harald Welte70767382018-02-21 12:16:40 +0100602
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700603 /* Obtain frequency hopping parameters for a given timeslot */
604 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700605 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700606 }
607
Harald Welte70767382018-02-21 12:16:40 +0100608 vc_conn.start(f_handler_init(fn, id, pars));
609 return vc_conn;
610}
611
Harald Welte70767382018-02-21 12:16:40 +0100612private altstep as_Tguard() runs on ConnHdlr {
613 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100615 }
616}
617
Harald Welte990a3612019-05-27 14:02:13 +0200618friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
619 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100620}
621
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700622private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100623 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700624 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100625}
626
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700627private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100628 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700629 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100630}
631
632/* first function started in ConnHdlr component */
633private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
634runs on ConnHdlr {
635 g_pars := pars;
636 g_chan_nr := pars.chan_nr;
637
638 map(self:L1CTL, system:L1CTL);
639 f_connect_reset(L1CTL);
640
Harald Welted48c0c72019-06-05 10:01:15 +0200641 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700642 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100643 }
Harald Welte70767382018-02-21 12:16:40 +0100644
645 g_Tguard.start(pars.t_guard);
646 activate(as_Tguard());
647
648 f_rslem_register(0, pars.chan_nr);
649
650 /* call the user-supplied test case function */
651 fn.apply(id);
652}
653
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700654private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
655 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200656runs on ConnHdlr return RSL_Message {
657 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100658 timer T := 3.0;
659 RSL.send(tx);
660 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100661 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200662 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100663 T.stop;
664 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100665 }
Harald Welte1eba3742018-02-25 12:48:14 +0100666 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100668 }
Harald Welte21240e62018-03-11 21:43:35 +0100669 [not ignore_other] as_l1_sacch();
670 [not ignore_other] as_meas_res();
671 [not ignore_other] as_l1_dcch();
672 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100674 }
Harald Welte21240e62018-03-11 21:43:35 +0100675 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100676 }
Harald Welteb1726c92018-03-30 11:56:38 +0200677 return rx;
678}
679
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700680friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
681 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200682runs on ConnHdlr {
683 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100684}
685
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700686friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
687 boolean encr_enable := false,
688 RSL_IE_List more_ies := {},
689 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
690runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200691 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200692 if (encr_enable) {
693 /* append encryption related IEs, if requested */
694 var RSL_IE_EncryptionInfo encr_info;
695 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
696 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
697encr_info})) };
698 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200699 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200700 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100701}
702
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700703friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100704 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 +0100705 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100706}
707
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700708/* Default Mobile Allocation to be used for frequency hopping */
709private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
710 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
711
Harald Welte2f2b2b72019-05-31 22:24:57 +0200712friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100713 template RSL_IE_ChannelMode chan_mode,
714 float t_guard := 20.0) := {
715 chan_nr := valueof(chan_nr),
716 chan_mode := valueof(chan_mode),
717 t_guard := t_guard,
718 l1_pars := {
719 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100720 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100721 meas_ul := {
722 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200723 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100724 rxqual := 0
725 },
726 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200727 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100728 rxqual := 0
729 }
730 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200731 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100732 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200733 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200734 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100735 },
Harald Weltee613f962018-04-18 22:38:16 +0200736 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200737 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700738 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700739 fhp := {
740 enabled := false,
741 maio_hsn := ts_HsnMaio(0, 0),
742 ma_map := c_MA_null,
743 ma := l1ctl_ma_def
744 }
Harald Welte70767382018-02-21 12:16:40 +0100745}
746
Harald Welte93640c62018-02-25 16:59:33 +0100747/***********************************************************************
748 * Channel Activation / Deactivation
749 ***********************************************************************/
750
Harald Welte70767382018-02-21 12:16:40 +0100751/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700752private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100753 for (var integer i := 0; i < 500; i := i+1) {
754 f_rsl_chan_act(g_pars.chan_mode);
755 f_rsl_chan_deact();
756 }
757 setverdict(pass);
758}
759testcase TC_chan_act_stress() runs on test_CT {
760 var ConnHdlr vc_conn;
761 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200762 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100763 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
764 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100766}
767
768/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700769private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100770 f_rsl_chan_act(g_pars.chan_mode);
771 /* attempt to activate the same lchan again -> expect reject */
772 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
773 alt {
774 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100776 }
777 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
778 setverdict(pass);
779 }
780 }
781 f_rsl_chan_deact();
782}
783testcase TC_chan_act_react() runs on test_CT {
784 var ConnHdlr vc_conn;
785 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100786 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100787 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
788 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100790}
791
792/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700793private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100794 timer T := 3.0;
795 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
796 T.start;
797 alt {
798 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
799 setverdict(pass);
800 }
801 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100803 }
804 }
805}
806testcase TC_chan_deact_not_active() runs on test_CT {
807 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100808 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100809 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
810 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100812}
813
814/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700815private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100816 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
817 alt {
818 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100820 }
821 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
822 setverdict(pass);
823 }
824 }
825}
826private type record WrongChanNrCase {
827 RslChannelNr chan_nr,
828 charstring description
829}
830private type record of WrongChanNrCase WrongChanNrCases;
831private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
832 chan_nr := chan_nr,
833 description := desc
834}
835
836testcase TC_chan_act_wrong_nr() runs on test_CT {
837 var ConnHdlr vc_conn;
838 var ConnHdlrPars pars;
839
Harald Welte294b0a22018-03-10 23:26:48 +0100840 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100841
842 var WrongChanNrCases wrong := {
843 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
844 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
845 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
846 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
847 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
848 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
849 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
850 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
851 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
852 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
853 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
854 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
855 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
856 };
857
858 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
859 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
860 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
861 vc_conn.done;
862 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100864}
865
Harald Weltee613f962018-04-18 22:38:16 +0200866/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200867friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200868 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200869 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200870
871 /* test on each of the channels we have */
872 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
873 pars.chan_nr := valueof(g_AllChanTypes[i]);
874
875 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
876 vc_conn := f_start_handler(fn, pars);
877 vc_conn.done;
878 }
879
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200881}
882
Harald Welte93640c62018-02-25 16:59:33 +0100883/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100884 * SACCH handling
885 ***********************************************************************/
886
887private function f_exp_sacch(boolean exp) runs on ConnHdlr {
888 timer T_sacch := 3.0;
889 T_sacch.start;
890 alt {
891 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100893 }
894 [not exp] T_sacch.timeout {
895 setverdict(pass);
896 }
897 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
898 setverdict(pass);
899 }
900 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100902 }
903 [] L1CTL.receive { repeat; }
904 [] RSL.receive { repeat; }
905 }
906}
907
908/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
909private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
910 f_l1_tune(L1CTL);
911 RSL.clear;
912
913 /* activate the logical channel */
914 f_est_dchan();
915 L1CTL.clear;
916
917 /* check that SACCH actually are received as expected */
918 f_exp_sacch(true);
919
920 /* deactivate SACCH on the logical channel */
921 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
922 f_sleep(1.0);
923 L1CTL.clear;
924
925 /* check that no SACCH are received anymore */
926 f_exp_sacch(false);
927
928 /* release the channel */
929 f_rsl_chan_deact();
930 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
931}
932testcase TC_deact_sacch() runs on test_CT {
933 var ConnHdlr vc_conn;
934 var ConnHdlrPars pars;
935 f_init();
936 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
937 //for (var integer i := 0; i < 1; i := i+1) {
938 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
939 log(testcasename(), ": Starting for ", g_AllChannels[i]);
940 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
941 vc_conn.done;
942 }
943 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100945}
946
Harald Welte55700662018-03-12 13:15:43 +0100947/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100948private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
949 var L1ctlDlMessage dl;
950 /* check that the specified SI5 value is actually sent */
951 timer T_sacch := 3.0;
952 L1CTL.clear;
953 T_sacch.start;
954 alt {
955 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
956 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
957 if (match(l3, l3_exp)) {
958 setverdict(pass);
959 } else {
960 repeat;
961 }
962 }
963 [] L1CTL.receive { repeat; }
964 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100966 }
967 }
968}
969
Harald Welte55700662018-03-12 13:15:43 +0100970/* verify that given SACCH payload is not present */
971private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
972 var L1ctlDlMessage dl;
973 /* check that the specified SI5 value is actually sent */
974 timer T_sacch := 3.0;
975 L1CTL.clear;
976 T_sacch.start;
977 alt {
978 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
979 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
980 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100982 } else {
983 repeat;
984 }
985 }
986 [] L1CTL.receive { repeat; }
987 [] T_sacch.timeout {
988 setverdict(pass);
989 }
990 }
991}
992
Harald Welte629cc6b2018-03-11 17:19:05 +0100993/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100994private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
995 /* Set a known default SACCH filling for SI5 */
996 var octetstring si5 := f_rnd_octstring(19);
997 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
998
999 f_l1_tune(L1CTL);
1000 RSL.clear;
1001
1002 /* activate the logical channel */
1003 f_est_dchan();
1004
1005 /* check that the specified SI5 value is actually sent */
1006 f_sacch_present(si5);
1007
1008 /* release the channel */
1009 RSL.clear;
1010 f_rsl_chan_deact();
1011 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1012}
1013testcase TC_sacch_filling() runs on test_CT {
1014 var ConnHdlr vc_conn;
1015 var ConnHdlrPars pars;
1016 f_init();
1017 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1018 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1019 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1020 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1021 vc_conn.done;
1022 }
1023 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001025}
1026
Harald Welte629cc6b2018-03-11 17:19:05 +01001027/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001028private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1029 /* Set a known default SACCH filling for SI5 */
1030 var octetstring si5 := f_rnd_octstring(19);
1031 var octetstring si5_diff := f_rnd_octstring(19);
1032 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1033
1034 f_l1_tune(L1CTL);
1035 RSL.clear;
1036
1037 log("Activating channel, expecting standard SI5");
1038 /* activate the logical channel */
1039 f_est_dchan();
1040 /* check that the specified SI5 value is actually sent */
1041 f_sacch_present(si5);
1042
1043 /* set channel-specific different SI5 */
1044 log("Setting channel specific SACCH INFO, expecting it");
1045 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1046 /* check that the specified lchan-specific value is now used */
1047 f_sacch_present(si5_diff);
1048
1049 /* deactivate the channel and re-activate it, this should result in default SI5 */
1050 log("De-activating and re-activating channel, expecting standard SI5");
1051 f_rsl_chan_deact();
1052 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1053 /* Verify that the TRX-wide default SACCH filling is present again */
1054 f_sacch_present(si5);
1055
1056 /* release the channel */
1057 RSL.clear;
1058 f_rsl_chan_deact();
1059 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1060}
1061testcase TC_sacch_info_mod() runs on test_CT {
1062 var ConnHdlr vc_conn;
1063 var ConnHdlrPars pars;
1064 f_init();
1065 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1066 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1067 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1068 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1069 vc_conn.done;
1070 }
1071 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001073}
1074
Harald Welte075d84c2018-03-12 13:07:24 +01001075/* Test SACCH scheduling of multiple different SI message types */
1076private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1077 var octetstring si5 := f_rnd_octstring(19);
1078 var octetstring si5bis := f_rnd_octstring(19);
1079 var octetstring si5ter := f_rnd_octstring(19);
1080 var octetstring si6 := f_rnd_octstring(19);
1081
1082 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1083 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1084 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1085 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1086
1087 f_l1_tune(L1CTL);
1088 RSL.clear;
1089
1090 /* activate the logical channel */
1091 f_est_dchan();
1092 L1CTL.clear;
1093
1094 /* check that SACCH actually are received as expected */
1095 f_sacch_present(si5);
1096 f_sacch_present(si5bis);
1097 f_sacch_present(si5ter);
1098 f_sacch_present(si6);
1099
1100 /* release the channel */
1101 f_rsl_chan_deact();
1102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1103}
1104testcase TC_sacch_multi() runs on test_CT {
1105 var ConnHdlr vc_conn;
1106 var ConnHdlrPars pars;
1107 f_init();
1108 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1109 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1110 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1111 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1112 vc_conn.done;
1113 }
1114 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001116}
1117
Harald Welte55700662018-03-12 13:15:43 +01001118/* Test if SACH information is modified as expected */
1119private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1120 var octetstring si5 := f_rnd_octstring(19);
1121 var octetstring si6 := f_rnd_octstring(19);
1122
1123 /* First, configure both SI5 and SI6 to be transmitted */
1124 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1125 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1126
1127 f_l1_tune(L1CTL);
1128 RSL.clear;
1129
1130 /* activate the logical channel */
1131 f_est_dchan();
1132 L1CTL.clear;
1133
1134 /* check that SACCH actually are received as expected */
1135 f_sacch_present(si5);
1136 f_sacch_present(si6);
1137
1138 /* disable SI6 */
1139 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1140
1141 /* check that SI5 is still transmitted */
1142 f_sacch_present(si5);
1143 /* check if SI6 is now gone */
1144 f_sacch_missing(si6);
1145
1146 /* release the channel */
1147 f_rsl_chan_deact();
1148 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1149}
1150testcase TC_sacch_multi_chg() runs on test_CT {
1151 var ConnHdlr vc_conn;
1152 var ConnHdlrPars pars;
1153 f_init();
1154 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1155 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1156 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1157 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1158 vc_conn.done;
1159 }
1160 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001162}
1163
Harald Weltec8d363c2019-05-19 20:36:48 +02001164/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1165private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1166 var octetstring si5 := f_rnd_octstring(19);
1167 var octetstring si6 := f_rnd_octstring(19);
1168 var octetstring si5_specific := f_rnd_octstring(19);
1169 var octetstring si6_specific := f_rnd_octstring(19);
1170
1171 /* First, configure both SI5 and SI6 to be transmitted */
1172 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1173 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1174
1175 f_l1_tune(L1CTL);
1176 RSL.clear;
1177
1178 /* activate channel with different SACCH filling */
1179 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1180 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1181 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1182 }));
1183 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1184 RSL_IE_Body:{sacch_info := sacch_info})) };
1185 f_est_dchan(more_ies := addl_ies);
1186
1187 /* check that SACCH actually are received as expected */
1188 f_sacch_present(si5_specific);
1189 f_sacch_present(si6_specific);
1190
1191 /* release the channel */
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_chan_act() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199
1200 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1201 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1202 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1203 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1204 vc_conn.done;
1205 }
1206 /* TODO: do the above in parallel, rather than sequentially? */
1207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1208}
1209
Harald Welte8b01c792019-05-19 22:51:25 +02001210/* verify that SACCH DL transmission is started only if MS power IE present
1211 * see section 4.1.3 of 3GPP TS 48.058 */
1212private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1213 var octetstring si5 := f_rnd_octstring(19);
1214
1215 f_l1_tune(L1CTL);
1216 RSL.clear;
1217
1218 /* Step 1: Activate ASYNC HO channel without MS power IE */
1219
1220 /* Activate channel on BTS side */
1221 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1222 /* don't perform immediate assignment here, as we're testing non-IA case */
1223 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001224 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001225
1226 /* Verify that no DL SACCH is being received */
1227 f_sacch_missing(?);
1228
1229 f_rsl_chan_deact();
1230 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1231
1232
1233 /* Step 2: Activate ASYNC HO channel with MS power IE */
1234
1235 /* Activate channel on BTS side */
1236 var RSL_IE_List addl_ies := {
1237 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1238 };
1239 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1240 /* don't perform immediate assignment here, as we're testing non-IA case */
1241 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001242 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001243
1244 /* Verify that DL SACCH is being received */
1245 f_sacch_present(si5);
1246
1247 f_rsl_chan_deact();
1248 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1249}
1250testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1251 var ConnHdlr vc_conn;
1252 var ConnHdlrPars pars;
1253 f_init();
1254
1255 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1256 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1257 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1258 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1259 vc_conn.done;
1260 }
1261 /* TODO: do the above in parallel, rather than sequentially? */
1262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1263}
1264
1265/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1266 * see section 4.1.4 of 3GPP TS 48.058 */
1267private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1268 var octetstring si5 := f_rnd_octstring(19);
1269 var RSL_IE_List addl_ies;
1270
1271 f_l1_tune(L1CTL);
1272 RSL.clear;
1273
1274 /* Step 1: Activate SYNC HO channel without MS power IE */
1275
1276 /* Activate channel on BTS side */
1277 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1278 /* don't perform immediate assignment here, as we're testing non-IA case */
1279 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001280 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001281
1282 /* Verify that no DL SACCH is being received */
1283 f_sacch_missing(?);
1284
1285 f_rsl_chan_deact();
1286 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1287
1288
1289 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1290
1291 /* Activate channel on BTS side */
1292 addl_ies := {
1293 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1294 };
1295 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1296 /* don't perform immediate assignment here, as we're testing non-IA case */
1297 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001298 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001299
1300 /* Verify that no DL SACCH is being received */
1301 f_sacch_missing(?);
1302
1303 f_rsl_chan_deact();
1304 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1305
1306
1307 /* Step 2b: Activate SYNC HO channel with TA IE */
1308
1309 /* Activate channel on BTS side */
1310 addl_ies := {
1311 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1312 };
1313 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1314 /* don't perform immediate assignment here, as we're testing non-IA case */
1315 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001316 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001317
1318 /* Verify that no DL SACCH is being received */
1319 f_sacch_missing(?);
1320
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323
1324
1325 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1326
1327 /* Activate channel on BTS side */
1328 addl_ies := {
1329 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1330 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1331 };
1332 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1333 /* don't perform immediate assignment here, as we're testing non-IA case */
1334 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001335 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001336
1337 /* Verify that DL SACCH is being received */
1338 f_sacch_present(si5);
1339
1340 f_rsl_chan_deact();
1341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1342}
1343testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1344 var ConnHdlr vc_conn;
1345 var ConnHdlrPars pars;
1346 f_init();
1347
1348 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1349 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1350 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1351 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1352 vc_conn.done;
1353 }
1354 /* TODO: do the above in parallel, rather than sequentially? */
1355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1356}
Harald Welte629cc6b2018-03-11 17:19:05 +01001357
1358
1359/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001360 * RACH Handling
1361 ***********************************************************************/
1362
Harald Welte8c24c2b2018-02-26 08:31:31 +01001363/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001364private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001365 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001366 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001367 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001368
Harald Welte8c24c2b2018-02-26 08:31:31 +01001369 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001370 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001371 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001372 var OCT1 ra := f_rnd_ra_emerg();
1373 if (emerg == true) {
1374 ra := f_rnd_ra_emerg();
1375 } else {
1376 ra := f_rnd_ra_cs();
1377 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001378 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1379 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381 }
1382 fn_last := fn;
1383
1384 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001385 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001387 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001388 T.stop;
1389 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001390 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001392 }
1393 [] RSL_CCHAN.receive { repeat; }
1394 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001395 test_failed := true;
1396 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001397 }
1398 }
1399 }
Maxba06feb2019-03-05 10:52:46 +01001400 if (test_failed) {
1401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001402 }
Maxba06feb2019-03-05 10:52:46 +01001403 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001405}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406
Philipp Maier16ade782020-07-08 21:36:00 +02001407/* Normal variant */
1408testcase TC_rach_content() runs on test_CT {
1409 f_TC_rach_content(emerg := false);
1410}
1411
1412/* Emergency call variant */
1413testcase TC_rach_content_emerg() runs on test_CT {
1414 f_TC_rach_content(emerg := true);
1415}
1416
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1418testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001419 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001420 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001421 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001422 f_l1_tune(L1CTL);
1423
1424 var GsmFrameNumber fn_last := 0;
1425 for (var integer i := 0; i < 1000; i := i+1) {
1426 var OCT1 ra := f_rnd_ra_cs();
1427 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1428 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001430 }
1431 fn_last := fn;
1432 }
1433 var integer rsl_chrqd := 0;
1434 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001435 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001436 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001437 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001439 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 repeat;
1441 }
1442 [] RSL_CCHAN.receive { repeat; }
1443 [] T.timeout { }
1444 }
1445 if (rsl_chrqd == 1000) {
1446 setverdict(pass);
1447 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001449 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001451}
1452
Harald Welte3453ab42019-05-24 21:19:58 +02001453private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1454 var charstring bts_str := "bts " & int2str(bts_nr);
1455 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1456}
1457
1458/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1459private template integer tr_rach_slots_per_interval := (90 .. 130);
1460
1461/* Expect 0 RACH load on an idle BTS that has just started up */
1462testcase TC_rach_load_idle_thresh0() runs on test_CT {
1463 var ASP_RSL_Unitdata rx_ud;
1464
1465 f_init_vty_bsc();
1466 /* send load indications even at 0% load */
1467 f_vty_load_ind_thresh(0);
1468 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1469 f_sleep(2.0);
1470
1471 f_init();
1472
1473 timer T := 5.0;
1474 T.start;
1475 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001476 [] 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 +02001477 setverdict(pass);
1478 repeat;
1479 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001480 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001481 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1482 repeat;
1483 }
1484 [] RSL_CCHAN.receive {
1485 repeat;
1486 }
1487 [] T.timeout { }
1488 }
1489
1490 f_vty_load_ind_thresh(10);
1491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1492}
1493
1494/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1495testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1496 var ASP_RSL_Unitdata rx_ud;
1497
1498 f_init_vty_bsc();
1499 f_init();
1500
1501 timer T := 5.0;
1502 T.start;
1503 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001504 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001505 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1506 repeat;
1507 }
1508 [] RSL_CCHAN.receive {
1509 repeat;
1510 }
1511 [] T.timeout {
1512 setverdict(pass);
1513 }
1514 }
1515
1516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1517}
1518
1519/* Expect 0 RACH load on an idle BTS that has just started up */
1520testcase TC_rach_load_count() runs on test_CT {
1521 var ASP_RSL_Unitdata rx_ud;
1522 var integer load_access_count := 0;
1523
1524 f_init_vty_bsc();
1525 /* send load indications even at 0% load */
1526 f_vty_load_ind_thresh(0);
1527 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1528 f_sleep(2.0);
1529 f_init();
1530
1531 f_init_l1ctl();
1532 f_sleep(1.0);
1533 f_l1_tune(L1CTL);
1534
1535 var GsmFrameNumber fn_last := 0;
1536 for (var integer i := 0; i < 1000; i := i+1) {
1537 var OCT1 ra := f_rnd_ra_cs();
1538 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1539 if (fn == fn_last) {
1540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1541 }
1542 fn_last := fn;
1543 }
1544
1545 timer T := 5.0;
1546 T.start;
1547 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001548 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001549 -> value rx_ud {
1550 var RSL_IE_Body ie;
1551 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1552 load_access_count := load_access_count + ie.rach_load.access_count;
1553 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1554 setverdict(fail, "Access count cannot be < Busy count");
1555 }
1556 repeat;
1557 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001558 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001559 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1560 repeat;
1561 }
1562 [] RSL_CCHAN.receive {
1563 repeat;
1564 }
1565 [] T.timeout { }
1566 }
1567 if (load_access_count == 1000) {
1568 setverdict(pass);
1569 } else {
1570 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1571 }
1572
1573 f_vty_load_ind_thresh(10);
1574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1575}
1576
Harald Welte54a2a2d2018-02-26 09:14:05 +01001577private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001578 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001579 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001580 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001581 f_sleep(0.5);
1582
1583 /* Transmit RACH request + wait for confirmation */
1584 var OCT1 ra := f_rnd_ra_cs();
1585 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1586
1587 /* Check for expected result */
1588 timer T := 1.5;
1589 T.start;
1590 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001591 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001592 setverdict(pass);
1593 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001594 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001596 }
1597 [] RSL_CCHAN.receive { repeat; }
1598 [not expect_pass] T.timeout {
1599 setverdict(pass);
1600 }
1601 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001603 }
1604 }
1605}
1606
1607/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1608testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001609 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610 f_init_l1ctl();
1611 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001612 f_sleep(1.0);
1613
1614 /* default max-ta is 63 (full range of GSM timing advance */
1615
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001616 /* We allow early arrival up to 2 symbols */
1617 f_rach_toffs(-1*256, true);
1618 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001619 f_rach_toffs(-10*256, false);
1620
1621 /* 0 / 32 / 63 bits is legal / permitted */
1622 f_rach_toffs(0, true);
1623 f_rach_toffs(32*256, true);
1624 f_rach_toffs(63*256, true);
1625
1626 /* more than 63 bits is not legal / permitted */
1627 f_rach_toffs(64*256, false);
1628 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001630}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001631
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001632private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001633 var GsmFrameNumber fn;
1634 var RSL_Message rm;
1635
1636 f_l1_tune(L1CTL);
1637 RSL.clear;
1638
1639 /* Generate a random Handover Reference */
1640 var integer ho_ref := oct2int(f_rnd_octstring(1));
1641
1642 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1643 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1644 RSL_IE_Body:{ handover_ref := ho_ref }));
1645
1646 /* Activate a channel on the BTS side (no encryption) */
1647 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1648 act_type := t_RSL_IE_ActType_HO_SYNC);
1649
1650 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1651 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001652 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001653
1654 /* Send handover Access Burst */
1655 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1656
1657 /* TODO: test mismatching Handover Reference, and missing IE */
1658
1659 /* Wait for handover detection */
1660 timer T := 3.0;
1661 T.start;
1662 alt {
1663 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1664 log("Handover RACH has been detected: ", rm);
1665 setverdict(pass);
1666 }
1667 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1669 log2str("RSL_CHAN_RQD was not expected: ", rm));
1670 }
1671 [] RSL.receive { repeat; }
1672 [] T.timeout {
1673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1674 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1675 }
1676 }
1677
1678 /* Release the channel */
1679 f_rsl_chan_deact();
1680 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1681}
1682
1683/* Test handover RACH detection */
1684testcase TC_ho_rach() runs on test_CT {
1685 var ConnHdlrPars pars;
1686 var ConnHdlr vc_conn;
1687
1688 f_init();
1689
1690 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1691 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1692 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1693 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1694 vc_conn.done;
1695 }
1696
1697 /* TODO: do the above in parallel, rather than sequentially? */
1698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1699}
1700
Harald Welte93640c62018-02-25 16:59:33 +01001701/***********************************************************************
1702 * Measurement Processing / Reporting
1703 ***********************************************************************/
1704
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001705private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001706 spare := '0'B,
1707 lpd := 0,
1708 sapi := sapi,
1709 c_r := c_r,
1710 ea := true
1711}
1712
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001713private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001714 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001715 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001716 len := 0, /* overwritten */
1717 m := false,
1718 el := 1,
1719 payload := pl
1720}
1721
1722/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001723private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001724 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001725 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001726 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001727 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 +01001728 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001729 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001730
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001731 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1732 g_pars.l1_pars.ms_power_level, false,
1733 g_pars.l1_pars.ms_actual_ta);
1734
1735 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1736 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1737
1738 log("Sending Measurement Report: ", l1h, l2);
1739 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001740 repeat;
1741 }
1742}
1743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001744private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001745 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001746 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001747 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1748 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001749 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1750 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001751 repeat;
1752 }
1753}
1754
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001755private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001756 uint6_t rxlev,
1757 uint3_t rxqual
1758}
1759
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001760private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001761 MeasElem full,
1762 MeasElem sub
1763}
1764
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001765private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001766 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001767 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001768 MeasElemFS meas_ul,
1769 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001770 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001771 uint5_t ms_power_level,
1772 uint8_t ms_actual_ta
1773}
1774
1775/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1776private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1777 return 63 + (toffs256s/256);
1778}
1779
Harald Welted5684392018-03-10 18:22:04 +01001780private function f_max(integer a, integer b) return integer {
1781 if (a > b) {
1782 return a;
1783 } else {
1784 return b;
1785 }
1786}
1787
1788private function f_min(integer a, integer b) return integer {
1789 if (a < b) {
1790 return a;
1791 } else {
1792 return b;
1793 }
1794}
1795
1796/* compute negative tolerance val-tolerance, ensure >= min */
1797private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1798 val := val - tolerance;
1799 return f_max(val, min);
1800}
1801
1802/* compute positive tolerance val+tolerance, ensure <= max */
1803private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1804 val := val + tolerance;
1805 return f_min(val, max);
1806}
1807
1808/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1809private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1810return template integer {
1811 var template integer ret;
1812 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1813 return ret;
1814}
1815
1816
Harald Welte70767382018-02-21 12:16:40 +01001817/* build a template for matching measurement results against */
1818private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1819 var ConnL1Pars l1p := g_pars.l1_pars;
1820 var template RSL_IE_UplinkMeas ul_meas := {
1821 len := 3,
1822 rfu := '0'B,
1823 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001824 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001825 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001826 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001827 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001828 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1829 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001830 supp_meas_info := omit
1831 };
Harald Welte685d5982018-02-27 20:42:05 +01001832 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001833 ul_meas.len := (3+8);
1834 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001835 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001836 toa256_min := ?,
1837 toa256_max := ?,
1838 toa256_std_dev := ?
1839 }
Harald Welte685d5982018-02-27 20:42:05 +01001840 }
Harald Welte70767382018-02-21 12:16:40 +01001841 var template RSL_IE_BS_Power bs_power := {
1842 reserved := 0,
1843 epc := false,
1844 fpc := false,
1845 power_level := l1p.bs_power_level
1846 };
1847 var template RSL_IE_L1Info l1_info := {
1848 ms_power_lvl := l1p.ms_power_level,
1849 fpc := false,
1850 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001851 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001852 };
1853 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001854 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001855 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1856 ?, t_toffs);
1857}
1858
Philipp Maierdd841d32019-12-17 14:44:54 +01001859/* build a template for matching measurement results that do not contain any
1860 * MS related measurement (l1_info, l3_info and ms timing offset). */
1861private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1862 var ConnL1Pars l1p := g_pars.l1_pars;
1863 var template RSL_IE_UplinkMeas ul_meas := {
1864 len := 3,
1865 rfu := '0'B,
1866 dtx_d := l1p.dtx_enabled,
1867 rxlev_f_u := ?,
1868 reserved1 := '00'B,
1869 rxlev_s_u := ?,
1870 reserved2 := '00'B,
1871 rxq_f_u := ?,
1872 rxq_s_u := ?,
1873 supp_meas_info := omit
1874 };
1875 if (l1p.toa256_enabled) {
1876 ul_meas.len := (3+8);
1877 ul_meas.supp_meas_info := {
1878 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1879 toa256_min := ?,
1880 toa256_max := ?,
1881 toa256_std_dev := ?
1882 }
1883 }
1884 var template RSL_IE_BS_Power bs_power := {
1885 reserved := 0,
1886 epc := false,
1887 fpc := false,
1888 power_level := l1p.bs_power_level
1889 };
1890
1891 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1892}
1893
Harald Welte70767382018-02-21 12:16:40 +01001894/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001895private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001896 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001897 var boolean chan_est := false;
1898
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001899 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001900
1901 /* Receive osmocom specific measurement reports. This is the normal
1902 * case. Here we verify that the measurement reports we sent are
1903 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001904 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1905 /* increment counter of next to-be-expected meas rep */
1906 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1907 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001908 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001909
1910 /* The following two cases may only happen in the beginning
1911 * of the channel establishment phase. Once we have received
1912 * the "our" measurement report the first time, the channel
1913 * is established and empty or hardcoded TRXCON reports must
1914 * not occur anymore. */
1915 chan_est := true;
1916
1917 repeat;
1918 }
1919
1920 /* When the BTS has established the channel, the MS might need slightly
1921 * more time to establish the channel and actually start sending. The
1922 * result is then a measurement report that just lacks the measurement
1923 * information of the MS. This is normal and we tolerate this behavior. */
1924 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1925 /* increment counter of next to-be-expected meas rep */
1926 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1927 /* Re-start the timer expecting the next MEAS RES */
1928 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001929 repeat;
1930 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001931
1932 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1933 * measurements if the TTCN3 side does not supply measurement input in
1934 * time. In those cases TRXCON will either use a cached measurement
1935 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1936 * report the templates above will not match. We tolerate this
1937 * behavior, but only once. */
1938 [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 +01001939 /* increment counter of next to-be-expected meas rep */
1940 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1941 if (g_first_meas_res) {
1942 g_first_meas_res := false;
1943 repeat;
1944 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001946 }
Harald Welte70767382018-02-21 12:16:40 +01001947 }
1948 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001950 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001951 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001953 }
1954}
1955
Harald Weltee613f962018-04-18 22:38:16 +02001956private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1957 select (rsl_alg_id) {
1958 case (RSL_ALG_ID_A5_0) { return 0; }
1959 case (RSL_ALG_ID_A5_1) { return 1; }
1960 case (RSL_ALG_ID_A5_2) { return 2; }
1961 case (RSL_ALG_ID_A5_3) { return 3; }
1962 case (RSL_ALG_ID_A5_4) { return 4; }
1963 case (RSL_ALG_ID_A5_5) { return 5; }
1964 case (RSL_ALG_ID_A5_6) { return 6; }
1965 case (RSL_ALG_ID_A5_7) { return 7; }
1966 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1968 /* Make compiler happy by calling mtc.stop here. It is already
1969 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001970 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001971 }
1972 }
1973}
1974
1975private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1976 select (rsl_alg_id) {
1977 case (RSL_ALG_ID_A5_1) { return '000'B; }
1978 case (RSL_ALG_ID_A5_2) { return '001'B; }
1979 case (RSL_ALG_ID_A5_3) { return '010'B; }
1980 case (RSL_ALG_ID_A5_4) { return '011'B; }
1981 case (RSL_ALG_ID_A5_5) { return '100'B; }
1982 case (RSL_ALG_ID_A5_6) { return '101'B; }
1983 case (RSL_ALG_ID_A5_7) { return '110'B; }
1984 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1986 /* Make compiler happy by calling mtc.stop here. It is already
1987 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001988 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001989 }
1990 }
1991}
1992
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001993/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1994private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1995 var GsmFrameNumber fn;
1996 timer T := 8.0;
1997
1998 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1999 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2000
2001 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2002 /* Send the actual RACH */
2003 fn := f_L1CTL_RACH(L1CTL, ra);
2004
2005 T.start;
2006 alt {
2007 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2008 [] T.timeout {
2009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2010 }
2011 }
2012 T.stop
2013 return fn;
2014}
Harald Weltee613f962018-04-18 22:38:16 +02002015
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002016/* Tune to a dedicated channel: L1CTL only */
2017private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002018 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002019 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2020 7 /* TODO: mp_tsc */,
2021 mp_trx0_arfcn));
2022 } else {
2023 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2024 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002025 pars.fhp.maio_hsn.hsn,
2026 pars.fhp.maio_hsn.maio,
2027 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002028 }
2029}
2030
Harald Welte70767382018-02-21 12:16:40 +01002031/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002032private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002033 var GsmFrameNumber fn;
2034 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002035 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002036 var integer ra := 23;
2037
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002038 /* Send RACH request and wait for ChanReq */
2039 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002040
2041 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002042 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002043
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002044 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002045 if (g_pars.fhp.enabled) {
2046 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002047 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002048 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002049 }
2050
Harald Welte70767382018-02-21 12:16:40 +01002051 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002052 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002053 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2054
2055 /* receive IMM.ASS on MS side */
2056 var ImmediateAssignment ia_um;
2057 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002058
2059 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2060 if (ch_desc.h != ia_um.chan_desc.h) {
2061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2062 }
2063
Harald Welte70767382018-02-21 12:16:40 +01002064 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002065 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002066 /* enable encryption, if requested */
2067 if (encr_enable) {
2068 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2069 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2070 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002071
2072 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002073}
2074
2075/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002076private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002077 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002078 RSL.clear;
2079
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002080 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002081 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002082 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002083 }
Harald Welte70767382018-02-21 12:16:40 +01002084
2085 f_est_dchan();
2086
2087 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2088 * RSL measurement reports on Abis side */
2089 timer T := 8.0;
2090 T.start;
2091 alt {
2092 [] as_l1_sacch();
2093 [] as_meas_res();
2094 [] as_l1_dcch();
2095 [] L1CTL.receive { repeat; }
2096 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002097 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002098 * of any earlier errors, so if we reach this timeout, we're good */
2099 setverdict(pass);
2100 }
2101 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002103 }
2104 }
2105 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002106 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002107}
Harald Welte0472ab42018-03-12 15:02:26 +01002108
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002109/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2110private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002111 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002112 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2113 timer Tup := 10.0;
2114 Tup.start;
2115 alt {
2116 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2117 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2118 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002119
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002120 if (rx_lvl != max_rx_lvl) {
2121 repeat;
2122 }
2123 Tup.stop;
2124 }
2125 [] L1CTL.receive { repeat; }
2126 [] Tup.timeout {
2127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2128 log2str("Didn't reach full power ", max_rx_lvl));
2129 }
2130 }
2131 return max_rx_lvl;
2132}
2133
2134/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2135private function f_verify_ramp_up() runs on ConnHdlr {
2136 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002137 var integer initial_rx_lvl := -1;
2138 var integer last_rx_lvl := -1;
2139 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2140
2141 timer T := 2.0;
2142 alt {
2143 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2144 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2145 log("Received rx_level=", rx_lvl);
2146 if (initial_rx_lvl == -1) {
2147 initial_rx_lvl := rx_lvl;
2148 last_rx_lvl := rx_lvl;
2149
2150 /* Expect a somehow low value during first received messages */
2151 if (initial_rx_lvl >= max_rx_lvl / 2) {
2152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2153 log2str("Detected high initial tx power during ramp up: ",
2154 initial_rx_lvl , ", full power is", max_rx_lvl));
2155 }
2156 }
2157
2158 /* received Rx level bigger than maximum allowed power by CN */
2159 if (rx_lvl > max_rx_lvl) {
2160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2161 log2str("Detected Tx power higher than full power: ",
2162 rx_lvl , " > ", max_rx_lvl));
2163 }
2164
2165 /* Make sure it never decreases, since we are rumping up */
2166 if (last_rx_lvl > rx_lvl) {
2167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2168 log2str("Detected Tx power decrease during ramp up: ",
2169 last_rx_lvl , " -> ", rx_lvl));
2170 }
2171
2172 if (rx_lvl == max_rx_lvl and not T.running) {
2173 /* We reached the maximum power, start timer and receive
2174 /* a few more to make sure we don't surpass it */
2175 log("Reached full power, wating a bit more until success");
2176 T.start;
2177 }
2178
2179 last_rx_lvl := rx_lvl;
2180 repeat;
2181 }
2182 [] L1CTL.receive { repeat; }
2183 [] T.timeout { }
2184 }
2185
2186 /* We didn't increase tx power during ramp up */
2187 if (initial_rx_lvl < last_rx_lvl) {
2188 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2189 } else {
2190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2191 log2str("No Tx power increase during whole ramp up: ",
2192 initial_rx_lvl , " -> ", last_rx_lvl));
2193 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002194}
2195
2196/* verify BTS ramps power down to rx_level 0 */
2197private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2198 var L1ctlDlMessage l1_dl;
2199 var integer last_rx_lvl := max_rx_lvl;
2200
2201 timer Tdown := 5.0;
2202 Tdown.start;
2203 alt {
2204 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2205 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2206 log("Received rx_level=", rx_lvl);
2207
2208 /* received Rx level bigger than maximum allowed power by CN */
2209 if (rx_lvl > max_rx_lvl) {
2210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2211 log2str("Detected Tx power higher than full power: ",
2212 rx_lvl , " > ", max_rx_lvl));
2213 }
2214
2215 /* Make sure it never increases, since we are rumping down */
2216 if (last_rx_lvl < rx_lvl) {
2217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2218 log2str("Detected Tx power increase during ramp up: ",
2219 last_rx_lvl , " -> ", rx_lvl));
2220 }
2221
2222 last_rx_lvl := rx_lvl;
2223 if (last_rx_lvl != 0) {
2224 repeat;
2225 }
2226 /* we reached power level 0, we are done */
2227 Tdown.stop;
2228 }
2229 [] L1CTL.receive { repeat; }
2230 [] Tdown.timeout { }
2231 }
2232
2233 /* We didn't increase tx power during ramp down */
2234 if (max_rx_lvl > last_rx_lvl) {
2235 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2236 } else {
2237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2238 log2str("No Tx power decrease during whole ramp down: ",
2239 max_rx_lvl , " -> ", last_rx_lvl));
2240 }
2241}
2242
2243/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002244private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002245 f_l1_tune(L1CTL);
2246 RSL.clear;
2247
2248 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002249
2250 setverdict(pass);
2251}
2252testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2253 var ConnHdlr vc_conn;
2254 var ConnHdlrPars pars;
2255 f_init();
2256 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2257 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2258 pcu_comp := false, trxc_comp := true);
2259 vc_conn.done;
2260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2261}
2262
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002263/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002264private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002265 f_connhdlr_init_vty_bsc();
2266
2267 f_l1_tune(L1CTL);
2268 RSL.clear;
2269
2270 /* Wait until BTS is started and at full power */
2271 var integer max_rx_lvl := f_wait_ramp_up();
2272 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2273
2274 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2275 f_verify_ramp_down(max_rx_lvl);
2276
2277 setverdict(pass);
2278}
2279testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2280 var ConnHdlr vc_conn;
2281 var ConnHdlrPars pars;
2282 f_init();
2283 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2284 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2285 pcu_comp := false, trxc_comp := true);
2286 vc_conn.done;
2287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2288}
2289
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002290/* Verify Tx power:
2291 * + ramping down during ADM state UNLOCKED->LOCKED
2292 * + ramping up during ADM state LOCKED->UNLOCKED
2293 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002294private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002295 var L1ctlDlMessage l1_dl;
2296 var integer last_rx_lvl;
2297
2298 f_connhdlr_init_vty_bsc();
2299
2300 f_l1_tune(L1CTL);
2301 RSL.clear;
2302
2303 /* Wait until BTS is started and at full power */
2304 var integer max_rx_lvl := f_wait_ramp_up();
2305 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2306
2307 log("ADM STATE UNLOCKED->LOCKED");
2308 f_vty_enter_cfg_trx(BSCVTY);
2309 f_vty_transceive(BSCVTY, "rf_locked 1");
2310 last_rx_lvl := max_rx_lvl;
2311 f_verify_ramp_down(max_rx_lvl);
2312
2313 /* Let some time after we received 0dBm, then check we don't receive BCCH
2314 * anymore because scheduler has stopped after ramping down */
2315 f_sleep(2.0);
2316 L1CTL.clear;
2317 timer Tlocked := 2.0;
2318 Tlocked.start;
2319 alt {
2320 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2322 log2str("Received data_ind during rf_locked: ", l1_dl));
2323 }
2324 [] L1CTL.receive { repeat; }
2325 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2326 }
2327
2328 log("ADM STATE LOCKED->UNLOCKED");
2329 f_vty_transceive(BSCVTY, "rf_locked 0");
2330 f_verify_ramp_up();
2331 setverdict(pass);
2332}
2333testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2334 var ConnHdlr vc_conn;
2335 var ConnHdlrPars pars;
2336 f_init();
2337 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2338 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2339 pcu_comp := false, trxc_comp := true);
2340 vc_conn.done;
2341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2342}
2343
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002344private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002345 timer T := 8.0;
2346 T.start;
2347 var RSL_Message rsl;
2348 alt {
2349 [] as_l1_sacch();
2350 [] L1CTL.receive { repeat; }
2351 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2352 if (rsl.ies[3].body.bs_power.power_level == level) {
2353 setverdict(pass)
2354 } else {
2355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2356 }
2357 }
2358 [] T.timeout {
2359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2360 }
2361 }
2362}
2363
2364/* see if the rsl meas res contains our expeced bs power level
2365bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002366private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002367 f_l1_tune(L1CTL);
2368 RSL.clear;
2369
2370 if (mp_bts_trxc_port != -1) {
2371 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2372 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2373 }
2374
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002375 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002376 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2377 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2378
2379 f_est_dchan(more_ies :={valueof(pwr)});
2380
2381 f_check_meas_bs_power_level(pwr_var);
2382
2383 f_rsl_chan_deact();
2384 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2385}
2386
2387/* see if the rsl meas res contains our expeced bs power level
2388bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002389private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002390 f_l1_tune(L1CTL);
2391 RSL.clear;
2392
2393 if (mp_bts_trxc_port != -1) {
2394 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2395 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2396 }
2397
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002398 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002399 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2400
2401 f_est_dchan();
2402
2403 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2404
2405 f_check_meas_bs_power_level(pwr_var);
2406
2407 f_rsl_chan_deact();
2408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2409}
2410
2411testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2412 var ConnHdlr vc_conn;
2413 var ConnHdlrPars pars;
2414 f_init();
2415 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2416 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2417 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2418 pcu_comp := false, trxc_comp := true);
2419 vc_conn.done;
2420 }
2421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2422}
2423
2424testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2425 var ConnHdlr vc_conn;
2426 var ConnHdlrPars pars;
2427 f_init();
2428 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2429 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2430 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2431 pcu_comp := false, trxc_comp := true);
2432 vc_conn.done;
2433 }
2434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2435}
2436
Eric Wild61edb7e2019-06-03 12:38:31 +02002437/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2438second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2439These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002440private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002441 var uint5_t pwr_var := 7;
2442 var L1ctlDlMessage l1_dl;
2443
2444 f_trxc_fake_rssi(rxlev2dbm(10));
2445 f_l1_tune(L1CTL);
2446 RSL.clear;
2447
2448 var RSL_IE_List addl_ies;
2449 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2450
2451 addl_ies := {
2452 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2453 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2454 };
2455
2456 /* establish with power parameters */
2457 f_est_dchan(more_ies := addl_ies);
2458
2459 /* set a high value to ensure L1 power control level increases */
2460 f_trxc_fake_rssi(rxlev2dbm(20));
2461
2462 timer T2 := 6.0;
2463 T2.start;
2464 alt {
2465 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002466 /* Update sent MS power to follow what BTS requests */
2467 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2468 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002469 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002470 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002471 T2.stop;
2472 }
2473 [] L1CTL.receive { repeat; }
2474 [] T2.timeout {
2475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2476 "Power Level in L1 header has not increased sufficiently");
2477 }
2478 }
2479
2480 /* set a low value to ensure L1 power control level decreases */
2481 f_trxc_fake_rssi(rxlev2dbm(0));
2482
2483 timer T4 := 6.0;
2484 T4.start;
2485 alt {
2486 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002487 /* Update sent MS power to follow what BTS requests */
2488 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2489 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002490 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002491 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002492 T4.stop;
2493 setverdict(pass, "Power level in L1 decreased/increased as expected");
2494 }
2495 [] L1CTL.receive { repeat; }
2496 [] T4.timeout {
2497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2498 "Power Level in L1 header has not decreased sufficiently");
2499 }
2500 }
2501
2502 f_rsl_chan_deact();
2503 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2504
2505}
2506
2507/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002508private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002509 var uint5_t pwr_var := 7;
2510 var L1ctlDlMessage l1_dl;
2511
2512 /* set a low value to ensure power increases */
2513 f_trxc_fake_rssi(rxlev2dbm(10));
2514 f_l1_tune(L1CTL);
2515 RSL.clear;
2516
2517 var RSL_IE_List addl_ies;
2518 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2519
2520 addl_ies := {
2521 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2522 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2523 };
2524
2525 /* establish with power parameters */
2526 f_est_dchan(more_ies := addl_ies);
2527
2528 timer T1 := 10.0;
2529 T1.start;
2530 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002531 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2532 /* Update sent MS power to follow what BTS requests */
2533 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2534 repeat;
2535 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002536 [] L1CTL.receive { repeat; }
2537 [] T1.timeout {
2538 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2539 setverdict(fail, "Power level in L1 header should not have changed");
2540 }
2541 }
2542 }
2543
2544 f_rsl_chan_deact();
2545 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2546
2547}
2548
2549/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002550private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002551 var L1ctlDlMessage l1_dl;
2552 var uint5_t pwr_var := 15;
2553 var uint5_t pwr_max_var := f_get_max_power_from_band();
2554
2555 /* set a low value to ensure power increases */
2556 f_trxc_fake_rssi(rxlev2dbm(10));
2557 f_l1_tune(L1CTL);
2558 RSL.clear;
2559
2560 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2561 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2562
2563 /* establish with fixed power level */
2564 f_est_dchan(more_ies :={valueof(pwr)});
2565
2566 /* check our initial power level */
2567 f_wait_for_l1_power_level(pwr_var);
2568
2569 /* update power param to enable power loop
2570 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2571 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2572
2573 /* wait, then check that our power level was reduced */
2574 timer T1 := 10.0;
2575 T1.start;
2576 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002577 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2578 /* Update sent MS power to follow what BTS requests */
2579 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2580 repeat;
2581 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002582 [] L1CTL.receive { repeat; }
2583 [] T1.timeout {
2584 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2585 if( f_power_level_is_highest_dbm(rcv) ){
2586 setverdict(pass, "Power level in L1 header reduced as expected");
2587 } else {
2588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2589 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2590 }
2591 }
2592 }
2593
2594 f_rsl_chan_deact();
2595 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2596
2597}
2598
2599/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002600private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002601 var L1ctlDlMessage l1_dl;
2602
2603 /* set a high value to ensure power decreases */
2604 f_trxc_fake_rssi(rxlev2dbm(50));
2605 f_l1_tune(L1CTL);
2606 RSL.clear;
2607
2608 var uint5_t pwr_var := 5;
2609 var uint5_t pwr_target_val := 15;
2610
2611 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2612 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2613
2614 /* establish with fixed power level */
2615 f_est_dchan(more_ies :={valueof(pwr)});
2616
2617 /* check our initial power level */
2618 f_wait_for_l1_power_level(pwr_var);
2619
2620 /* update power param to enable power loop
2621 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002622 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002623
2624 /* wait, then check that our power level was increased */
2625 timer T1 := 10.0;
2626 T1.start;
2627 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002628 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2629 /* Update sent MS power to follow what BTS requests */
2630 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2631 repeat;
2632 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002633 [] L1CTL.receive { repeat; }
2634 [] T1.timeout {
2635 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2636 setverdict(pass, "Power level in L1 header increased to lowest power value");
2637 } else {
2638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2639 "Power level in L1 header NOT increased to lowest power value");
2640 }
2641 }
2642 }
2643
2644 f_rsl_chan_deact();
2645 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2646
2647}
2648
Eric Wild095024b2019-06-17 15:08:57 +02002649/* see if we change the power level without receiving power parameters, which should not happen
2650rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002651private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002652 var L1ctlDlMessage l1_dl;
2653
2654 /* set a high value to ensure power decreases */
2655 f_trxc_fake_rssi(rxlev2dbm(50));
2656 f_l1_tune(L1CTL);
2657 RSL.clear;
2658
2659 var uint5_t pwr_var := 5;
2660
2661 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2662 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2663
2664 /* establish with fixed power level */
2665 f_est_dchan(more_ies :={valueof(pwr)});
2666
2667 /* check our initial power level */
2668 f_wait_for_l1_power_level(pwr_var);
2669
2670 /* wait, then check that our power level did not change */
2671 timer T1 := 10.0;
2672 T1.start;
2673 alt {
2674 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2675 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2677 "BS power control should not be active unless we receive a power parameters IE!");
2678 }
2679 repeat;
2680 }
2681 [] L1CTL.receive { repeat; }
2682 [] T1.timeout { setverdict(pass); }
2683 }
2684
2685 f_rsl_chan_deact();
2686 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2687
2688}
2689
Eric Wild095024b2019-06-17 15:08:57 +02002690/* see if we change the power level without receiving power parameters, which should not happen
2691ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002692private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002693 var L1ctlDlMessage l1_dl;
2694
2695 /* set a high value to ensure power decreases */
2696 f_trxc_fake_rssi(rxlev2dbm(50));
2697 f_l1_tune(L1CTL);
2698 RSL.clear;
2699
2700 var uint5_t pwr_var := 5;
2701
2702 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2703 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2704
2705 /* establish with fixed power level */
2706 f_est_dchan(more_ies :={valueof(pwr)});
2707
2708 /* check our initial power level */
2709 f_wait_for_l1_power_level(pwr_var);
2710
2711 /* pwr control without power params IE, should NOT activate MS power control*/
2712 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2713
2714 /* wait, then check that our power level did not change */
2715 timer T1 := 10.0;
2716 T1.start;
2717 alt {
2718 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2719 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2721 "BS power control should not be active unless we receive a power parameters IE!");
2722 }
2723 repeat;
2724 }
2725 [] L1CTL.receive { repeat; }
2726 [] T1.timeout { setverdict(pass); }
2727 }
2728
2729 f_rsl_chan_deact();
2730 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2731
2732}
2733
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002734private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002735 var L1ctlDlMessage l1_dl;
2736 timer T0 := 10.0;
2737 T0.start;
2738 alt {
2739 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2740 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2742 "Power level in L1 header != signaled (RSL) power level.");
2743 }
2744 }
2745 [] L1CTL.receive { repeat; }
2746 [] T0.timeout {
2747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2748 "Timeout waiting for initial power level");
2749 }
2750 }
2751 T0.stop;
2752}
2753
2754private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2755 var IntegerRecord min_dbm_level;
2756 var IntegerRecord max_dbm_level;
2757 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2758
2759 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2760 if (min_dbm_level[i] == level) {
2761 return true;
2762 }
2763 }
2764 return false;
2765}
2766
2767private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2768 var IntegerRecord min_dbm_level;
2769 var IntegerRecord max_dbm_level;
2770 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2771
2772 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2773 if (max_dbm_level[i] == level) {
2774 return true;
2775 }
2776 }
2777 return false;
2778}
2779
2780private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2781 var IntegerRecord min_dbm_level;
2782 var IntegerRecord max_dbm_level;
2783 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2784 return max_dbm_level[0];
2785}
2786
2787type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002788private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002789private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2790 // 45.005 4.1.1
2791 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2792 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2793 2, 1, 0};
2794 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2795 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2796 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2797 var IntegerRecord rv;
2798
2799 select(band){
2800 case (BtsBand_allGSM){
2801 rv := gsm_power;
2802 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2803 max_dbm_level := {2, 1, 0};
2804 }
2805 case("DCS1800"){
2806 rv := dcs_power;
2807 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2808 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2809 }
2810 case("PCS1900"){
2811 rv := pcs_power;
2812 min_dbm_level := {15};
2813 max_dbm_level := {30};
2814 }
2815 }
2816
2817 return rv;
2818}
2819
2820private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2821 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2822}
2823
2824testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2825 var ConnHdlr vc_conn;
2826 var ConnHdlrPars pars;
2827 f_init();
2828 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2829 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2830 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2831 pars.bts0_band := f_vty_get_bts0_band();
2832 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2833 vc_conn.done;
2834 }
2835 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2837}
2838
2839testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2840 var ConnHdlr vc_conn;
2841 var ConnHdlrPars pars;
2842 f_init();
2843 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2844 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2845 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2846 pars.bts0_band := f_vty_get_bts0_band();
2847 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2848 vc_conn.done;
2849 }
2850 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2852}
2853
2854testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2855 var ConnHdlr vc_conn;
2856 var ConnHdlrPars pars;
2857 f_init();
2858 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2859 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2860 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2861 pars.bts0_band := f_vty_get_bts0_band();
2862 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2863 vc_conn.done;
2864 }
2865 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2867}
2868
2869testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2870 var ConnHdlr vc_conn;
2871 var ConnHdlrPars pars;
2872 f_init();
2873 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2874 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2875 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2876 pars.bts0_band := f_vty_get_bts0_band();
2877 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2878 vc_conn.done;
2879 }
2880 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2882}
2883
Eric Wild280ccb82019-06-17 11:11:52 +02002884testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2885 var ConnHdlr vc_conn;
2886 var ConnHdlrPars pars;
2887 f_init();
2888 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2889 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2890 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2891 pars.bts0_band := f_vty_get_bts0_band();
2892 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2893 vc_conn.done;
2894 }
2895 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2897}
2898
Eric Wild095024b2019-06-17 15:08:57 +02002899testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2900 var ConnHdlr vc_conn;
2901 var ConnHdlrPars pars;
2902 f_init();
2903 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2904 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2905 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2906 pars.bts0_band := f_vty_get_bts0_band();
2907 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2908 vc_conn.done;
2909 }
2910 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2912}
2913
Harald Welte70767382018-02-21 12:16:40 +01002914testcase TC_meas_res_sign_tchf() runs on test_CT {
2915 var ConnHdlr vc_conn;
2916 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002917 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002918 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2919 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002920 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2921 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002922 vc_conn.done;
2923 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002925}
2926testcase TC_meas_res_sign_tchh() runs on test_CT {
2927 var ConnHdlr vc_conn;
2928 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002929 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002930 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2931 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002932 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2933 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002934 vc_conn.done;
2935 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002937}
2938testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2939 var ConnHdlr vc_conn;
2940 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002941 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002942 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2943 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002944 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2945 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002946 vc_conn.done;
2947 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002949}
2950testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2951 var ConnHdlr vc_conn;
2952 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002953 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002954 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2955 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002956 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2957 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002958 vc_conn.done;
2959 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002961}
Harald Welte685d5982018-02-27 20:42:05 +01002962testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2963 var ConnHdlr vc_conn;
2964 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002965 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002966 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2967 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2968 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2969 pars.l1_pars.toa256_enabled := true;
2970 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2971 vc_conn.done;
2972 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002974}
2975
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002976/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2977 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002978private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002979 var L1ctlDlMessage l1_dl;
2980 var RSL_IE_MS_Power ms_power;
2981 var RSL_Message rsl;
2982 var uint5_t power_level := 0;
2983
2984 f_l1_tune(L1CTL);
2985 RSL.clear;
2986
2987 f_est_dchan();
2988
2989 ms_power.reserved := 0;
2990 ms_power.fpc_epc := false;
2991
2992 /* Send the first power control command. This will disable any BTS/TRX
2993 * internal power control and switch the MS (which is not in scope of
2994 * this test) to a constant power level. We start with a power level
2995 * of 0 */
2996 ms_power.power_level := power_level;
2997 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2998 RSL.send(rsl);
2999
3000 alt {
3001
3002 /* Pick all SACCH blocks for checking */
3003 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3004
3005 /* The first byte of the L1 header contains the power level.
3006 * The reserved bits and the fpc bit is set to 0, so we may
3007 * compare directly. */
3008 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3009 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3010 }
3011
3012 /* Signal a new power level via RSL for the next turn. */
3013 if (power_level < 31) {
3014 power_level := power_level + 1;
3015 ms_power.power_level := power_level;
3016 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3017 RSL.send(rsl);
3018 repeat;
3019 }
3020
3021 }
3022
3023 /* Ignore all other blocks */
3024 [] L1CTL.receive { repeat; }
3025
3026 }
3027
3028 f_rsl_chan_deact();
3029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3030
3031 setverdict(pass);
3032}
3033
3034testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3035 var ConnHdlr vc_conn;
3036 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003037 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003038
3039 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3040 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3041 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3042 vc_conn.done;
3043 }
3044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3045}
Harald Welte70767382018-02-21 12:16:40 +01003046
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003047/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003048TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003049private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003050 var L1ctlDlMessage l1_dl;
3051 var uint5_t ta_to_test := 16;
3052
3053
3054 f_l1_tune(L1CTL);
3055 RSL.clear;
3056
3057 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003058 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003059
3060 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3061
3062
3063 alt {
3064
3065 /* Pick all SACCH blocks for checking */
3066 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3067
3068 /* The second byte of the L1 header contains the TA. */
3069 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3070 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3071 }
3072
3073 }
3074
3075 /* Ignore all other blocks */
3076 [] L1CTL.receive { repeat; }
3077
3078 }
3079
3080 f_rsl_chan_deact();
3081 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3082
3083 setverdict(pass);
3084}
3085
3086testcase TC_rsl_chan_initial_ta() runs on test_CT {
3087 var ConnHdlr vc_conn;
3088 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003089 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003090 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003091 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3092 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003093 vc_conn.done;
3094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3095}
3096
Eric Wilde57e1a62019-05-28 13:30:55 +02003097/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003098private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003099 var L1ctlDlMessage l1_dl;
3100 var uint5_t ms_power_level := 7;
3101
3102 var RSL_IE_MS_Power ms_power;
3103 ms_power.reserved := 0;
3104 ms_power.fpc_epc := false;
3105 ms_power.power_level := ms_power_level;
3106
3107 f_l1_tune(L1CTL);
3108 RSL.clear;
3109
3110 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3111
3112 timer T := 1.0;
3113 T.start;
3114 alt {
3115 /* Pick all SACCH blocks for checking */
3116 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3117 /* The first byte of the L1 header contains the power level.. */
3118 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3119 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3120 }
3121 }
3122 /* Ignore all other blocks */
3123 [] L1CTL.receive { repeat; }
3124 [] T.timeout {
3125 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3126 }
3127 }
3128
3129 f_rsl_chan_deact();
3130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3131 setverdict(pass);
3132}
3133
3134testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3135 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3136 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3137}
3138
Harald Welte0472ab42018-03-12 15:02:26 +01003139/* 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 +01003140private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003141 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003142 RSL.clear;
3143
3144 f_est_dchan();
3145 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003146 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003147
3148 timer T := 40.0;
3149 T.start;
3150 alt {
3151 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3152 setverdict(pass)
3153 }
3154 [] RSL.receive { repeat };
3155 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003157 }
3158 }
3159 f_rsl_chan_deact();
3160}
3161testcase TC_conn_fail_crit() runs on test_CT {
3162 var ConnHdlr vc_conn;
3163 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003164 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003165 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3166 pars.t_guard := 60.0;
3167 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3168 vc_conn.done;
3169}
3170
Harald Welte93640c62018-02-25 16:59:33 +01003171/***********************************************************************
3172 * Paging
3173 ***********************************************************************/
3174
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003175private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003176 if (tmsi == 'FFFFFFFF'O) {
3177 return true;
3178 } else {
3179 return false;
3180 }
3181}
Harald Welte70767382018-02-21 12:16:40 +01003182
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003183private type record allowedFn { integer frame_nr }
3184private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3185private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3186private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3187private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3188private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3189private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3190private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3191private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3192private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003193{
3194 var integer frame_nr_51;
3195 frame_nr_51 := frame_nr mod 51
3196
3197 var allowedFn fn_check;
3198 fn_check.frame_nr := frame_nr_51;
3199
3200 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003202 return;
3203 }
3204
3205 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3206 return;
3207 }
3208 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3209 return;
3210 }
3211 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3212 return;
3213 }
3214 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3215 return;
3216 }
3217 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3218 return;
3219 }
3220 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3221 return;
3222 }
3223 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3224 return;
3225 }
3226 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3227 return;
3228 }
3229
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003231 return;
3232}
3233
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003234private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3235 inout integer num_paging_rcv_ids,
3236 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003237runs on test_CT {
3238 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003239 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003240 repeat;
3241 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003242 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003243 var octetstring without_plen :=
3244 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3245 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003246
3247 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3248
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003249 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3250 /* Ignore empty RR Paging Request (PCH filling) messages.
3251 * TODO: does it make sense to count them? */
3252 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003253 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3254 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003255 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
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_REQ2)) {
3259 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3260 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3261 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3262 }
3263 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3264 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3265 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003266 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003267 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3268 }
3269 } else if (match(rr, tr_PAGING_REQ3)) {
3270 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3271 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3272 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3273 }
3274 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3275 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3276 }
3277 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3278 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3279 }
3280 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3281 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3282 }
3283 }
3284 repeat;
3285 }
3286}
3287
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003288private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003289 boolean combined_ccch,
3290 integer bs_ag_blks_res,
3291 float load_factor,
3292 boolean exp_load_ind,
3293 boolean exp_overload,
3294 boolean use_tmsi
3295}
3296
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003297private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003298 integer num_paging_sent,
3299 integer num_paging_rcv_msgs,
3300 integer num_paging_rcv_ids,
3301 integer num_overload
3302}
3303
Harald Welte68e495b2018-02-25 00:05:57 +01003304/* Helper function for paging related testing */
3305private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003306 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003307 f_init_l1ctl();
3308 f_l1_tune(L1CTL);
3309
3310 var PagingTestState st := {
3311 num_paging_sent := 0,
3312 num_paging_rcv_msgs := 0,
3313 num_paging_rcv_ids := 0,
3314 num_overload := 0
3315 };
3316
3317 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3318 var float max_pch_imsi_per_sec;
3319 if (cfg.use_tmsi) {
3320 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3321 } else {
3322 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3323 }
3324 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3325 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003326 var float time_total := 20.0;
3327 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3328 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003329
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003330 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3331 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003332
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003333 timer T_itv := 0.0;
3334 T_itv.start;
3335 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003336 alt {
3337 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003338 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003339 st.num_overload := st.num_overload + 1;
3340 repeat;
3341 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003342 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003344 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003345 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003346 log("Rx LOAD_IND");
3347 /* FIXME: analyze/verify interval + contents */
3348 repeat;
3349 }
3350 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003351 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003352 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003353 [] T_itv.timeout {
3354 /* Send paging cmds based on elapsed time */
3355 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3356 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003357 var MobileIdentityV mi;
3358
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003359 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003360 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003361 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003362 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003363 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003364 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003365
3366 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003367 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 +02003368
3369 st.num_paging_sent := st.num_paging_sent + 1;
3370 }
3371 if (st.num_paging_sent < pkt_total) {
3372 /* Wait for interval to next PAGING COMMAND */
3373 var float time_now := T_total.read;
3374 var float next_sched := int2float(st.num_paging_sent)*interval;
3375 if (next_sched > time_now) {
3376 T_itv.start(next_sched - time_now);
3377 } else {
3378 T_itv.start(0.0);
3379 }
3380 } else {
3381 /* We are done, no need to keep counting */
3382 T_total.stop;
3383 }
3384 }
3385 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003386 }
3387 }
3388
3389 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3390 timer T_wait := 18.0;
3391 T_wait.start;
3392 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003393 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003394 [] L1CTL.receive { repeat; }
3395 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003396 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3397 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003398 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003400 }
Harald Welte68e495b2018-02-25 00:05:57 +01003401 }
3402
3403 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3404 " rcvd_ids=", st.num_paging_rcv_ids);
3405 return st;
3406}
3407
3408/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3409 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3410 * - that CCCH LOAD IND (PCH) are being generated
3411 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3412testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003413 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003414 var PagingTestCfg cfg := {
3415 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003416 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003417 load_factor := 0.8,
3418 exp_load_ind := true,
3419 exp_overload := false,
3420 use_tmsi := false
3421 };
3422 var PagingTestState st := f_TC_paging(cfg);
3423 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3425 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003426 } else {
3427 setverdict(pass);
3428 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003430}
3431
3432/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3433 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3434 * - that CCCH LOAD IND (PCH) are being generated
3435 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3436testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003437 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003438 var PagingTestCfg cfg := {
3439 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003440 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003441 load_factor := 0.8,
3442 exp_load_ind := true,
3443 exp_overload := false,
3444 use_tmsi := true
3445 };
3446 var PagingTestState st := f_TC_paging(cfg);
3447 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3449 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003450 } else {
3451 setverdict(pass);
3452 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003454}
3455
3456/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3457 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3458 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3459 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3460testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003461 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003462 var PagingTestCfg cfg := {
3463 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003464 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003465 load_factor := 2.0,
3466 exp_load_ind := true,
3467 exp_overload := true,
3468 use_tmsi := false
3469 };
3470 var PagingTestState st := f_TC_paging(cfg);
3471 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3472 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003473 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003474 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003475 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 +01003476 } else {
3477 setverdict(pass);
3478 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003480}
3481
3482/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3483 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3484 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3485 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3486testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003487 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003488 var PagingTestCfg cfg := {
3489 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003490 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003491 load_factor := 2.0,
3492 exp_load_ind := true,
3493 exp_overload := true,
3494 use_tmsi := true
3495 };
3496 var PagingTestState st := f_TC_paging(cfg);
3497 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3498 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003499 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003500 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003501 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 +01003502 } else {
3503 setverdict(pass);
3504 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003506}
3507
3508
Harald Welte93640c62018-02-25 16:59:33 +01003509/***********************************************************************
3510 * Immediate Assignment / AGCH
3511 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003512private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003513 len := 0,
3514 ma := ''B
3515}
Harald Welte93640c62018-02-25 16:59:33 +01003516
Harald Weltee8d750e2018-06-10 21:41:35 +02003517private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3518 return int2str(num_tx) & " sent, "
3519 & int2str(num_rx) & " received, "
3520 & int2str(num_del) & " deleted";
3521}
3522
3523private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3524 var L1ctlDlMessage l1_dl;
3525 timer T := 10.0;
3526 var integer num_tx := 0;
3527 var integer num_rx := 0;
3528 var integer num_del := 0;
3529 var charstring res_str;
3530 var float rx_ratio;
3531
Harald Welte10474062019-05-30 16:48:17 +02003532 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003533 f_init_l1ctl();
3534 f_l1_tune(L1CTL);
3535
3536 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003537 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003538 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3539 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003540 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003541 num_tx := num_tx+1;
3542 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003543 }
3544 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003545 T.start;
3546 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003547 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003548 num_del := num_del+1;
3549 repeat;
3550 }
3551 [] RSL_CCHAN.receive {
3552 repeat;
3553 }
3554 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003555 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3556 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3557 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003558 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003559 } else {
3560 num_rx := num_rx+1;
3561 }
3562 repeat;
3563 }
3564 [] L1CTL.receive { repeat; }
3565 [] T.timeout { }
3566 }
3567 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3568 log("AGCH test: " & res_str);
3569 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003571 }
3572 rx_ratio := int2float(num_rx) / int2float(num_tx);
3573 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003574 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 +02003575 } else {
3576 setverdict(pass);
3577 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003579}
3580
Harald Weltee8d750e2018-06-10 21:41:35 +02003581/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3582testcase TC_imm_ass_1000_20ms() runs on test_CT {
3583 f_TC_imm_ass(1000, 0.02, 0.25);
3584}
3585
3586/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3587testcase TC_imm_ass_200_0ms() runs on test_CT {
3588 f_TC_imm_ass(200, 0.0, 0.05);
3589}
3590
3591/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3592testcase TC_imm_ass_200_76ms() runs on test_CT {
3593 f_TC_imm_ass(150, 0.076, 1.00);
3594}
3595
3596
3597
Harald Welte48494ca2018-02-25 16:59:50 +01003598/***********************************************************************
3599 * BCCH
3600 ***********************************************************************/
3601
3602/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003603private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003604 GsmFrameNumber frame_number,
3605 SystemInformation si
3606}
3607
3608/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003609private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003610
3611/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003612private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003613
3614/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003615private function f_si_vecslot_contains(SystemInformationVector arr,
3616 RrMessageType key,
3617 boolean bcch_ext := false)
3618return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003619 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3620 var integer fn_mod51 := arr[i].frame_number mod 51;
3621 if (not bcch_ext and fn_mod51 == 2 or
3622 bcch_ext and fn_mod51 == 6) {
3623 if (arr[i].si.header.message_type == key) {
3624 return true;
3625 }
3626 }
3627 }
3628 return false;
3629}
3630
3631/* 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 +07003632private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3633 integer tc, RrMessageType key,
3634 boolean ext_bcch := false)
3635{
Harald Welte48494ca2018-02-25 16:59:50 +01003636 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003638 }
3639}
3640
3641/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003642private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3643 RrMessageType key)
3644return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003645 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3646 if (f_si_vecslot_contains(arr[tc], key) or
3647 f_si_vecslot_contains(arr[tc], key, true)) {
3648 return true;
3649 }
3650 }
3651 return false;
3652}
3653
3654/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003655private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3656 RrMessageType key,
3657 boolean bcch_ext := false,
3658 integer n := 1, integer m := 4)
3659return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003660 var integer count := 0;
3661 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003663 }
3664 for (var integer i:= 0; i < m; i := i + 1) {
3665 var integer fn_mod51 := arr[i].frame_number mod 51;
3666 if (not bcch_ext and fn_mod51 == 2 or
3667 bcch_ext and fn_mod51 == 6) {
3668 if (arr[i].si.header.message_type == key) {
3669 count := count + 1;
3670 }
3671 }
3672 }
3673 if (count >= n) {
3674 return true;
3675 } else {
3676 return false;
3677 }
3678}
3679
3680/* 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 +07003681private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3682 integer tc, RrMessageType key,
3683 boolean ext_bcch := false,
3684 integer n, integer m)
3685{
Harald Welte48494ca2018-02-25 16:59:50 +01003686 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003688 }
3689}
3690
3691/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003692private function f_si_vecslot_contains_only(SystemInformationVector arr,
3693 RrMessageType key,
3694 boolean bcch_ext := false)
3695return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003696 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3697 var integer fn_mod51 := arr[i].frame_number mod 51;
3698 if (not bcch_ext and fn_mod51 == 2 or
3699 bcch_ext and fn_mod51 == 6) {
3700 if (arr[i].si.header.message_type != key) {
3701 return false;
3702 }
3703 }
3704 }
3705 return true;
3706}
3707
3708/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003709private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3710 integer tc, RrMessageType key,
3711 boolean ext_bcch := false)
3712{
Harald Welte48494ca2018-02-25 16:59:50 +01003713 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003715 }
3716}
3717
3718/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003719private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003720 boolean bcch_extended,
3721 boolean si1_present,
3722 boolean si2bis_present,
3723 boolean si2ter_present,
3724 boolean si2quater_present,
3725 boolean si7_present,
3726 boolean si8_present,
3727 boolean si9_present,
3728 boolean si13_present,
3729 boolean si13alt_present,
3730 boolean si15_present,
3731 boolean si16_present,
3732 boolean si17_present,
3733 boolean si2n_present,
3734 boolean si21_present,
3735 boolean si22_present
3736}
3737
3738/* 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 +07003739private function f_validate_si_scheduling(SystemInformationConfig cfg,
3740 SystemInformationVectorPerTc si_per_tc)
3741{
Harald Welte48494ca2018-02-25 16:59:50 +01003742 var integer i;
3743 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3744 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003746 }
3747 }
3748 if (cfg.si1_present) {
3749 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3750 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3751 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3752 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3753 /* make sure *ALL* contain SI1 */
3754 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3755 }
3756 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3757 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3758 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3759 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3760 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3761 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3762
3763 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3764 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3765 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3766 * consecutive occurrences of TC = 4. */
3767 if (cfg.si2bis_present and not cfg.si2ter_present) {
3768 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3769 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3770 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3771 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3772 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3773 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3774 }
3775
3776 if (cfg.si7_present or cfg.si8_present) {
3777 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3778 * if System Information type 4 does not contain all information needed for cell
3779 * selection and reselection. */
3780 if (not cfg.bcch_extended) {
3781 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3782 }
3783 if (cfg.si7_present) {
3784 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3785 }
3786 if (cfg.si8_present) {
3787 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3788 }
3789 }
3790
3791 if (cfg.si2quater_present) {
3792 /* iii) System information type 2 quater is sent if needed, as determined by the system
3793 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3794 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3795 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3796 * within any of 4 consecutive occurrences of TC = 5. */
3797 if (not (cfg.bcch_extended)) {
3798 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3799 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3800 } else {
3801 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3802 }
3803 } else {
3804 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3805 }
3806 }
3807 if (cfg.si9_present) {
3808 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3809 * in system information type 3 as defined in 3GPP TS 44.018. */
3810 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3811 }
3812 if (cfg.si13_present) {
3813 /* vii) System Information type 13 is only related to the GPRS service. System Information
3814 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3815 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3816 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3817 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3818 * within any of 4 consecutive occurrences of TC=4. */
3819 if (not cfg.bcch_extended) {
3820 log("not-bccch-extended");
3821 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3822 } else {
3823 log("bccch-extended");
3824 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3825 }
3826 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003828 }
3829 }
3830 if (cfg.si16_present or cfg.si17_present) {
3831 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3832 * should not be sent in a cell where network sharing is used (see rule xv). */
3833 if (cfg.si22_present) {
3834 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3835 }
3836 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003838 }
3839 if (not cfg.bcch_extended) {
3840 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3841 }
3842 if (cfg.si16_present) {
3843 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3844 }
3845 if (cfg.si17_present) {
3846 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3847 }
3848 }
3849
3850 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3851 * broadcast information. The frequency with which they are sent is determined by the
3852 * system operator. System Information type 9 identifies the scheduling of System
3853 * Information type 18 and 20 messages. */
3854
3855 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3856 * Information Type 19 is present, then its scheduling shall be indicated in System
3857 * Information Type 9. */
3858
3859 if (cfg.si15_present) {
3860 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3861 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3862 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3863 * 4 consecutive occurrences of TC = 1. */
3864 if (not cfg.bcch_extended) {
3865 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3866 } else {
3867 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3868 }
3869 }
3870 if (cfg.si13alt_present) {
3871 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3872 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3873 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3874 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3875 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3876 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3877 * of TC = 4. */
3878 if (cfg.si13_present) {
3879 testcase.stop("Error: Cannot have SI13alt and SI13");
3880 }
3881 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003883 }
3884 if (not cfg.bcch_extended) {
3885 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3886 } else {
3887 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3888 }
3889 }
3890 if (cfg.si2n_present) {
3891 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3892 * as determined by the system operator. In the case that the message is sent on the
3893 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3894 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3895 * consecutive occurrences of TC = 4. */
3896 if (not cfg.bcch_extended) {
3897 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3898 } else {
3899 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3900 }
3901 }
3902 if (cfg.si21_present) {
3903 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3904 * determined by the system operator. If Extended Access Barring is in use in the cell
3905 * then this message is sent at least once within any of 4 consecutive occurrences of
3906 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3907 * cell then this message shall only be sent on BCCH Ext. */
3908 if (not cfg.bcch_extended) {
3909 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3910 } else {
3911 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3912 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003914 }
3915 }
3916 }
3917 if (cfg.si22_present) {
3918 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3919 * should not be sent in a cell where SoLSA is used (see rule viii). System
3920 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3921 * =2 and TC=6. */
3922 if (cfg.si16_present or cfg.si17_present) {
3923 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3924 }
3925 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3926 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003928 }
3929 if (not cfg.bcch_extended) {
3930 testcase.stop("Error: SI22 requires BCCH Extd!");
3931 } else {
3932 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3933 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3934 }
3935 }
3936}
3937
3938/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003939private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3940return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003941 timer T := duration;
3942 var SystemInformationVectorPerTc si_per_tc;
3943 var L1ctlDlMessage l1_dl;
3944
3945 /* initialize all per-TC vectors empty */
3946 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3947 si_per_tc[i] := {};
3948 }
3949
3950 /* flush all previous L1 queued msgs */
3951 pt.clear;
3952
3953 T.start;
3954 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003955 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003956 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3957 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3958 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003959 repeat;
3960 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003961
Harald Welte48494ca2018-02-25 16:59:50 +01003962 var integer tc := f_gsm_compute_tc(sig.frame_number);
3963 log("SI received at TC=", tc, ": ", sig.si);
3964 /* append to the per-TC bucket */
3965 si_per_tc[tc] := si_per_tc[tc] & { sig };
3966 repeat;
3967 }
3968 [] pt.receive { repeat; }
3969 [] T.timeout { }
3970 }
3971
3972 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3973 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3974 }
3975 log("si_per_tc=", si_per_tc);
3976 return si_per_tc;
3977}
3978
3979/* helper function: Set given SI via RSL + validate scheduling.
3980 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003981private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003982 var SystemInformationVectorPerTc si_per_tc;
3983 f_init_l1ctl();
3984 f_l1_tune(L1CTL);
3985
3986 /* Sample + Validate Scheduling */
3987 si_per_tc := f_l1_sample_si(L1CTL);
3988 f_validate_si_scheduling(si_cfg, si_per_tc);
3989
3990 setverdict(pass);
3991}
3992
3993testcase TC_si_sched_default() runs on test_CT {
3994 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003995 /* 2+3+4 are mandatory and set in f_init() */
3996 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003998}
3999
4000testcase TC_si_sched_1() runs on test_CT {
4001 f_init();
4002 si_cfg.si1_present := true;
4003 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004004 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004006}
4007
4008testcase TC_si_sched_2bis() runs on test_CT {
4009 f_init();
4010 si_cfg.si2bis_present := true;
4011 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4012 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004014}
4015
4016testcase TC_si_sched_2ter() runs on test_CT {
4017 f_init();
4018 si_cfg.si2ter_present := true;
4019 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4020 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004022}
4023
4024testcase TC_si_sched_2ter_2bis() runs on test_CT {
4025 f_init();
4026 si_cfg.si2bis_present := true;
4027 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4028 si_cfg.si2ter_present := true;
4029 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4030 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004032}
4033
4034testcase TC_si_sched_2quater() runs on test_CT {
4035 f_init();
4036 si_cfg.si2quater_present := true;
4037 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4038 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004040}
4041
4042testcase TC_si_sched_13() runs on test_CT {
4043 f_init();
4044 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004045 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004046 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004048}
4049
4050testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4051 f_init();
4052 si_cfg.si2bis_present := true;
4053 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4054 si_cfg.si2ter_present := true;
4055 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4056 si_cfg.si2quater_present := true;
4057 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4058 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004059 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004060 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004062}
4063
4064
Harald Welte68e495b2018-02-25 00:05:57 +01004065testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004066 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004067 /* FIXME: enable / disable individual BCCH info */
4068 //ts_RSL_BCCH_INFO(si_type, info);
4069 /* expect no ERROR REPORT after either of them *
4070 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004072}
4073
Harald Welte93640c62018-02-25 16:59:33 +01004074/***********************************************************************
4075 * Low-Level Protocol Errors / ERROR REPORT
4076 ***********************************************************************/
4077
Harald Welte01d982c2018-02-25 01:31:40 +01004078private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4079 timer T := 5.0;
4080 T.start;
4081 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004082 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004083 setverdict(pass);
4084 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004085 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004087 }
4088 [] RSL_CCHAN.receive {
4089 repeat;
4090 }
4091 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004093 }
4094 }
4095}
4096
4097/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4098testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004099 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004100 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4101 rsl.ies := omit;
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_PROTO);
4105}
4106
4107/* Provoke a mandatory IE error and match on ERROR REPORT */
4108testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004109 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004110
4111 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4112 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004113 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004114
4115 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4116}
4117
4118/* Provoke an IE content error and match on ERROR REPORT */
4119testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004120 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004121 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4122 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004123 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004124
4125 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4126}
4127
Harald Welteee25aae2019-05-19 14:32:37 +02004128/* attempt to activate channel with wrong RSL Message Discriminator IE */
4129function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4130 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4131 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4132 RSL.send(rsl);
4133 f_rslem_unregister(0, g_chan_nr);
4134}
4135testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4136 var ConnHdlr vc_conn;
4137 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4138
Harald Welte10474062019-05-30 16:48:17 +02004139 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004140
4141 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4142 vc_conn.done;
4143 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4144
4145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4146}
4147
4148/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004149private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004150 var template (value) RSL_Message rsl_tx;
4151 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4152 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4153 RSL.send(rsl_tx);
4154 f_rslem_unregister(0, g_chan_nr);
4155}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004156private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004157 var template (value) RSL_Message rsl_tx;
4158 /* we first have to activate the dedicated channel */
4159 f_rsl_chan_act(g_pars.chan_mode);
4160 /* ... to then send an invalid RLL message */
4161 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4162 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4163 RSL.send(rsl_tx);
4164 f_rslem_unregister(0, g_chan_nr);
4165}
4166testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4167 var ConnHdlr vc_conn;
4168 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4169 var template (value) RSL_Message rsl_tx;
4170
Harald Welte10474062019-05-30 16:48:17 +02004171 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004172
4173 /* Common Channel with wrong message type */
4174 RSL_CCHAN.clear;
4175 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4176 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004177 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004178 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4179
4180 /* TRX Management */
4181 RSL_CCHAN.clear;
4182 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4183 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004184 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004185 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4186
4187 /* Dedicated Channel */
4188 RSL_CCHAN.clear;
4189 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4190 vc_conn.done;
4191 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4192
4193 /* RLL */
4194 RSL_CCHAN.clear;
4195 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4196 vc_conn.done;
4197 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4198}
4199
4200/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004201private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004202 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4203 f_rslem_unregister(0, g_chan_nr);
4204}
4205testcase TC_err_rep_wrong_sequence() runs on test_CT {
4206 var ConnHdlr vc_conn;
4207 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4208
Harald Welte10474062019-05-30 16:48:17 +02004209 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004210
4211 RSL_CCHAN.clear;
4212 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4213 vc_conn.done;
4214 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4215}
4216
Harald Welte93640c62018-02-25 16:59:33 +01004217/***********************************************************************
4218 * IPA CRCX/MDCX/DLCS media stream handling
4219 ***********************************************************************/
4220
Harald Weltea871a382018-02-25 02:03:14 +01004221/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004222private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004223 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4224 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004225}
4226testcase TC_ipa_dlcx_not_active() runs on test_CT {
4227 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004228 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004229 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4230 vc_conn.done;
4231}
Harald Welte68e495b2018-02-25 00:05:57 +01004232
Harald Weltea3f1df92018-02-25 12:49:55 +01004233/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004234private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004235 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4236 "IPA CRCX ACK");
4237 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4238 "IPA CRCX NACK");
4239}
4240testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4241 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004242 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004243 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4244 vc_conn.done;
4245}
4246
4247/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004248private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004249 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4250 "IPA CRCX ACK");
4251 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4252 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4253 var uint7_t rtp_pt2 := f_rnd_int(127);
4254 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4255 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4256 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4257 "IPA MDCX ACK");
4258 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4259 "IPA DLCX ACK");
4260}
4261testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4262 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004263 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004264 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4265 vc_conn.done;
4266}
4267
Harald Welte3ae11da2018-02-25 13:36:06 +01004268/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004269private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004270 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4271 "IPA CRCX ACK");
4272 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4273 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4274 var uint7_t rtp_pt2 := f_rnd_int(127);
4275 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4276 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4277 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4278 "IPA MDCX ACK");
4279 /* Second MDCX */
4280 remote_ip := f_rnd_int(c_UINT32_MAX);
4281 remote_port := f_rnd_int(c_UINT16_MAX);
4282 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4283 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4284 "IPA MDCX ACK");
4285 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4286 "IPA DLCX ACK");
4287}
4288testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4289 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004290 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004291 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4292 vc_conn.done;
4293}
4294
Harald Welte9912eb52018-02-25 13:30:15 +01004295/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004296private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004297 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4298 "IPA CRCX NACK");
4299}
4300testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4301 var ConnHdlrPars pars;
4302 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004303 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004304
4305 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4306 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4307 vc_conn.done;
4308
4309 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4310 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4311 vc_conn.done;
4312}
4313
Harald Weltea3f1df92018-02-25 12:49:55 +01004314
Harald Welte883340c2018-02-28 18:59:29 +01004315/***********************************************************************
4316 * PCU Socket related tests
4317 ***********************************************************************/
4318
Harald Welte07bd2d22019-05-25 11:03:30 +02004319/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004320friend 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 +01004321runs on test_CT {
4322 timer T := 3.0;
4323
4324 /* we don't expect any RTS.req before PDCH are active */
4325 T.start;
4326 alt {
4327 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004329 }
4330 [] PCU.receive { repeat; }
4331 [] T.timeout { }
4332 }
4333
4334 /* Send PDCH activate request for known PDCH timeslot */
4335 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4336
4337 /* we now expect RTS.req for this timeslot (only) */
4338 T.start;
4339 alt {
4340 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4341 setverdict(pass);
4342 }
4343 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4344 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004346 }
4347 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004349 }
4350 [] PCU.receive { repeat; }
4351 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004353 }
4354 [not exp_success] T.timeout {
4355 setverdict(pass);
4356 }
4357 }
4358}
4359
Harald Welte07bd2d22019-05-25 11:03:30 +02004360/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004361friend 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 +01004362runs on test_CT {
4363 timer T := 3.0;
4364
4365 /* Send PDCH activate request for known PDCH timeslot */
4366 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4367
4368 PCU.clear;
4369 /* we now expect no RTS.req for this timeslot */
4370 T.start;
4371 alt {
4372 [] 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 +02004373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004374 }
4375 [] PCU.receive { repeat; }
4376 [] T.timeout {
4377 setverdict(pass);
4378 }
4379 }
4380}
4381
Harald Weltead033dc2019-05-25 17:28:16 +02004382friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004383 f_init();
4384 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4385}
4386
Harald Welte883340c2018-02-28 18:59:29 +01004387/* PDCH activation via PCU socket; check for presence of RTS.req */
4388testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004389 f_init_pcu_test();
4390
Harald Welte883340c2018-02-28 18:59:29 +01004391 f_TC_pcu_act_req(0, 0, 7, true);
4392}
4393
4394/* PDCH activation via PCU socket on non-PDCU timeslot */
4395testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004396 f_init_pcu_test();
4397
Harald Welte883340c2018-02-28 18:59:29 +01004398 f_TC_pcu_act_req(0, 0, 1, false);
4399}
4400
4401/* PDCH activation via PCU socket on wrong BTS */
4402testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004403 f_init_pcu_test();
4404
Harald Welte883340c2018-02-28 18:59:29 +01004405 f_TC_pcu_act_req(23, 0, 7, false);
4406}
4407
4408/* PDCH activation via PCU socket on wrong TRX */
4409testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004410 f_init_pcu_test();
4411
Harald Welte883340c2018-02-28 18:59:29 +01004412 f_TC_pcu_act_req(0, 23, 7, false);
4413}
4414
4415/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4416testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004417 f_init_pcu_test();
4418
Harald Welte883340c2018-02-28 18:59:29 +01004419 /* Activate PDCH */
4420 f_TC_pcu_act_req(0, 0, 7, true);
4421 f_sleep(1.0);
4422 /* and De-Activate again */
4423 f_TC_pcu_deact_req(0, 0, 7);
4424}
4425
4426/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4427testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004428 f_init_pcu_test();
4429
Harald Welte883340c2018-02-28 18:59:29 +01004430 f_TC_pcu_deact_req(0, 0, 1);
4431}
4432
4433/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4434testcase TC_pcu_ver_si13() runs on test_CT {
4435 const octetstring si13 := '00010203040506070909'O;
4436 var PCUIF_send_data sd;
4437 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004438 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004439
4440 /* Set SI13 via RSL */
4441 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004442
Harald Welte883340c2018-02-28 18:59:29 +01004443 T.start;
4444 alt {
4445 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4446 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4447 setverdict(pass);
4448 } else {
4449 repeat;
4450 }
4451 }
4452 [] PCU.receive { repeat; }
4453 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004455 }
4456 }
4457}
4458
4459private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4460
4461/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004462friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004463 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4464runs on test_CT
4465{
4466 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4467 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4468}
4469
4470/* 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 +02004471friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4472 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004473runs on test_CT
4474{
4475 var PCUIF_send_data sd;
4476
4477 timer T := 3.0;
4478 T.start;
4479 alt {
4480 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4481 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4482 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4483 sd.data.u.rts_req.fn, sapi, data);
4484 }
4485 [] PCU.receive { repeat; }
4486 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004488 }
4489 }
4490}
4491
4492/* Send DATA.req on invalid BTS */
4493testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004494 var TfiUsfArr tua := f_TfiUsfArrInit();
4495 var octetstring data := '0000'O & f_rnd_octstring(21);
4496
4497 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004498
Harald Welte883340c2018-02-28 18:59:29 +01004499 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004500 f_TfiUsfArrSet(tua, 7, 0);
4501 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4502 f_sleep(1.0);
4503
4504 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004505}
4506
4507/* Send DATA.req on invalid TRX */
4508testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004509 var TfiUsfArr tua := f_TfiUsfArrInit();
4510 var octetstring data := '0000'O & f_rnd_octstring(21);
4511
4512 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004513
Harald Welte883340c2018-02-28 18:59:29 +01004514 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004515 f_TfiUsfArrSet(tua, 7, 0);
4516 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4517 f_sleep(1.0);
4518
4519 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004520}
4521
4522/* Send DATA.req on invalid timeslot */
4523testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004524 var TfiUsfArr tua := f_TfiUsfArrInit();
4525 var octetstring data := '0000'O & f_rnd_octstring(21);
4526
4527 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004528
Harald Welte883340c2018-02-28 18:59:29 +01004529 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004530 f_TfiUsfArrSet(tua, 7, 0);
4531 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4532 f_sleep(1.0);
4533
4534 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004535}
4536
4537/* Send DATA.req on timeslot that hasn't been activated */
4538testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004539 var TfiUsfArr tua := f_TfiUsfArrInit();
4540 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004541
Harald Welte7162a612019-05-26 12:56:09 +02004542 f_virtphy_common();
4543
4544 f_TfiUsfArrSet(tua, 7, 0);
4545 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4546 f_sleep(1.0);
4547
4548 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004549}
4550
Harald Weltead033dc2019-05-25 17:28:16 +02004551private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004552 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4553 boolean wait_rts := true)
4554runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004555 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004556 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004557
4558 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004559 if (wait_rts) {
4560 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4561 } else {
4562 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4563 }
Harald Weltead033dc2019-05-25 17:28:16 +02004564
4565 T.start;
4566 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004567 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004568 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4569 setverdict(pass);
4570 }
Harald Welte7162a612019-05-26 12:56:09 +02004571 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4572 setverdict(fail, "Received unexpected ", rx_dl);
4573 }
Harald Weltead033dc2019-05-25 17:28:16 +02004574 [] L1CTL.receive {
4575 repeat;
4576 }
Harald Welte7162a612019-05-26 12:56:09 +02004577 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004578 setverdict(fail, "Timeout waiting for ", data);
4579 }
Harald Welte7162a612019-05-26 12:56:09 +02004580 [not expect_data] T.timeout {
4581 setverdict(pass);
4582 }
Harald Weltead033dc2019-05-25 17:28:16 +02004583 }
4584}
4585
4586private function f_disable_dynamic_ts() runs on test_CT
4587{
4588 f_init_vty_bsc();
4589 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4590 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4591 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4592 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004593 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004594}
4595
4596private function f_virtphy_common() runs on test_CT {
4597 f_disable_dynamic_ts();
4598 f_init_l1ctl();
4599 f_l1_tune(L1CTL);
4600}
4601
4602testcase TC_pcu_data_req_pdtch() runs on test_CT {
4603 var TfiUsfArr tua := f_TfiUsfArrInit();
4604 var octetstring data := '0000'O & f_rnd_octstring(21);
4605
4606 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004607
Harald Welte883340c2018-02-28 18:59:29 +01004608 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004609 f_TfiUsfArrSet(tua, 7, 0);
4610 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4611 f_sleep(1.0);
4612
4613 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004614}
4615
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004616/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004617testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004618 var TfiUsfArr tua := f_TfiUsfArrInit();
4619 var octetstring data := '0000'O & f_rnd_octstring(21);
4620
4621 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004622
Harald Welte883340c2018-02-28 18:59:29 +01004623 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004624 f_TfiUsfArrSet(tua, 7, 0);
4625 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4626 f_sleep(1.0);
4627
4628 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004629}
4630
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004631private function f_TC_pcu_ptcch_ul(uint16_t ra)
4632runs on test_CT {
4633 var template PCUIF_Message pcu_rach_ind;
4634 var PCUIF_send_data sd;
4635 var GsmFrameNumber fn;
4636 timer T;
4637
4638 /* Send an Access Burst on PTCCH/U over the Um-interface */
4639 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4640 chan_nr := ts_RslChanNr_PDCH(7),
4641 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4642
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004643 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4644 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004645
4646 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4647 T.start(52.0 * 4.615 / 1000.0);
4648 alt {
4649 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4650 log("Rx an Access Burst on the PCU interface: ", sd.data);
4651 setverdict(pass);
4652 T.stop;
4653 }
4654 [] PCU.receive { repeat; }
4655 [] T.timeout {
4656 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4657 /* Keep going, that's not the end of the world */
4658 }
4659 }
4660}
4661
4662testcase TC_pcu_ptcch() runs on test_CT {
4663 var L1ctlDlMessage dl;
4664 var octetstring data;
4665 timer T;
4666
4667 f_init_pcu_test();
4668 f_init_l1ctl();
4669 f_l1_tune(L1CTL);
4670
4671 /* Activate PDCH channel on TS7 */
4672 f_TC_pcu_act_req(0, 0, 7, true);
4673
4674 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004675 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004676 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004677 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004678 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004679
4680 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4681 for (var integer i := 0; i < 16; i := i + 1) {
4682 log("Sending an Access Burst towards the L1CTL interface");
4683 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4684 }
4685
4686 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4687 data := f_rnd_octstring(23);
4688
4689 /* Verify PTCCH/D: send a random data block, make sure it's received */
4690 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4691 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4692
4693 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4694 * let's give it more time in case if we miss the beginning. */
4695 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4696 alt {
4697 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4698 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4699 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4700 frame := data)) -> value dl {
4701 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4702 setverdict(pass);
4703 T.stop;
4704 }
4705 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4706 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4707 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4708 l2_data := data)) -> value dl {
4709 log("Rx PTCCH/D data block on L1CTL: ", dl);
4710 setverdict(pass);
4711 T.stop;
4712 }
4713 [] L1CTL.receive { repeat; }
4714 [] T.timeout {
4715 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4716 }
4717 }
4718}
4719
Harald Welte883340c2018-02-28 18:59:29 +01004720/* Send AGCH from PCU; check it appears on Um side */
4721testcase TC_pcu_data_req_agch() runs on test_CT {
4722 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004723 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004724 f_init_l1ctl();
4725 f_l1_tune(L1CTL);
4726
4727 f_TC_pcu_act_req(0, 0, 7, true);
4728 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4729
4730 T.start;
4731 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004732 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004733 setverdict(pass);
4734 }
4735 [] L1CTL.receive { repeat; }
4736 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004738 }
4739 }
4740}
4741
Harald Welte928622b2019-05-26 13:22:59 +02004742/* Send AGCH from PCU; check it appears on Um side */
4743testcase TC_pcu_data_req_pch() runs on test_CT {
4744 timer T := 3.0;
4745 f_init_pcu_test();
4746 f_init_l1ctl();
4747 f_l1_tune(L1CTL);
4748
4749 f_TC_pcu_act_req(0, 0, 7, true);
4750 /* three characters prefix: last 3 digits of IMSI as ASCII */
4751 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4752
4753 T.start;
4754 alt {
4755 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4756 setverdict(pass);
4757 }
4758 [] L1CTL.receive { repeat; }
4759 [] T.timeout {
4760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4761 }
4762 }
4763}
4764
Harald Welte883340c2018-02-28 18:59:29 +01004765/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4766testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4767 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004768 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004769 f_init_l1ctl();
4770 f_l1_tune(L1CTL);
4771
4772 /* append 3 last imsi digits so BTS can compute pagng group */
4773 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4774
4775 timer T := 0.5;
4776 T.start;
4777 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004778 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004779 /* TODO: verify paging group */
4780 setverdict(pass);
4781 }
4782 [] L1CTL.receive { repeat; }
4783 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004785 }
4786 }
4787}
4788
4789/* Send RACH from Um side, expect it to show up on PCU socket */
4790testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004791 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004792 f_init_l1ctl();
4793 f_l1_tune(L1CTL);
4794
4795 var GsmFrameNumber fn_last := 0;
4796 for (var integer i := 0; i < 1000; i := i+1) {
4797 var OCT1 ra := f_rnd_ra_ps();
4798 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4799 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004801 }
4802 fn_last := fn;
4803
4804 timer T := 2.0;
4805 T.start;
4806 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004807 [] 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 +01004808 T.stop;
4809 }
4810 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004812 }
4813 [] PCU.receive { repeat; }
4814 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004816 }
4817 }
4818 }
4819 setverdict(pass);
4820}
4821
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004822/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4823 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4824testcase TC_pcu_ext_rach_content() runs on test_CT {
4825 var template PCUIF_Message pcu_rach_ind;
4826 var GsmFrameNumber fn_last := 0;
4827 var L1ctlRachSynchSeq synch_seq;
4828 var PCUIF_BurstType pcu_bt;
4829 var GsmFrameNumber fn;
4830 var BIT11 ra11;
4831
4832 f_init_pcu_test();
4833 f_init_l1ctl();
4834 f_l1_tune(L1CTL);
4835
4836 for (var integer i := 0; i < 1000; i := i+1) {
4837 /* We need to test both TS1 & TS2 */
4838 if (i rem 2 == 0) {
4839 synch_seq := RACH_SYNCH_SEQ_TS1;
4840 pcu_bt := BURST_TYPE_1;
4841 } else {
4842 synch_seq := RACH_SYNCH_SEQ_TS2;
4843 pcu_bt := BURST_TYPE_2;
4844 }
4845
4846 ra11 := f_rnd_ra11_ps();
4847 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4848 if (fn == fn_last) {
4849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4850 "Two RACH in same FN?!?");
4851 }
4852 fn_last := fn;
4853
4854 /* Compose the expected message */
4855 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004856 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004857 ra := bit2int(ra11),
4858 is_11bit := 1,
4859 burst_type := pcu_bt,
4860 fn := fn);
4861
4862 timer T := 2.0;
4863 T.start;
4864 alt {
4865 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4866 T.stop;
4867 }
4868 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4870 }
4871 [] PCU.receive { repeat; }
4872 [] T.timeout {
4873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4874 }
4875 }
4876 }
4877 setverdict(pass);
4878}
4879
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004880private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4881runs on test_CT {
4882 var template PCUIF_send_data sdt;
4883 var PCUIF_send_data sd;
4884 var int16_t lqual_cb;
4885 timer T := 1.0;
4886
4887 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4888 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4889
4890 /* Send a random PDTCH frame over Um */
4891 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4892 '0000'O & f_rnd_octstring(21)));
4893
4894 T.start;
4895 alt {
4896 /* If expected link quality is above the threshold */
4897 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4898 lqual_cb := sd.data.u.data_ind.lqual_cb;
4899 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4900
4901 /* Make sure the actual link quality matches the expected value */
4902 if (not match(lqual_cb, lqual_cb_exp)) {
4903 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4904 "expected value ", lqual_cb_exp));
4905 } else {
4906 setverdict(pass);
4907 }
4908 }
4909 /* If expected link quality is below the threshold */
4910 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4912 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4913 }
4914 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4915 [] PCU.receive { repeat; }
4916 [lqual_cb_exp < thresh] T.timeout {
4917 log("Rx nothing, as expected");
4918 setverdict(pass);
4919 }
4920 [lqual_cb_exp >= thresh] T.timeout {
4921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4922 "Timeout waiting for PCUIF_DATA.ind");
4923 }
4924 }
4925}
4926
4927/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4928testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4929 f_init_pcu_test();
4930 PCU.clear;
4931
4932 f_init_l1ctl();
4933 f_l1_tune(L1CTL);
4934
4935 /* Activate a PDCH channel on TS7 */
4936 f_TC_pcu_act_req(0, 0, 7, true);
4937
4938 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004939 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004940 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004941 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004942 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004943
4944 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4945 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4946 var TrxcMessage ret;
4947
4948 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4949 valueof(ts_TRXC_FAKE_CI(i)));
4950
4951 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4952 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4953 }
4954}
4955
Harald Welte883340c2018-02-28 18:59:29 +01004956/* Send PAGING via RSL, expect it to shw up on PCU socket */
4957testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004958 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004959
4960 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004961 var MobileIdentityLV mi_lv;
4962 var octetstring mi_lv_enc;
4963 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004964 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004965
Harald Welte883340c2018-02-28 18:59:29 +01004966 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004967 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004968 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004969 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004970 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004971
4972 /* Fancy encoding for PCUIF */
4973 mi_lv := valueof(ts_MI_LV(mi));
4974 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4975 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004976
4977 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004978 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004979 T.start;
4980 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004981 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004982 }
4983 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004985 }
4986 [] PCU.receive { repeat; }
4987 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004989 }
4990 }
4991 }
4992 setverdict(pass);
4993}
4994
Harald Welted66c9b82019-05-25 09:03:15 +02004995/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4996testcase TC_pcu_time_ind() runs on test_CT {
4997 var PCUIF_send_data pcu_sd;
4998 var integer num_time_ind := 0;
4999 var integer first_fn, last_fn;
5000 var float test_duration := 5.0;
5001 timer T;
5002
5003 f_init_pcu_test();
5004 f_TC_pcu_act_req(0, 0, 7, true);
5005
5006 PCU.clear;
5007 T.start(test_duration);
5008 alt {
5009 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5010 num_time_ind := num_time_ind + 1;
5011 if (not isbound(first_fn)) {
5012 first_fn := pcu_sd.data.u.time_ind.fn;
5013 }
5014 last_fn := pcu_sd.data.u.time_ind.fn;
5015 repeat;
5016 }
5017 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5018 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5019 repeat;
5020 }
5021 [] PCU.receive {
5022 repeat;
5023 }
5024 [] T.timeout {}
5025 }
5026 var integer fn_expired := last_fn - first_fn;
5027 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5028
5029 /* verify the number of frames expired matches our expectation */
5030 const float c_GSM_FN_DURATION_MS := 4.61538;
5031 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005032 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005033 if (not match(fn_expired, t_fn_expected)) {
5034 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5035 }
5036
5037 /* There are three TIME.ind in every fn MOD 13 */
5038 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5039 /* Add some tolerance */
5040 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5041 if (not match(num_time_ind, t_time_ind_exp)) {
5042 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5043 }
5044
5045 setverdict(pass);
5046}
5047
Harald Welte4832c862019-05-25 14:57:18 +02005048/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5049testcase TC_pcu_rts_req() runs on test_CT {
5050 var PCUIF_send_data pcu_sd;
5051 var integer first_fn, last_fn;
5052 var integer num_rts_pdtch := 0;
5053 var integer num_rts_ptcch := 0;
5054 var float test_duration := 5.0;
5055 timer T;
5056
5057 f_init_pcu_test();
5058 f_TC_pcu_act_req(0, 0, 7, true);
5059
5060 PCU.clear;
5061 T.start(test_duration);
5062 alt {
5063 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5064 -> value pcu_sd {
5065 num_rts_pdtch := num_rts_pdtch + 1;
5066 if (not isbound(first_fn)) {
5067 first_fn := pcu_sd.data.u.rts_req.fn;
5068 }
5069 last_fn := pcu_sd.data.u.rts_req.fn;
5070 repeat;
5071 }
5072 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5073 -> value pcu_sd {
5074 num_rts_ptcch := num_rts_ptcch + 1;
5075 if (not isbound(first_fn)) {
5076 first_fn := pcu_sd.data.u.rts_req.fn;
5077 }
5078 last_fn := pcu_sd.data.u.rts_req.fn;
5079 repeat;
5080 }
5081 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5082 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5083 repeat;
5084 }
5085 [] PCU.receive {
5086 repeat;
5087 }
5088 [] T.timeout {}
5089 }
5090 var integer fn_expired := last_fn - first_fn;
5091 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5092 ", num_rts_ptcch=", num_rts_ptcch);
5093
5094 /* verify the number of frames expired matches our expectation */
5095 const float c_GSM_FN_DURATION_MS := 4.61538;
5096 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005097 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005098 if (not match(fn_expired, t_fn_expected)) {
5099 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5100 }
5101
5102 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5103 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5104 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5105 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5106 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5107 t_ptcch_exp);
5108 }
5109
5110 /* We have 12 PDTCH blocks every 52-multiframe */
5111 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5112 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5113 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5114 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5115 t_pdtch_exp);
5116 }
5117
5118 setverdict(pass);
5119}
5120
Harald Welte07bd2d22019-05-25 11:03:30 +02005121/* test for generating Abis side OML ALERT from the PCU */
5122testcase TC_pcu_oml_alert() runs on test_CT {
5123 var PCUIF_send_data pcu_sd;
5124 var integer num_time_ind := 0;
5125 var integer first_fn, last_fn;
5126 var float test_duration := 5.0;
5127 timer T;
5128
5129 f_init_pcu_test();
5130 f_TC_pcu_act_req(0, 0, 7, true);
5131
5132 /* re-connect CTRL port from BTS to BSC */
5133 f_ipa_ctrl_stop();
5134 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5135
5136 /* Send that OML Alert */
5137 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5138
5139 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5140 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5141 setverdict(pass);
5142}
5143
Harald Welteeaa9a862019-05-26 23:01:08 +02005144/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5145private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5146 var PCUIF_Message first_info;
5147 var integer pcu_conn_id := -1;
5148 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5149 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5150 var OCT4 tlli := '01020304'O;
5151 var OCT1 cause := '23'O;
5152 timer T := 5.0;
5153
5154 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5155
5156 f_l1_tune(L1CTL);
5157 RSL.clear;
5158
5159 f_est_dchan();
5160 L1CTL.clear;
5161
5162 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5163
5164 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5165 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5166 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5167
5168 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5169 T.start;
5170 alt {
5171 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5172 setverdict(pass);
5173 }
5174 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5175 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5176 }
5177 [] PCU.receive {
5178 repeat;
5179 }
5180 [] T.timeout {
5181 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5182 }
5183 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005184
5185 /* release the channel */
5186 f_rsl_chan_deact();
5187 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5188 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005189}
5190testcase TC_pcu_rr_suspend() runs on test_CT {
5191 var ConnHdlrPars pars;
5192 var ConnHdlr vc_conn;
5193
5194 f_init();
5195
5196 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5197 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5198 vc_conn.done;
5199}
Harald Welte07bd2d22019-05-25 11:03:30 +02005200
Harald Weltea2e0e942019-05-27 18:12:53 +02005201/* Ensure that PCUIF socket can accept only a single connection */
5202testcase TC_pcu_socket_connect_multi() runs on test_CT {
5203 timer T := 5.0;
5204
5205 /* this (among other things) establishes the first connection to the PCUIF socket */
5206 f_init();
5207
5208 /* try to establish a second connection, expect it to fail */
5209 PCU.send(UD_connect:{mp_pcu_socket, -1});
5210 T.start;
5211 alt {
5212 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5213 setverdict(pass);
5214 }
5215 [] PCU.receive(UD_connect_result:?) {
5216 setverdict(fail, "Unexpected unix domain connect result");
5217 }
5218 [] T.timeout {
5219 setverdict(pass);
5220 }
5221 }
5222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5223}
5224
Harald Weltec8effb72019-05-27 18:23:04 +02005225/* Ensure that PCUIF socket can disconnect + reconnect */
5226testcase TC_pcu_socket_reconnect() runs on test_CT {
5227 /* this (among other things) establishes the first connection to the PCUIF socket */
5228 f_init();
5229
5230 f_sleep(1.0);
5231
5232 f_pcuif_close(PCU, g_pcu_conn_id);
5233 g_pcu_conn_id := -1;
5234
5235 f_sleep(1.0);
5236
5237 /* re-connect */
5238 PCU.clear;
5239 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5240 setverdict(pass);
5241
5242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5243}
5244
Harald Weltebe030482019-05-27 22:29:35 +02005245/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005246private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5247runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005248 var L1ctlDlMessage l1_dl;
5249 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005250 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005251 timer T := 5.0;
5252 T.start;
5253 alt {
5254 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005255 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5256 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005257 repeat;
5258 }
5259 }
5260 [] pt.receive {
5261 repeat;
5262 }
5263 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5265 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005266 }
5267 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005268 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005269}
5270
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005271/* Check if GPRS Indicator is present in RR System Information of a given type */
5272private function f_si_has_gprs_indicator(RrMessageType si_type)
5273runs on test_CT return boolean {
5274 var SystemInformation si := f_get_si(L1CTL, si_type);
5275
5276 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005277 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005278 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005279 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005280 }
5281
5282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5283 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005284}
5285
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005286/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5287private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5288runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005289 /* don't call f_init() as this would connect PCU socket */
5290 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005291
5292 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005293 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005294 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005295
5296 f_init_l1ctl();
5297 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005298 f_sleep(2.0);
5299 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005300
5301 if (f_si_has_gprs_indicator(si_type)) {
5302 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005303 } else {
5304 setverdict(pass);
5305 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005306
Harald Weltebe030482019-05-27 22:29:35 +02005307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5308}
5309
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005310testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5311 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5312}
Harald Weltebe030482019-05-27 22:29:35 +02005313
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005314testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5315 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5316}
5317
5318/* Ensure that GPRS capability is advertised after PCU socket connect */
5319private function f_TC_pcu_socket_connect(RrMessageType si_type)
5320runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005321 /* this (among other things) establishes the first connection to the PCUIF socket */
5322 f_init();
5323 f_init_l1ctl();
5324 f_l1_tune(L1CTL);
5325
5326 f_sleep(2.0);
5327 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005328
5329 if (not f_si_has_gprs_indicator(si_type)) {
5330 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005331 } else {
5332 setverdict(pass);
5333 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005334
Harald Weltebe030482019-05-27 22:29:35 +02005335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5336}
5337
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005338testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5339 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5340}
Harald Weltebe030482019-05-27 22:29:35 +02005341
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005342testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5343 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5344}
5345
5346/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5347private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5348runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005349 /* this (among other things) establishes the first connection to the PCUIF socket */
5350 f_init();
5351 f_init_l1ctl();
5352 f_l1_tune(L1CTL);
5353
5354 f_pcuif_close(PCU, g_pcu_conn_id);
5355 g_pcu_conn_id := -1;
5356
5357 f_sleep(1.0);
5358
5359 /* re-connect */
5360 PCU.clear;
5361 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5362
5363 f_sleep(2.0);
5364 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005365
5366 if (f_si_has_gprs_indicator(si_type)) {
5367 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005368 } else {
5369 setverdict(pass);
5370 }
5371
5372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5373}
5374
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005375testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5376 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5377}
5378
5379testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5380 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5381}
5382
Oliver Smithf5239c72019-08-28 10:01:25 +02005383/* 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) */
5384testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5385 var SystemInformation si3 := valueof(ts_SI3_default);
5386
5387 f_init();
5388
5389 /* Verify cell_id */
5390 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5391 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5392 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005393 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5394 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5395 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005396 }
5397
5398 /* Verify LAC */
5399 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5400 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5401 if (lac_si3 != lac_pcu) {
5402 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5403 }
5404
5405 setverdict(pass);
5406}
Harald Welted66c9b82019-05-25 09:03:15 +02005407
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005408/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5409testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5410 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005411 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005412
5413 f_init();
5414
5415 info_ind := g_pcu_last_info.u.info_ind;
5416
5417 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5418 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5419 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5420 /* Skip inactive timeslots */
5421 continue;
5422 }
5423
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005424 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005425 { f_resolve_fh_params(fhp, tn); }
5426 else
5427 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005428
5429 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005430 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005431 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005432 hsn := fhp.maio_hsn.hsn,
5433 maio := fhp.maio_hsn.maio,
5434 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
5435 ma_bit_len := lengthof(fhp.ma_map.ma));
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005436 } else {
5437 tr_ts := tr_PCUIF_InfoTrxTsH0;
5438 }
5439
5440 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5441 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5442 if (not match(ts, tr_ts)) {
5443 setverdict(fail, "Hopping parameters do not match: ",
5444 "received ", ts, " vs expected ", tr_ts);
5445 } else {
5446 setverdict(pass);
5447 }
5448 }
5449 }
5450}
5451
Alexander Couzens5283f552020-07-28 15:39:04 +02005452/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5453testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5454 f_init_vty_bsc();
5455 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5456 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5457
5458 f_init();
5459
5460 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5461 if (not ischosen(remote_addr.v10)) {
5462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5463 log2str("Unexpected remote_addr: ", remote_addr));
5464 }
5465
5466 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5467 setverdict(fail, "Received address family is not IPv4");
5468 }
5469
5470 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5471 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5472 }
5473
5474 setverdict(pass);
5475}
5476
5477/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5478testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5479 f_init_vty_bsc();
5480 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5481
5482 f_init();
5483
5484 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5485 if (not ischosen(remote_addr.v10)) {
5486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5487 log2str("Unexpected remote_addr: ", remote_addr));
5488 }
5489
5490 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5491 setverdict(fail, "Received address family is not IPv6");
5492 }
5493
5494 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5495 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5496 }
5497
5498 setverdict(pass);
5499}
5500
Harald Welte3d04ae62018-04-04 20:29:05 +02005501/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005502 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005503 ***********************************************************************/
5504
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005505private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5506 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005507runs on ConnHdlr {
5508 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005509
5510 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005511 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005512 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5513 repeat;
5514 }
5515 }
5516}
5517
5518private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5519runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005520 /* Expect BTS to immediately acknowledge activation as PDCH */
5521 PCU.clear;
5522 f_rsl_chan_act(g_pars.chan_mode);
5523 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005524 timer T_wait := 2.0;
5525 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005526 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005527 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005528 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005529 [] T_wait.timeout {
5530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5531 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5532 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005533 }
5534 /* try to activate this PDCH from the PCU point of view */
5535 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5536 /* FIXME: is there a response? */
5537}
5538
5539private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5540runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005541 /* Send RSL CHAN REL (deactivate) */
5542 PCU.clear;
5543 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5544 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005545 timer T_wait := 2.0;
5546 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005547 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005548 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005549 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005550 [] T_wait.timeout {
5551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5552 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5553 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005554 }
5555 /* Emulate PCU asking BTS to deactivate PDCH */
5556 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5557 alt {
5558 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5559 setverdict(pass);
5560 }
5561 [] RSL.receive { repeat; }
5562 }
5563}
5564
5565/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005566private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005567 var PCUIF_Message first_info;
5568 var integer ts_nr := g_chan_nr.tn;
5569 var integer trx_nr := 0;
5570 var integer bts_nr := 0;
5571 var integer pcu_conn_id := -1;
5572
5573 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5574
5575 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5576 f_sleep(3.0);
5577 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5578 setverdict(pass);
5579}
5580testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5581 var ConnHdlrPars pars;
5582 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005583 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005584
5585 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5586 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5587 vc_conn.done;
5588}
5589
5590/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005591private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005592 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005593 var integer pcu_conn_id := -1;
5594
5595 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5596
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005597 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5598 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5599 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005600 setverdict(pass);
5601}
5602testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5603 var ConnHdlrPars pars;
5604 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005605 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005606
5607 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5608 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5609 vc_conn.done;
5610}
5611
5612/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005613private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005614 var PCUIF_Message first_info;
5615 var integer ts_nr := g_chan_nr.tn;
5616 var integer trx_nr := 0;
5617 var integer bts_nr := 0;
5618 var integer pcu_conn_id := -1;
5619
5620 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5621
5622 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005623 /* Send a second Chan Activ and expect it to be NACKed */
5624 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5625 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005626 setverdict(pass);
5627}
5628testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5629 var ConnHdlrPars pars;
5630 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005631 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005632
5633 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5634 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5635 vc_conn.done;
5636}
5637
5638/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005639private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005640 var PCUIF_Message first_info;
5641 var integer ts_nr := g_chan_nr.tn;
5642 var integer trx_nr := 0;
5643 var integer bts_nr := 0;
5644 var integer pcu_conn_id := -1;
5645 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5646
5647 /* register for the TCH/F channel number */
5648 f_rslem_register(0, chan_nr);
5649
5650 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5651
5652 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5653 "RSL CHAN ACT");
5654 setverdict(pass);
5655}
5656testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5657 var ConnHdlrPars pars;
5658 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005659 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005660
5661 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5662 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5663 vc_conn.done;
5664}
5665
5666/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005667private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005668 var PCUIF_Message first_info;
5669 var integer ts_nr := g_chan_nr.tn;
5670 var integer trx_nr := 0;
5671 var integer bts_nr := 0;
5672 var integer pcu_conn_id := -1;
5673 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5674 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5675
5676 /* register for the TCH/H channel numbers */
5677 f_rslem_register(0, chan_nr[0]);
5678 f_rslem_register(0, chan_nr[1]);
5679
5680 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5681
5682 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5683 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5684 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5685 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5686 setverdict(pass);
5687}
5688testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5689 var ConnHdlrPars pars;
5690 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005691 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005692
5693 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5694 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5695 vc_conn.done;
5696}
5697
Harald Welte9bbbfb52018-04-05 09:33:19 +02005698/***********************************************************************
5699 * IPA Style Dynamic Timeslot Support
5700 ***********************************************************************/
5701
5702private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5703runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005704 /* Expect BTS to immediately acknowledge activation as PDCH */
5705 PCU.clear;
5706 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5707 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005708 timer T_wait := 2.0;
5709 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005710 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005711 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005712 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005713 [] T_wait.timeout {
5714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5715 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5716 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005717 }
5718 /* try to activate this PDCH from the PCU point of view */
5719 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5720 /* FIXME: is there a response? */
5721
5722 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5723}
5724
5725private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5726runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005727 /* Send RSL CHAN REL (deactivate) */
5728 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5729 PCU.clear;
5730 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005731 timer T_wait := 2.0;
5732 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005733 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005734 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005735 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005736 [] T_wait.timeout {
5737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5738 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5739 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005740 }
5741 /* Emulate PCU asking BTS to deactivate PDCH */
5742 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5743 alt {
5744 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5745 setverdict(pass);
5746 }
5747 [] RSL.receive { repeat; }
5748 }
5749}
5750
5751/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005752private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005753 var PCUIF_Message first_info;
5754 var integer ts_nr := g_chan_nr.tn;
5755 var integer trx_nr := 0;
5756 var integer bts_nr := 0;
5757 var integer pcu_conn_id := -1;
5758
5759 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5760
5761 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5762 f_sleep(3.0);
5763 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5764
5765 setverdict(pass);
5766
5767}
5768testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5769 var ConnHdlrPars pars;
5770 var ConnHdlr vc_conn;
5771 f_init();
5772
5773 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5774 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5775 vc_conn.done;
5776}
5777
5778/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005779private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005780 var PCUIF_Message first_info;
5781 var integer ts_nr := g_chan_nr.tn;
5782 var integer trx_nr := 0;
5783 var integer bts_nr := 0;
5784 var integer pcu_conn_id := -1;
5785
5786 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5787
5788 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5789 "RSL CHAN ACT");
5790 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5791 "RF CHAN REL", true);
5792 setverdict(pass);
5793}
5794testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5795 var ConnHdlrPars pars;
5796 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005797 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005798
5799 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5800 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5801 vc_conn.done;
5802}
5803
5804/* 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 +07005805private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005806 var PCUIF_Message first_info;
5807 var integer ts_nr := g_chan_nr.tn;
5808 var integer trx_nr := 0;
5809 var integer bts_nr := 0;
5810 var integer pcu_conn_id := -1;
5811
5812 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5813
5814 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5815 "RSL CHAN ACT");
5816
5817 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5818 alt {
5819 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5820 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005822 }
5823 [] RSL.receive { repeat; }
5824 }
5825
5826 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5827 "RF CHAN REL", true);
5828 setverdict(pass);
5829}
5830testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5831 var ConnHdlrPars pars;
5832 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005833 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005834
5835 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5836 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5837 vc_conn.done;
5838}
5839
5840/* 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 +07005841private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005842 var PCUIF_Message first_info;
5843 var integer ts_nr := g_chan_nr.tn;
5844 var integer trx_nr := 0;
5845 var integer bts_nr := 0;
5846 var integer pcu_conn_id := -1;
5847
5848 /* register for the TCH/F channel number */
5849 f_rslem_register(0, g_chan_nr);
5850
5851 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5852
5853 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5854
5855 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5856 "RSL CHAN ACT");
5857
5858 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5859
5860 setverdict(pass);
5861}
5862testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5863 var ConnHdlrPars pars;
5864 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005865 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005866
5867 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5868 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5869 vc_conn.done;
5870}
5871
5872
Harald Welte0472ab42018-03-12 15:02:26 +01005873/***********************************************************************
5874 * LAPDm / RLL related
5875 ***********************************************************************/
5876
5877private function f_tx_lapdm(template (value) LapdmFrame l,
5878 template (value) RslLinkId link_id) runs on ConnHdlr {
5879 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005880 var template (value) SacchL1Header l1h;
5881
5882 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005883 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005884 /* Compose dummy L1 header */
5885 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5886 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 +02005887 } else {
5888 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005889 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 +01005890 }
Harald Welte0472ab42018-03-12 15:02:26 +01005891}
5892
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005893private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005894 uint3_t sapi,
5895 RslLinkId link_id,
5896 octetstring l3,
5897 boolean exp
5898}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005899private type record of RllTestCase RllTestCases;
5900private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5901 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005902 sapi := sapi,
5903 link_id := id,
5904 l3 := l3,
5905 exp := exp
5906}
5907
5908/* execute the same callback function with a set of different parameters (tcs) on a
5909 * variety of logical channels */
5910private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5911 var ConnHdlrPars pars;
5912 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005913 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005914
5915 /* test on each of the channels we have */
5916 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5917 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5918
5919 /* test each of the test cases on the current channel */
5920 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5921 pars.spec.rll := tcs[j];
5922 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5923 vc_conn := f_start_handler(fn, pars);
5924 vc_conn.done;
5925 }
5926 }
5927
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005929}
5930
5931/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5932private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5933 var RllTestCase tc := g_pars.spec.rll;
5934 timer T := 3.0;
5935
5936 f_l1_tune(L1CTL);
5937 RSL.clear;
5938
5939 /* activate the logical channel */
5940 f_est_dchan();
5941 L1CTL.clear;
5942
5943 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5944 T.start;
5945 alt {
5946 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5947 if (tc.exp) {
5948 setverdict(pass);
5949 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005951 }
5952 }
5953 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5954 if (tc.exp) {
5955 setverdict(pass);
5956 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005958 }
5959 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005960 /* We also expect to receive the measurements */
5961 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005962 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005964 }
5965 [not tc.exp] T.timeout {
5966 setverdict(pass);
5967 }
5968 }
5969
5970 f_rsl_chan_deact();
5971 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5972 f_rslem_unregister(0, g_chan_nr);
5973}
5974testcase TC_rll_est_ind() runs on test_CT {
5975 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005976 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005977 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005978 /* normal SAPI0 establishment */
5979 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005980 /* SAPI 3 doesn't support contention resolution */
5981 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5982 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5983 /* normal SAPI3 establishment on main DCCH */
5984 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5985 /* normal SAPI3 establishment on SACCH */
5986 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5987 };
5988 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5989}
5990
5991/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5992private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5993 var RllTestCase tc := g_pars.spec.rll;
5994 var L1ctlDlMessage dl;
5995 timer T := 3.0;
5996
5997 f_l1_tune(L1CTL);
5998 RSL.clear;
5999
6000 /* activate the logical channel */
6001 f_est_dchan();
6002 L1CTL.clear;
6003
6004 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6005 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6006 T.start;
6007 alt {
6008 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6009 var LapdmFrame lapdm;
6010 var octetstring l2 := dl.payload.data_ind.payload;
6011 if (dl.dl_info.link_id.c == SACCH) {
6012 /* remove L1 header */
6013 l2 := substr(l2, 2, lengthof(l2)-2);
6014 }
6015 lapdm.ab := dec_LapdmFrameAB(l2);
6016 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6017 setverdict(pass);
6018 } else {
6019 repeat;
6020 }
6021 }
6022 [] L1CTL.receive { repeat; }
6023 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006025 }
6026 }
6027
6028 f_rsl_chan_deact();
6029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6030 f_rslem_unregister(0, g_chan_nr);
6031}
6032testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6033 var RllTestCases tcs := {
6034 /* normal SAPI3 establishment on main DCCH */
6035 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6036 };
6037 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6038}
6039testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6040 var RllTestCases tcs := {
6041 /* normal SAPI3 establishment on SACCH */
6042 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6043 }
6044 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6045}
6046
6047/* altstep to receive a LAPDm frame matching the given template */
6048private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6049 var L1ctlDlMessage dl;
6050 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6051 var LapdmFrame lapdm;
6052 var octetstring l2 := dl.payload.data_ind.payload;
6053 if (dl.dl_info.link_id.c == SACCH) {
6054 /* remove L1 header */
6055 l2 := substr(l2, 2, lengthof(l2)-2);
6056 }
6057 if (ischosen(exp.ab)) {
6058 lapdm.ab := dec_LapdmFrameAB(l2);
6059 } else if (ischosen(exp.b4)) {
6060 lapdm.b4 := dec_LapdmFrameB4(l2);
6061 } else if (ischosen(exp.bbis)) {
6062 lapdm.bbis := dec_LapdmFrameBbis(l2);
6063 }
6064 log("Rx LAPDm ", lapdm);
6065 if (match(lapdm, exp)) {
6066 setverdict(pass);
6067 } else {
6068 repeat;
6069 }
6070 }
6071 [] L1CTL.receive { repeat; }
6072}
6073private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6074 timer T := t;
6075 T.start;
6076 alt {
6077 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006079 }
6080 [] as_l1_exp_lapdm(exp);
6081 }
6082}
6083
6084/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6085private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6086 /* send SABM from MS -> BTS */
6087 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6088 /* expect RLL EST IND on Abis */
6089 alt {
6090 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6091 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6092 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006094 }
6095 [] RSL.receive { repeat; }
6096 }
6097 /* expect UA from BTS -> MS */
6098 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6099}
6100
6101/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6102private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6103 var RllTestCase tc := g_pars.spec.rll;
6104
6105 f_l1_tune(L1CTL);
6106 RSL.clear;
6107
6108 /* activate the logical channel */
6109 f_est_dchan();
6110 L1CTL.clear;
6111
6112 /* first establish the link-layer */
6113 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6114
6115 /* then send the DISC */
6116 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6117 /* ... and expect the REL IND on the RSL side */
6118 alt {
6119 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6120 setverdict(pass);
6121 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006122 /* We also expect to receive the measurements */
6123 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006124 }
6125
6126 /* release the channel */
6127 f_rsl_chan_deact();
6128 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6129 f_rslem_unregister(0, g_chan_nr);
6130}
6131testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6132 var RllTestCases tcs := {
6133 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6134 };
6135 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6136}
6137
6138testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6139 var RllTestCases tcs := {
6140 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6141 };
6142 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6143}
6144testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6145 var RllTestCases tcs := {
6146 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6147 };
6148 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6149}
6150testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6151 var RllTestCases tcs := {
6152 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6153 };
6154 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6155}
6156
6157/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6158private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6159 var RllTestCase tc := g_pars.spec.rll;
6160 f_l1_tune(L1CTL);
6161 RSL.clear;
6162
6163 /* activate the logical channel */
6164 f_est_dchan();
6165 L1CTL.clear;
6166
6167 /* first establish the link-layer */
6168 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6169
6170 /* then send the REL REQ via RSL */
6171 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6172 /* ... and expect the DISC on the Um side */
6173 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006174 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006175 /* FIXME: send a UA in resposne to the DISC */
6176 }
6177 }
6178
6179 /* release the channel */
6180 f_rsl_chan_deact();
6181 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6182 f_rslem_unregister(0, g_chan_nr);
6183}
6184testcase TC_rll_rel_req() runs on test_CT {
6185 var RllTestCases tcs := {
6186 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6187 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6188 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6189 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6190 };
6191 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6192}
6193
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006194/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006195testcase TC_rll_data_req() runs on test_CT {
6196}
6197
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006198/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006199testcase TC_rll_data_ind() runs on test_CT {
6200}
6201
6202/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6203private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6204 var RllTestCase tc := g_pars.spec.rll;
6205
6206 f_l1_tune(L1CTL);
6207 RSL.clear;
6208
6209 f_est_dchan();
6210 L1CTL.clear;
6211
6212 /* Send UNITDATA REQ on RSL side */
6213 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6214 /* Expect it to arrive on the other side */
6215 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006216 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006217 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006218 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006219 }
6220
6221 /* release the channel */
6222 f_rsl_chan_deact();
6223 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6224 f_rslem_unregister(0, g_chan_nr);
6225}
6226testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6227 var octetstring l3 := f_rnd_octstring(15);
6228 var RllTestCases tcs := {
6229 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6230 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6231 };
6232 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6233}
6234testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6235 var octetstring l3 := f_rnd_octstring(19);
6236 var RllTestCases tcs := {
6237 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6238 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6239 };
6240 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6241}
6242
6243/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6244private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6245 var RllTestCase tc := g_pars.spec.rll;
6246
6247 f_l1_tune(L1CTL);
6248 RSL.clear;
6249
6250 f_est_dchan();
6251 L1CTL.clear;
6252
6253 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006254 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006255 /* Expdct RLL UNITDATA IND on RSL side */
6256 alt {
6257 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6258 setverdict(pass);
6259 }
6260 [] RSL.receive { repeat; }
6261 }
6262
6263 /* release the channel */
6264 f_rsl_chan_deact();
6265 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6266 f_rslem_unregister(0, g_chan_nr);
6267}
6268testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006269 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006270 var RllTestCases tcs := {
6271 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6272 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6273 };
6274 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6275}
6276testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6277 var octetstring l3 := f_rnd_octstring(18);
6278 var RllTestCases tcs := {
6279 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6280 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6281 };
6282 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6283}
6284
Harald Weltee613f962018-04-18 22:38:16 +02006285/***********************************************************************
6286 * Encryption Related
6287 ***********************************************************************/
6288
6289/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006290private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006291 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6292 if (link_id.c == SACCH) {
6293 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6294 } else {
6295 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6296 }
6297}
6298
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006299/* Expect (or not expect) other kinds of messages */
6300private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6301 [exp_any] RSL.receive { repeat; }
6302 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006304 }
6305}
6306
Harald Weltee613f962018-04-18 22:38:16 +02006307/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006308private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006309 RslLinkId link_id,
6310 octetstring l3,
6311 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006312 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006313) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006314 timer T := 3.0;
6315 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6316 T.start;
6317 /* Expect RLL UNITDATA IND on RSL side */
6318 alt {
6319 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6320 setverdict(pass);
6321 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006322 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006323 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006324 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006326 }
Harald Weltee613f962018-04-18 22:38:16 +02006327 }
6328}
6329
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006330/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6331private function f_data_mo(
6332 RslLinkId link_id,
6333 boolean p, uint3_t nr, uint3_t ns,
6334 octetstring l3,
6335 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006336 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006337) runs on ConnHdlr {
6338 timer T := 3.0;
6339 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6340 T.start;
6341 /* Expect RLL DATA IND on RSL side */
6342 alt {
6343 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6344 setverdict(pass);
6345 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006346 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006347 [] as_rsl_any_ind(exp_any);
6348 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006350 }
6351 }
6352}
6353
Harald Weltee613f962018-04-18 22:38:16 +02006354/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006355private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006356 f_l1_tune(L1CTL);
6357 f_est_dchan(true);
6358
6359 /* now we actually need to transmit some data both ways to check if the encryption works */
6360 var L1ctlDlMessage dl;
6361
Stefan Sperling603d98e2018-07-25 16:47:28 +02006362 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006363 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6364
6365 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6366 f_unitdata_mt(link_id, l3);
6367
6368 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6369 f_unitdata_mo(link_id, l3);
6370
6371 /* release the channel */
6372 f_rsl_chan_deact();
6373 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6374 f_rslem_unregister(0, g_chan_nr);
6375}
6376testcase TC_chan_act_a51() runs on test_CT {
6377 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6378 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6379 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6380}
6381testcase TC_chan_act_a52() runs on test_CT {
6382 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6383 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6384 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6385}
6386testcase TC_chan_act_a53() runs on test_CT {
6387 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6388 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6389 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6390}
6391
Eric Wildf1827a72019-05-28 17:37:35 +02006392/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6393 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 +07006394private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006395 f_l1_tune(L1CTL);
6396 f_est_dchan(true);
6397
6398 /* now we actually need to transmit some data both ways to check if the encryption works */
6399 var L1ctlDlMessage dl;
6400
6401 var octetstring l3 := f_rnd_octstring(20);
6402 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6403
6404 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6405 f_unitdata_mt(link_id, l3);
6406
6407 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6408 f_unitdata_mo(link_id, l3);
6409
6410 var RSL_Message rsl;
6411 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6412
6413 /* modify key to break proper encryption */
6414 g_pars.encr.key := f_rnd_octstring(8);
6415 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6416 rsl.ies := rsl.ies & { ei };
6417 RSL.send(rsl);
6418
6419 timer T0 := 1.0;
6420 T0.start;
6421 /* Expect RSL MODIFY ACK */
6422 alt {
6423 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6424 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6426 }
6427 [] T0.timeout {
6428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6429 }
6430 }
6431
6432 var octetstring l3msg := f_rnd_octstring(15);
6433 timer T1 := 3.0;
6434 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6435 due to broken encryption */
6436 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6437 T1.start;
6438 alt {
6439 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6441 }
6442 [] T1.timeout {
6443 setverdict(pass);
6444 }
6445 }
6446
6447 /* release the channel */
6448 f_rsl_chan_deact();
6449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6450 f_rslem_unregister(0, g_chan_nr);
6451}
6452testcase TC_rsl_modify_encr() runs on test_CT {
6453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6454 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6455 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6456}
Harald Weltee613f962018-04-18 22:38:16 +02006457
6458/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006459private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006460 /* L3 payload doesn't matter, as it is passed transparently */
6461 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6462 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6463 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6464
6465 f_l1_tune(L1CTL);
6466
6467 /* first establish a dedicated channel in the clear */
6468 f_est_dchan(false);
6469
6470 /* Establish ABM */
6471 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6472
6473 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6474 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6475 /* expect the L3 to arrive still unencrypted on the MS side */
6476 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6477
6478 /* configure L1 to apply ciphering */
6479 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6480 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6481
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006482 /* send first ciphered I-frame in response and expect it on RSL */
6483 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006484
6485 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6486 * and hence enable encryption also on the downlink */
6487
6488 /* expect bi-directional communication work in encrypted mode */
6489 f_unitdata_mo(link_id, f_rnd_octstring(15));
6490 f_unitdata_mt(link_id, f_rnd_octstring(15));
6491
6492 /* release the channel */
6493 f_rsl_chan_deact();
6494 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6495 f_rslem_unregister(0, g_chan_nr);
6496}
6497testcase TC_encr_cmd_a51() runs on test_CT {
6498 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6499 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6500 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6501}
6502testcase TC_encr_cmd_a52() runs on test_CT {
6503 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6504 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6505 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6506}
6507testcase TC_encr_cmd_a53() runs on test_CT {
6508 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6509 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6510 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6511}
6512
6513private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6514 var LapdmFrame lf;
6515 var octetstring reenc;
6516
6517 /* decode the LAPDm frame */
6518 if (ischosen(exp_match.ab)) {
6519 lf.ab := dec_LapdmFrameAB(enc);
6520 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006522 }
6523
6524 /* check if decoder result matches expectation */
6525 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006527 } else {
6528 log(name, ": matched");
6529 setverdict(pass);
6530 }
6531
6532 /* test if re-encoded frame equals original input */
6533 reenc := enc_LapdmFrame(lf);
6534 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006536 } else {
6537 setverdict(pass);
6538 }
6539}
6540
6541testcase TC_lapdm_selftest() runs on test_CT {
6542 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6543 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6544 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6545 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6546 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6547 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6548 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6549}
6550
Stefan Sperling4880be42018-08-07 18:12:59 +02006551/***********************************************************************
6552 * DTX Related (see GSM 05.08, section 8.3)
6553 ***********************************************************************/
6554
6555/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006556private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006557 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6558 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6559 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6560 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6561}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006562private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006563 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6564 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6565}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006566private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006567 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6568 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6569 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6570 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6571}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006572private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006573 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6574 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6575 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6576 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6577 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6578 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6579 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6580 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6581}
6582
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006583private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006584 var L1ctlDlMessage dl;
6585 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6586 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6587 var GsmFrameNumber first_fn;
6588 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006589 var integer nfill_frames_sacch := 0;
6590 var integer nfill_frames_nonsacch := 0;
6591 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006592 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6593 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006594 const integer frame_dtx_tchf_mod := 104;
6595 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6596 * which operates in terms of blocks rather than frames. */
6597 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6598 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 timer T := 5.0;
6600
6601 f_l1_tune(L1CTL);
6602 RSL.clear;
6603 L1CTL.clear;
6604
6605 /* activate TCHF signalling channel */
6606 f_est_dchan(false);
6607
6608 T.start;
6609 alt {
6610 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6611 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6612 var octetstring l2 := dl.payload.data_ind.payload;
6613
6614 if (is_first_frame) {
6615 is_first_frame := false;
6616 first_fn := dl.dl_info.frame_nr;
6617 }
6618
6619 if (dl.dl_info.link_id.c == SACCH) {
6620 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6621 if (not match(l2_fill_frame_sacch, l2)) {
6622 repeat;
6623 }
6624 } else if (not match(l2_fill_frame, l2)) {
6625 repeat;
6626 }
6627
6628 if (dtxd) {
6629 if (not f_g_chan_is_tchf()) {
6630 T.stop;
6631 f_rsl_chan_deact();
6632 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006633 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 +02006634 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006635 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006636 T.stop;
6637 f_rsl_chan_deact();
6638 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006639
6640 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6641 * 2 SACCH, 1 TCH/F */
6642 expected_fill_frames := 3;
6643
6644 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6645 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6646 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006648 } else {
6649 setverdict(pass);
6650 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006651 } else {
6652 if (dl.dl_info.link_id.c == SACCH) {
6653 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006654 repeat;
6655 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006656 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6657 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6658 * we should only see the subset of frames numbers which correspond to a block boundary.
6659 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6660 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6661 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6662 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6663 repeat;
6664 }
6665 }
6666 log("Received DTX TCH fill frame with bad frame number: ", fn,
6667 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6668 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6669 f_rsl_chan_deact();
6670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006672 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006673 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006674 if (dl.dl_info.link_id.c == SACCH) {
6675 nfill_frames_sacch := nfill_frames_sacch + 1;
6676 } else {
6677 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6678 }
6679 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006680 T.stop;
6681 if (f_g_chan_is_tchf()) {
6682 /* Without DTX we can expect 25 fill frames for every 104 frames.
6683 * (24 FACCH + 1 SACCH filling) */
6684 expected_fill_frames := 25;
6685 } else if (f_g_chan_is_tchh()) {
6686 /* We can expect 2 fill frames for every 104 frames. */
6687 expected_fill_frames := 2;
6688 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6689 /* We can expect 5 fill frames for every 104 frames. */
6690 expected_fill_frames := 5;
6691 } else {
6692 f_rsl_chan_deact();
6693 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006695 }
6696
6697 f_rsl_chan_deact();
6698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006699
6700 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006701 setverdict(pass);
6702 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006703 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6704 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006706 }
6707 } else {
6708 repeat;
6709 }
6710 }
6711 }
6712 [] L1CTL.receive { repeat; }
6713 [] T.timeout {
6714 f_rsl_chan_deact();
6715 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006717 }
6718 }
6719}
6720
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006721private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006722 f_test_l2_fill_frames(false);
6723}
6724
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006725private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006726 f_test_l2_fill_frames(true);
6727}
6728
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006729private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006730 var ConnHdlr vc_conn;
6731 var ConnHdlrPars pars;
6732 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006733 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006734 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6735 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6736 if (dtxd) {
6737 if (i >= 4) { /* DTX is only allowed on TCH/F */
6738 break;
6739 }
6740 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6741 } else {
6742 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6743 }
6744 vc_conn.done;
6745 }
6746}
6747
6748/* Verify that L2 fill frames are sent on TCH in signaling mode if
6749 * there is nothing to transmit while DTX is disabled on downlink. */
6750testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6751 f_tch_sign_l2_fill_frame(false);
6752}
6753
6754/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6755 * there is nothing to transmit while DTX is enabled on downlink. */
6756testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6757 f_tch_sign_l2_fill_frame(true);
6758}
Harald Welte0472ab42018-03-12 15:02:26 +01006759
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006760testcase TC_chopped_ipa_ping() runs on test_CT {
6761 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6762}
6763
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006764testcase TC_chopped_ipa_payload() runs on test_CT {
6765 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6766}
6767
Harald Welte0472ab42018-03-12 15:02:26 +01006768/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6769/* protocol error as per 44.006 */
6770/* link layer failure (repetition of I-frame N200 times without ACK */
6771/* repetition of SABM or DISC N200 times without ACK */
6772/* receptiom of SABM in multi-frame established state */
6773
6774
Harald Welte68e495b2018-02-25 00:05:57 +01006775/* TODO Areas:
6776
6777* channel activation
6778** with BS_Power / MS_Power, bypassing power control loop
6779** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006780** with timing advance from initial activation on
6781* mode modify
6782** encryption
6783** multirate
6784* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006785** unsupported algorithm
6786* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006787* BS Power Control
6788* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006789* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006790* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006791** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006792* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006793** DATA_IND from BTS->PCU
6794** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006795
6796*/
Harald Welte70767382018-02-21 12:16:40 +01006797
6798control {
6799 execute( TC_chan_act_stress() );
6800 execute( TC_chan_act_react() );
6801 execute( TC_chan_deact_not_active() );
6802 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006803 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006804 execute( TC_sacch_filling() );
6805 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006806 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006807 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006808 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006809 execute( TC_sacch_chan_act_ho_async() );
6810 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006811 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006812 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006813 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006814 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006815 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006816 execute( TC_rach_load_idle_thresh0() );
6817 execute( TC_rach_load_idle_below_thresh() );
6818 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006819 execute( TC_meas_res_sign_tchf() );
6820 execute( TC_meas_res_sign_tchh() );
6821 execute( TC_meas_res_sign_sdcch4() );
6822 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006823 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006824 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006825 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006826 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006827 execute( TC_rsl_bs_pwr_static_ass() );
6828 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006829 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006830 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006831 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006832 execute( TC_rsl_ms_pwr_dyn_up() );
6833 execute( TC_rsl_ms_pwr_dyn_down() );
6834 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6835 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006836 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006837 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006838 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006839 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006840 execute( TC_paging_imsi_80percent() );
6841 execute( TC_paging_tmsi_80percent() );
6842 execute( TC_paging_imsi_200percent() );
6843 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006844 execute( TC_rsl_protocol_error() );
6845 execute( TC_rsl_mand_ie_error() );
6846 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006847 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006848 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006849 execute( TC_si_sched_2bis() );
6850 execute( TC_si_sched_2ter() );
6851 execute( TC_si_sched_2ter_2bis() );
6852 execute( TC_si_sched_2quater() );
6853 execute( TC_si_sched_13() );
6854 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006855 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006856 execute( TC_ipa_crcx_twice_not_active() );
6857 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006858 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006859 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006860
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006861 if (mp_pcu_socket != "") {
6862 execute( TC_pcu_act_req() );
6863 execute( TC_pcu_act_req_wrong_ts() );
6864 execute( TC_pcu_act_req_wrong_bts() );
6865 execute( TC_pcu_act_req_wrong_trx() );
6866 execute( TC_pcu_deact_req() );
6867 execute( TC_pcu_deact_req_wrong_ts() );
6868 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006869 if (mp_l1_supports_gprs) {
6870 execute( TC_pcu_data_req_pdtch() );
6871 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006872 execute( TC_pcu_data_req_wrong_bts() );
6873 execute( TC_pcu_data_req_wrong_trx() );
6874 execute( TC_pcu_data_req_wrong_ts() );
6875 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006876 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006877 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006878 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006879 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006880 execute( TC_pcu_data_req_imm_ass_pch() );
6881 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006882 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006883 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006884 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006885 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006886 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006887 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006888 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006889 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006890 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006891 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006892 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006893 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006894 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006895 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006896 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006897 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006898 execute( TC_dyn_osmo_pdch_act_deact() );
6899 execute( TC_dyn_osmo_pdch_double_act() );
6900 execute( TC_dyn_ipa_pdch_act_deact() );
6901 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6902
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006903 if (PCUIF_Types.mp_pcuif_version >= 10) {
6904 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006905 execute( TC_pcu_socket_nsvc_ipv4() );
6906 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006907 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006908 } else {
6909 log("PCU socket path not available, skipping PCU tests");
6910 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006911
Harald Welte3d04ae62018-04-04 20:29:05 +02006912 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006913 execute( TC_dyn_osmo_pdch_tchf_act() );
6914 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006915 execute( TC_dyn_ipa_pdch_tchf_act() );
6916 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006917
6918 execute( TC_rll_est_ind() );
6919 execute( TC_rll_est_req_DCCH_3() );
6920 execute( TC_rll_est_req_ACCH_3() );
6921 execute( TC_rll_rel_ind_DCCH_0() );
6922 execute( TC_rll_rel_ind_DCCH_3() );
6923 execute( TC_rll_rel_ind_ACCH_0() );
6924 execute( TC_rll_rel_ind_ACCH_3() );
6925 execute( TC_rll_rel_req() );
6926 execute( TC_rll_unit_data_req_DCCH() );
6927 execute( TC_rll_unit_data_req_ACCH() );
6928 execute( TC_rll_unit_data_ind_DCCH() );
6929 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006930
6931 execute( TC_chan_act_a51() );
6932 execute( TC_chan_act_a52() );
6933 execute( TC_chan_act_a53() );
6934 execute( TC_encr_cmd_a51() );
6935 execute( TC_encr_cmd_a52() );
6936 execute( TC_encr_cmd_a53() );
6937
Harald Welteee25aae2019-05-19 14:32:37 +02006938 execute( TC_err_rep_wrong_mdisc() );
6939 execute( TC_err_rep_wrong_msg_type() );
6940 execute( TC_err_rep_wrong_sequence() );
6941
Harald Weltee613f962018-04-18 22:38:16 +02006942 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006943
6944 execute( TC_tch_sign_l2_fill_frame() );
6945 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006946
6947 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006948 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006949}
6950
6951
6952}