blob: 7c17e0355bfa1822a0c71a1c647504702d52861e [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
Harald Weltee37f9a52020-10-11 20:45:23 +02001473 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1474 alt {
1475 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1476 [] RSL_CCHAN.receive { repeat }
1477 }
1478
Harald Welte3453ab42019-05-24 21:19:58 +02001479 timer T := 5.0;
1480 T.start;
1481 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001482 [] 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 +02001483 setverdict(pass);
1484 repeat;
1485 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001486 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001487 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1488 repeat;
1489 }
1490 [] RSL_CCHAN.receive {
1491 repeat;
1492 }
1493 [] T.timeout { }
1494 }
1495
1496 f_vty_load_ind_thresh(10);
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
1499
1500/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1501testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1502 var ASP_RSL_Unitdata rx_ud;
1503
1504 f_init_vty_bsc();
1505 f_init();
1506
1507 timer T := 5.0;
1508 T.start;
1509 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001510 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001511 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1512 repeat;
1513 }
1514 [] RSL_CCHAN.receive {
1515 repeat;
1516 }
1517 [] T.timeout {
1518 setverdict(pass);
1519 }
1520 }
1521
1522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1523}
1524
1525/* Expect 0 RACH load on an idle BTS that has just started up */
1526testcase TC_rach_load_count() runs on test_CT {
1527 var ASP_RSL_Unitdata rx_ud;
1528 var integer load_access_count := 0;
1529
1530 f_init_vty_bsc();
1531 /* send load indications even at 0% load */
1532 f_vty_load_ind_thresh(0);
1533 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1534 f_sleep(2.0);
1535 f_init();
1536
1537 f_init_l1ctl();
1538 f_sleep(1.0);
1539 f_l1_tune(L1CTL);
1540
1541 var GsmFrameNumber fn_last := 0;
1542 for (var integer i := 0; i < 1000; i := i+1) {
1543 var OCT1 ra := f_rnd_ra_cs();
1544 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1545 if (fn == fn_last) {
1546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1547 }
1548 fn_last := fn;
1549 }
1550
1551 timer T := 5.0;
1552 T.start;
1553 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001554 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001555 -> value rx_ud {
1556 var RSL_IE_Body ie;
1557 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1558 load_access_count := load_access_count + ie.rach_load.access_count;
1559 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1560 setverdict(fail, "Access count cannot be < Busy count");
1561 }
1562 repeat;
1563 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001564 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001565 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1566 repeat;
1567 }
1568 [] RSL_CCHAN.receive {
1569 repeat;
1570 }
1571 [] T.timeout { }
1572 }
1573 if (load_access_count == 1000) {
1574 setverdict(pass);
1575 } else {
1576 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1577 }
1578
1579 f_vty_load_ind_thresh(10);
1580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1581}
1582
Harald Welte54a2a2d2018-02-26 09:14:05 +01001583private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001584 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001585 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001586 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001587 f_sleep(0.5);
1588
1589 /* Transmit RACH request + wait for confirmation */
1590 var OCT1 ra := f_rnd_ra_cs();
1591 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1592
1593 /* Check for expected result */
1594 timer T := 1.5;
1595 T.start;
1596 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001597 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001598 setverdict(pass);
1599 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001600 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001602 }
1603 [] RSL_CCHAN.receive { repeat; }
1604 [not expect_pass] T.timeout {
1605 setverdict(pass);
1606 }
1607 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001609 }
1610 }
1611}
1612
1613/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1614testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001615 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001616 f_init_l1ctl();
1617 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001618 f_sleep(1.0);
1619
1620 /* default max-ta is 63 (full range of GSM timing advance */
1621
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001622 /* We allow early arrival up to 2 symbols */
1623 f_rach_toffs(-1*256, true);
1624 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001625 f_rach_toffs(-10*256, false);
1626
1627 /* 0 / 32 / 63 bits is legal / permitted */
1628 f_rach_toffs(0, true);
1629 f_rach_toffs(32*256, true);
1630 f_rach_toffs(63*256, true);
1631
1632 /* more than 63 bits is not legal / permitted */
1633 f_rach_toffs(64*256, false);
1634 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001636}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001637
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001638private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001639 var GsmFrameNumber fn;
1640 var RSL_Message rm;
1641
1642 f_l1_tune(L1CTL);
1643 RSL.clear;
1644
1645 /* Generate a random Handover Reference */
1646 var integer ho_ref := oct2int(f_rnd_octstring(1));
1647
1648 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1649 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1650 RSL_IE_Body:{ handover_ref := ho_ref }));
1651
1652 /* Activate a channel on the BTS side (no encryption) */
1653 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1654 act_type := t_RSL_IE_ActType_HO_SYNC);
1655
1656 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1657 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001658 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001659
1660 /* Send handover Access Burst */
1661 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1662
1663 /* TODO: test mismatching Handover Reference, and missing IE */
1664
1665 /* Wait for handover detection */
1666 timer T := 3.0;
1667 T.start;
1668 alt {
1669 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1670 log("Handover RACH has been detected: ", rm);
1671 setverdict(pass);
1672 }
1673 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1675 log2str("RSL_CHAN_RQD was not expected: ", rm));
1676 }
1677 [] RSL.receive { repeat; }
1678 [] T.timeout {
1679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1680 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1681 }
1682 }
1683
1684 /* Release the channel */
1685 f_rsl_chan_deact();
1686 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1687}
1688
1689/* Test handover RACH detection */
1690testcase TC_ho_rach() runs on test_CT {
1691 var ConnHdlrPars pars;
1692 var ConnHdlr vc_conn;
1693
1694 f_init();
1695
1696 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1697 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1698 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1699 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1700 vc_conn.done;
1701 }
1702
1703 /* TODO: do the above in parallel, rather than sequentially? */
1704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1705}
1706
Harald Welte93640c62018-02-25 16:59:33 +01001707/***********************************************************************
1708 * Measurement Processing / Reporting
1709 ***********************************************************************/
1710
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001711private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001712 spare := '0'B,
1713 lpd := 0,
1714 sapi := sapi,
1715 c_r := c_r,
1716 ea := true
1717}
1718
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001719private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001720 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001721 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001722 len := 0, /* overwritten */
1723 m := false,
1724 el := 1,
1725 payload := pl
1726}
1727
1728/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001729private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001730 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001731 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001732 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001733 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 +01001734 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001735 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001736
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001737 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1738 g_pars.l1_pars.ms_power_level, false,
1739 g_pars.l1_pars.ms_actual_ta);
1740
1741 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1742 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1743
1744 log("Sending Measurement Report: ", l1h, l2);
1745 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001746 repeat;
1747 }
1748}
1749
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001750private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001751 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001752 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001753 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1754 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001755 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1756 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001757 repeat;
1758 }
1759}
1760
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001761private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001762 uint6_t rxlev,
1763 uint3_t rxqual
1764}
1765
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001766private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001767 MeasElem full,
1768 MeasElem sub
1769}
1770
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001771private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001772 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001773 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001774 MeasElemFS meas_ul,
1775 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001776 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001777 uint5_t ms_power_level,
1778 uint8_t ms_actual_ta
1779}
1780
1781/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1782private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1783 return 63 + (toffs256s/256);
1784}
1785
Harald Welted5684392018-03-10 18:22:04 +01001786private function f_max(integer a, integer b) return integer {
1787 if (a > b) {
1788 return a;
1789 } else {
1790 return b;
1791 }
1792}
1793
1794private function f_min(integer a, integer b) return integer {
1795 if (a < b) {
1796 return a;
1797 } else {
1798 return b;
1799 }
1800}
1801
1802/* compute negative tolerance val-tolerance, ensure >= min */
1803private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1804 val := val - tolerance;
1805 return f_max(val, min);
1806}
1807
1808/* compute positive tolerance val+tolerance, ensure <= max */
1809private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1810 val := val + tolerance;
1811 return f_min(val, max);
1812}
1813
1814/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1815private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1816return template integer {
1817 var template integer ret;
1818 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1819 return ret;
1820}
1821
1822
Harald Welte70767382018-02-21 12:16:40 +01001823/* build a template for matching measurement results against */
1824private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1825 var ConnL1Pars l1p := g_pars.l1_pars;
1826 var template RSL_IE_UplinkMeas ul_meas := {
1827 len := 3,
1828 rfu := '0'B,
1829 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001830 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001831 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001832 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001833 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001834 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1835 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001836 supp_meas_info := omit
1837 };
Harald Welte685d5982018-02-27 20:42:05 +01001838 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001839 ul_meas.len := (3+8);
1840 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001841 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001842 toa256_min := ?,
1843 toa256_max := ?,
1844 toa256_std_dev := ?
1845 }
Harald Welte685d5982018-02-27 20:42:05 +01001846 }
Harald Welte70767382018-02-21 12:16:40 +01001847 var template RSL_IE_BS_Power bs_power := {
1848 reserved := 0,
1849 epc := false,
1850 fpc := false,
1851 power_level := l1p.bs_power_level
1852 };
1853 var template RSL_IE_L1Info l1_info := {
1854 ms_power_lvl := l1p.ms_power_level,
1855 fpc := false,
1856 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001857 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001858 };
1859 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001860 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001861 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1862 ?, t_toffs);
1863}
1864
Philipp Maierdd841d32019-12-17 14:44:54 +01001865/* build a template for matching measurement results that do not contain any
1866 * MS related measurement (l1_info, l3_info and ms timing offset). */
1867private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1868 var ConnL1Pars l1p := g_pars.l1_pars;
1869 var template RSL_IE_UplinkMeas ul_meas := {
1870 len := 3,
1871 rfu := '0'B,
1872 dtx_d := l1p.dtx_enabled,
1873 rxlev_f_u := ?,
1874 reserved1 := '00'B,
1875 rxlev_s_u := ?,
1876 reserved2 := '00'B,
1877 rxq_f_u := ?,
1878 rxq_s_u := ?,
1879 supp_meas_info := omit
1880 };
1881 if (l1p.toa256_enabled) {
1882 ul_meas.len := (3+8);
1883 ul_meas.supp_meas_info := {
1884 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1885 toa256_min := ?,
1886 toa256_max := ?,
1887 toa256_std_dev := ?
1888 }
1889 }
1890 var template RSL_IE_BS_Power bs_power := {
1891 reserved := 0,
1892 epc := false,
1893 fpc := false,
1894 power_level := l1p.bs_power_level
1895 };
1896
1897 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1898}
1899
Harald Welte70767382018-02-21 12:16:40 +01001900/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001901private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001902 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001903 var boolean chan_est := false;
1904
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001905 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001906
1907 /* Receive osmocom specific measurement reports. This is the normal
1908 * case. Here we verify that the measurement reports we sent are
1909 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001910 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1911 /* increment counter of next to-be-expected meas rep */
1912 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1913 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001914 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001915
1916 /* The following two cases may only happen in the beginning
1917 * of the channel establishment phase. Once we have received
1918 * the "our" measurement report the first time, the channel
1919 * is established and empty or hardcoded TRXCON reports must
1920 * not occur anymore. */
1921 chan_est := true;
1922
1923 repeat;
1924 }
1925
1926 /* When the BTS has established the channel, the MS might need slightly
1927 * more time to establish the channel and actually start sending. The
1928 * result is then a measurement report that just lacks the measurement
1929 * information of the MS. This is normal and we tolerate this behavior. */
1930 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1931 /* increment counter of next to-be-expected meas rep */
1932 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1933 /* Re-start the timer expecting the next MEAS RES */
1934 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001935 repeat;
1936 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001937
1938 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1939 * measurements if the TTCN3 side does not supply measurement input in
1940 * time. In those cases TRXCON will either use a cached measurement
1941 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1942 * report the templates above will not match. We tolerate this
1943 * behavior, but only once. */
1944 [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 +01001945 /* increment counter of next to-be-expected meas rep */
1946 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1947 if (g_first_meas_res) {
1948 g_first_meas_res := false;
1949 repeat;
1950 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001952 }
Harald Welte70767382018-02-21 12:16:40 +01001953 }
1954 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001956 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001957 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001959 }
1960}
1961
Harald Weltee613f962018-04-18 22:38:16 +02001962private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1963 select (rsl_alg_id) {
1964 case (RSL_ALG_ID_A5_0) { return 0; }
1965 case (RSL_ALG_ID_A5_1) { return 1; }
1966 case (RSL_ALG_ID_A5_2) { return 2; }
1967 case (RSL_ALG_ID_A5_3) { return 3; }
1968 case (RSL_ALG_ID_A5_4) { return 4; }
1969 case (RSL_ALG_ID_A5_5) { return 5; }
1970 case (RSL_ALG_ID_A5_6) { return 6; }
1971 case (RSL_ALG_ID_A5_7) { return 7; }
1972 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1974 /* Make compiler happy by calling mtc.stop here. It is already
1975 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001976 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001977 }
1978 }
1979}
1980
1981private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1982 select (rsl_alg_id) {
1983 case (RSL_ALG_ID_A5_1) { return '000'B; }
1984 case (RSL_ALG_ID_A5_2) { return '001'B; }
1985 case (RSL_ALG_ID_A5_3) { return '010'B; }
1986 case (RSL_ALG_ID_A5_4) { return '011'B; }
1987 case (RSL_ALG_ID_A5_5) { return '100'B; }
1988 case (RSL_ALG_ID_A5_6) { return '101'B; }
1989 case (RSL_ALG_ID_A5_7) { return '110'B; }
1990 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1992 /* Make compiler happy by calling mtc.stop here. It is already
1993 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001994 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001995 }
1996 }
1997}
1998
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001999/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2000private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2001 var GsmFrameNumber fn;
2002 timer T := 8.0;
2003
2004 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2005 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2006
2007 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2008 /* Send the actual RACH */
2009 fn := f_L1CTL_RACH(L1CTL, ra);
2010
2011 T.start;
2012 alt {
2013 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2014 [] T.timeout {
2015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2016 }
2017 }
2018 T.stop
2019 return fn;
2020}
Harald Weltee613f962018-04-18 22:38:16 +02002021
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002022/* Tune to a dedicated channel: L1CTL only */
2023private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002024 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002025 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2026 7 /* TODO: mp_tsc */,
2027 mp_trx0_arfcn));
2028 } else {
2029 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2030 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002031 pars.fhp.maio_hsn.hsn,
2032 pars.fhp.maio_hsn.maio,
2033 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002034 }
2035}
2036
Harald Welte70767382018-02-21 12:16:40 +01002037/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002038private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002039 var GsmFrameNumber fn;
2040 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002041 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002042 var integer ra := 23;
2043
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002044 /* Send RACH request and wait for ChanReq */
2045 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002046
2047 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002048 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002049
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002050 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002051 if (g_pars.fhp.enabled) {
2052 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002053 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002054 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002055 }
2056
Harald Welte70767382018-02-21 12:16:40 +01002057 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002058 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 +01002059 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2060
2061 /* receive IMM.ASS on MS side */
2062 var ImmediateAssignment ia_um;
2063 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002064
2065 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2066 if (ch_desc.h != ia_um.chan_desc.h) {
2067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2068 }
2069
Harald Welte70767382018-02-21 12:16:40 +01002070 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002071 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002072 /* enable encryption, if requested */
2073 if (encr_enable) {
2074 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2075 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2076 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002077
2078 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002079}
2080
2081/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002082private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002083 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002084 RSL.clear;
2085
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002086 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002087 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002088 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002089 }
Harald Welte70767382018-02-21 12:16:40 +01002090
2091 f_est_dchan();
2092
2093 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2094 * RSL measurement reports on Abis side */
2095 timer T := 8.0;
2096 T.start;
2097 alt {
2098 [] as_l1_sacch();
2099 [] as_meas_res();
2100 [] as_l1_dcch();
2101 [] L1CTL.receive { repeat; }
2102 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002103 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002104 * of any earlier errors, so if we reach this timeout, we're good */
2105 setverdict(pass);
2106 }
2107 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002109 }
2110 }
2111 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002112 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002113}
Harald Welte0472ab42018-03-12 15:02:26 +01002114
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002115/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2116private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002117 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002118 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2119 timer Tup := 10.0;
2120 Tup.start;
2121 alt {
2122 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2123 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2124 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002125
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002126 if (rx_lvl != max_rx_lvl) {
2127 repeat;
2128 }
2129 Tup.stop;
2130 }
2131 [] L1CTL.receive { repeat; }
2132 [] Tup.timeout {
2133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2134 log2str("Didn't reach full power ", max_rx_lvl));
2135 }
2136 }
2137 return max_rx_lvl;
2138}
2139
2140/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2141private function f_verify_ramp_up() runs on ConnHdlr {
2142 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002143 var integer initial_rx_lvl := -1;
2144 var integer last_rx_lvl := -1;
2145 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2146
2147 timer T := 2.0;
2148 alt {
2149 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2150 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2151 log("Received rx_level=", rx_lvl);
2152 if (initial_rx_lvl == -1) {
2153 initial_rx_lvl := rx_lvl;
2154 last_rx_lvl := rx_lvl;
2155
2156 /* Expect a somehow low value during first received messages */
2157 if (initial_rx_lvl >= max_rx_lvl / 2) {
2158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2159 log2str("Detected high initial tx power during ramp up: ",
2160 initial_rx_lvl , ", full power is", max_rx_lvl));
2161 }
2162 }
2163
2164 /* received Rx level bigger than maximum allowed power by CN */
2165 if (rx_lvl > max_rx_lvl) {
2166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2167 log2str("Detected Tx power higher than full power: ",
2168 rx_lvl , " > ", max_rx_lvl));
2169 }
2170
2171 /* Make sure it never decreases, since we are rumping up */
2172 if (last_rx_lvl > rx_lvl) {
2173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2174 log2str("Detected Tx power decrease during ramp up: ",
2175 last_rx_lvl , " -> ", rx_lvl));
2176 }
2177
2178 if (rx_lvl == max_rx_lvl and not T.running) {
2179 /* We reached the maximum power, start timer and receive
2180 /* a few more to make sure we don't surpass it */
2181 log("Reached full power, wating a bit more until success");
2182 T.start;
2183 }
2184
2185 last_rx_lvl := rx_lvl;
2186 repeat;
2187 }
2188 [] L1CTL.receive { repeat; }
2189 [] T.timeout { }
2190 }
2191
2192 /* We didn't increase tx power during ramp up */
2193 if (initial_rx_lvl < last_rx_lvl) {
2194 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2195 } else {
2196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2197 log2str("No Tx power increase during whole ramp up: ",
2198 initial_rx_lvl , " -> ", last_rx_lvl));
2199 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002200}
2201
2202/* verify BTS ramps power down to rx_level 0 */
2203private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2204 var L1ctlDlMessage l1_dl;
2205 var integer last_rx_lvl := max_rx_lvl;
2206
2207 timer Tdown := 5.0;
2208 Tdown.start;
2209 alt {
2210 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2211 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2212 log("Received rx_level=", rx_lvl);
2213
2214 /* received Rx level bigger than maximum allowed power by CN */
2215 if (rx_lvl > max_rx_lvl) {
2216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2217 log2str("Detected Tx power higher than full power: ",
2218 rx_lvl , " > ", max_rx_lvl));
2219 }
2220
2221 /* Make sure it never increases, since we are rumping down */
2222 if (last_rx_lvl < rx_lvl) {
2223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2224 log2str("Detected Tx power increase during ramp up: ",
2225 last_rx_lvl , " -> ", rx_lvl));
2226 }
2227
2228 last_rx_lvl := rx_lvl;
2229 if (last_rx_lvl != 0) {
2230 repeat;
2231 }
2232 /* we reached power level 0, we are done */
2233 Tdown.stop;
2234 }
2235 [] L1CTL.receive { repeat; }
2236 [] Tdown.timeout { }
2237 }
2238
2239 /* We didn't increase tx power during ramp down */
2240 if (max_rx_lvl > last_rx_lvl) {
2241 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2242 } else {
2243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2244 log2str("No Tx power decrease during whole ramp down: ",
2245 max_rx_lvl , " -> ", last_rx_lvl));
2246 }
2247}
2248
2249/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002250private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002251 f_l1_tune(L1CTL);
2252 RSL.clear;
2253
2254 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002255
2256 setverdict(pass);
2257}
2258testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2259 var ConnHdlr vc_conn;
2260 var ConnHdlrPars pars;
2261 f_init();
2262 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2263 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2264 pcu_comp := false, trxc_comp := true);
2265 vc_conn.done;
2266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2267}
2268
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002269/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002270private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002271 f_connhdlr_init_vty_bsc();
2272
2273 f_l1_tune(L1CTL);
2274 RSL.clear;
2275
2276 /* Wait until BTS is started and at full power */
2277 var integer max_rx_lvl := f_wait_ramp_up();
2278 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2279
2280 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2281 f_verify_ramp_down(max_rx_lvl);
2282
2283 setverdict(pass);
2284}
2285testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2286 var ConnHdlr vc_conn;
2287 var ConnHdlrPars pars;
2288 f_init();
2289 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2290 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2291 pcu_comp := false, trxc_comp := true);
2292 vc_conn.done;
2293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2294}
2295
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002296/* Verify Tx power:
2297 * + ramping down during ADM state UNLOCKED->LOCKED
2298 * + ramping up during ADM state LOCKED->UNLOCKED
2299 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002300private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002301 var L1ctlDlMessage l1_dl;
2302 var integer last_rx_lvl;
2303
2304 f_connhdlr_init_vty_bsc();
2305
2306 f_l1_tune(L1CTL);
2307 RSL.clear;
2308
2309 /* Wait until BTS is started and at full power */
2310 var integer max_rx_lvl := f_wait_ramp_up();
2311 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2312
2313 log("ADM STATE UNLOCKED->LOCKED");
2314 f_vty_enter_cfg_trx(BSCVTY);
2315 f_vty_transceive(BSCVTY, "rf_locked 1");
2316 last_rx_lvl := max_rx_lvl;
2317 f_verify_ramp_down(max_rx_lvl);
2318
2319 /* Let some time after we received 0dBm, then check we don't receive BCCH
2320 * anymore because scheduler has stopped after ramping down */
2321 f_sleep(2.0);
2322 L1CTL.clear;
2323 timer Tlocked := 2.0;
2324 Tlocked.start;
2325 alt {
2326 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2328 log2str("Received data_ind during rf_locked: ", l1_dl));
2329 }
2330 [] L1CTL.receive { repeat; }
2331 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2332 }
2333
2334 log("ADM STATE LOCKED->UNLOCKED");
2335 f_vty_transceive(BSCVTY, "rf_locked 0");
2336 f_verify_ramp_up();
2337 setverdict(pass);
2338}
2339testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2340 var ConnHdlr vc_conn;
2341 var ConnHdlrPars pars;
2342 f_init();
2343 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2344 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2345 pcu_comp := false, trxc_comp := true);
2346 vc_conn.done;
2347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2348}
2349
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002350private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002351 timer T := 8.0;
2352 T.start;
2353 var RSL_Message rsl;
2354 alt {
2355 [] as_l1_sacch();
2356 [] L1CTL.receive { repeat; }
2357 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2358 if (rsl.ies[3].body.bs_power.power_level == level) {
2359 setverdict(pass)
2360 } else {
2361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2362 }
2363 }
2364 [] T.timeout {
2365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2366 }
2367 }
2368}
2369
2370/* see if the rsl meas res contains our expeced bs power level
2371bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002372private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002373 f_l1_tune(L1CTL);
2374 RSL.clear;
2375
2376 if (mp_bts_trxc_port != -1) {
2377 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2378 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2379 }
2380
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002381 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002382 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2383 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2384
2385 f_est_dchan(more_ies :={valueof(pwr)});
2386
2387 f_check_meas_bs_power_level(pwr_var);
2388
2389 f_rsl_chan_deact();
2390 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2391}
2392
2393/* see if the rsl meas res contains our expeced bs power level
2394bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002395private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002396 f_l1_tune(L1CTL);
2397 RSL.clear;
2398
2399 if (mp_bts_trxc_port != -1) {
2400 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2401 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2402 }
2403
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002404 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002405 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2406
2407 f_est_dchan();
2408
2409 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2410
2411 f_check_meas_bs_power_level(pwr_var);
2412
2413 f_rsl_chan_deact();
2414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2415}
2416
2417testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2418 var ConnHdlr vc_conn;
2419 var ConnHdlrPars pars;
2420 f_init();
2421 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2422 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2423 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2424 pcu_comp := false, trxc_comp := true);
2425 vc_conn.done;
2426 }
2427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2428}
2429
2430testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2431 var ConnHdlr vc_conn;
2432 var ConnHdlrPars pars;
2433 f_init();
2434 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2435 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2436 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2437 pcu_comp := false, trxc_comp := true);
2438 vc_conn.done;
2439 }
2440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2441}
2442
Eric Wild61edb7e2019-06-03 12:38:31 +02002443/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2444second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2445These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002446private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002447 var uint5_t pwr_var := 7;
2448 var L1ctlDlMessage l1_dl;
2449
2450 f_trxc_fake_rssi(rxlev2dbm(10));
2451 f_l1_tune(L1CTL);
2452 RSL.clear;
2453
2454 var RSL_IE_List addl_ies;
2455 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2456
2457 addl_ies := {
2458 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2459 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2460 };
2461
2462 /* establish with power parameters */
2463 f_est_dchan(more_ies := addl_ies);
2464
2465 /* set a high value to ensure L1 power control level increases */
2466 f_trxc_fake_rssi(rxlev2dbm(20));
2467
2468 timer T2 := 6.0;
2469 T2.start;
2470 alt {
2471 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002472 /* Update sent MS power to follow what BTS requests */
2473 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2474 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002475 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002476 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002477 T2.stop;
2478 }
2479 [] L1CTL.receive { repeat; }
2480 [] T2.timeout {
2481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2482 "Power Level in L1 header has not increased sufficiently");
2483 }
2484 }
2485
2486 /* set a low value to ensure L1 power control level decreases */
2487 f_trxc_fake_rssi(rxlev2dbm(0));
2488
2489 timer T4 := 6.0;
2490 T4.start;
2491 alt {
2492 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002493 /* Update sent MS power to follow what BTS requests */
2494 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2495 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002496 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002497 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002498 T4.stop;
2499 setverdict(pass, "Power level in L1 decreased/increased as expected");
2500 }
2501 [] L1CTL.receive { repeat; }
2502 [] T4.timeout {
2503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2504 "Power Level in L1 header has not decreased sufficiently");
2505 }
2506 }
2507
2508 f_rsl_chan_deact();
2509 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2510
2511}
2512
2513/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002514private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002515 var uint5_t pwr_var := 7;
2516 var L1ctlDlMessage l1_dl;
2517
2518 /* set a low value to ensure power increases */
2519 f_trxc_fake_rssi(rxlev2dbm(10));
2520 f_l1_tune(L1CTL);
2521 RSL.clear;
2522
2523 var RSL_IE_List addl_ies;
2524 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2525
2526 addl_ies := {
2527 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2528 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2529 };
2530
2531 /* establish with power parameters */
2532 f_est_dchan(more_ies := addl_ies);
2533
2534 timer T1 := 10.0;
2535 T1.start;
2536 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002537 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2538 /* Update sent MS power to follow what BTS requests */
2539 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2540 repeat;
2541 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002542 [] L1CTL.receive { repeat; }
2543 [] T1.timeout {
2544 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2545 setverdict(fail, "Power level in L1 header should not have changed");
2546 }
2547 }
2548 }
2549
2550 f_rsl_chan_deact();
2551 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2552
2553}
2554
2555/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002556private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002557 var L1ctlDlMessage l1_dl;
2558 var uint5_t pwr_var := 15;
2559 var uint5_t pwr_max_var := f_get_max_power_from_band();
2560
2561 /* set a low value to ensure power increases */
2562 f_trxc_fake_rssi(rxlev2dbm(10));
2563 f_l1_tune(L1CTL);
2564 RSL.clear;
2565
2566 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2567 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2568
2569 /* establish with fixed power level */
2570 f_est_dchan(more_ies :={valueof(pwr)});
2571
2572 /* check our initial power level */
2573 f_wait_for_l1_power_level(pwr_var);
2574
2575 /* update power param to enable power loop
2576 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2577 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2578
2579 /* wait, then check that our power level was reduced */
2580 timer T1 := 10.0;
2581 T1.start;
2582 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002583 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2584 /* Update sent MS power to follow what BTS requests */
2585 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2586 repeat;
2587 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002588 [] L1CTL.receive { repeat; }
2589 [] T1.timeout {
2590 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2591 if( f_power_level_is_highest_dbm(rcv) ){
2592 setverdict(pass, "Power level in L1 header reduced as expected");
2593 } else {
2594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2595 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2596 }
2597 }
2598 }
2599
2600 f_rsl_chan_deact();
2601 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2602
2603}
2604
2605/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002606private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002607 var L1ctlDlMessage l1_dl;
2608
2609 /* set a high value to ensure power decreases */
2610 f_trxc_fake_rssi(rxlev2dbm(50));
2611 f_l1_tune(L1CTL);
2612 RSL.clear;
2613
2614 var uint5_t pwr_var := 5;
2615 var uint5_t pwr_target_val := 15;
2616
2617 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2618 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2619
2620 /* establish with fixed power level */
2621 f_est_dchan(more_ies :={valueof(pwr)});
2622
2623 /* check our initial power level */
2624 f_wait_for_l1_power_level(pwr_var);
2625
2626 /* update power param to enable power loop
2627 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002628 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002629
2630 /* wait, then check that our power level was increased */
2631 timer T1 := 10.0;
2632 T1.start;
2633 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002634 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2635 /* Update sent MS power to follow what BTS requests */
2636 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2637 repeat;
2638 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002639 [] L1CTL.receive { repeat; }
2640 [] T1.timeout {
2641 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2642 setverdict(pass, "Power level in L1 header increased to lowest power value");
2643 } else {
2644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2645 "Power level in L1 header NOT increased to lowest power value");
2646 }
2647 }
2648 }
2649
2650 f_rsl_chan_deact();
2651 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2652
2653}
2654
Eric Wild095024b2019-06-17 15:08:57 +02002655/* see if we change the power level without receiving power parameters, which should not happen
2656rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002657private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002658 var L1ctlDlMessage l1_dl;
2659
2660 /* set a high value to ensure power decreases */
2661 f_trxc_fake_rssi(rxlev2dbm(50));
2662 f_l1_tune(L1CTL);
2663 RSL.clear;
2664
2665 var uint5_t pwr_var := 5;
2666
2667 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2668 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2669
2670 /* establish with fixed power level */
2671 f_est_dchan(more_ies :={valueof(pwr)});
2672
2673 /* check our initial power level */
2674 f_wait_for_l1_power_level(pwr_var);
2675
2676 /* wait, then check that our power level did not change */
2677 timer T1 := 10.0;
2678 T1.start;
2679 alt {
2680 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2681 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2683 "BS power control should not be active unless we receive a power parameters IE!");
2684 }
2685 repeat;
2686 }
2687 [] L1CTL.receive { repeat; }
2688 [] T1.timeout { setverdict(pass); }
2689 }
2690
2691 f_rsl_chan_deact();
2692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2693
2694}
2695
Eric Wild095024b2019-06-17 15:08:57 +02002696/* see if we change the power level without receiving power parameters, which should not happen
2697ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002698private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002699 var L1ctlDlMessage l1_dl;
2700
2701 /* set a high value to ensure power decreases */
2702 f_trxc_fake_rssi(rxlev2dbm(50));
2703 f_l1_tune(L1CTL);
2704 RSL.clear;
2705
2706 var uint5_t pwr_var := 5;
2707
2708 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2709 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2710
2711 /* establish with fixed power level */
2712 f_est_dchan(more_ies :={valueof(pwr)});
2713
2714 /* check our initial power level */
2715 f_wait_for_l1_power_level(pwr_var);
2716
2717 /* pwr control without power params IE, should NOT activate MS power control*/
2718 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2719
2720 /* wait, then check that our power level did not change */
2721 timer T1 := 10.0;
2722 T1.start;
2723 alt {
2724 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2725 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2727 "BS power control should not be active unless we receive a power parameters IE!");
2728 }
2729 repeat;
2730 }
2731 [] L1CTL.receive { repeat; }
2732 [] T1.timeout { setverdict(pass); }
2733 }
2734
2735 f_rsl_chan_deact();
2736 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2737
2738}
2739
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002740private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002741 var L1ctlDlMessage l1_dl;
2742 timer T0 := 10.0;
2743 T0.start;
2744 alt {
2745 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2746 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2748 "Power level in L1 header != signaled (RSL) power level.");
2749 }
2750 }
2751 [] L1CTL.receive { repeat; }
2752 [] T0.timeout {
2753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2754 "Timeout waiting for initial power level");
2755 }
2756 }
2757 T0.stop;
2758}
2759
2760private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2761 var IntegerRecord min_dbm_level;
2762 var IntegerRecord max_dbm_level;
2763 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2764
2765 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2766 if (min_dbm_level[i] == level) {
2767 return true;
2768 }
2769 }
2770 return false;
2771}
2772
2773private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2774 var IntegerRecord min_dbm_level;
2775 var IntegerRecord max_dbm_level;
2776 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2777
2778 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2779 if (max_dbm_level[i] == level) {
2780 return true;
2781 }
2782 }
2783 return false;
2784}
2785
2786private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2787 var IntegerRecord min_dbm_level;
2788 var IntegerRecord max_dbm_level;
2789 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2790 return max_dbm_level[0];
2791}
2792
2793type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002794private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002795private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2796 // 45.005 4.1.1
2797 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2798 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2799 2, 1, 0};
2800 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2801 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2802 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2803 var IntegerRecord rv;
2804
2805 select(band){
2806 case (BtsBand_allGSM){
2807 rv := gsm_power;
2808 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2809 max_dbm_level := {2, 1, 0};
2810 }
2811 case("DCS1800"){
2812 rv := dcs_power;
2813 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2814 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2815 }
2816 case("PCS1900"){
2817 rv := pcs_power;
2818 min_dbm_level := {15};
2819 max_dbm_level := {30};
2820 }
2821 }
2822
2823 return rv;
2824}
2825
2826private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2827 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2828}
2829
2830testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2831 var ConnHdlr vc_conn;
2832 var ConnHdlrPars pars;
2833 f_init();
2834 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2835 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2836 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2837 pars.bts0_band := f_vty_get_bts0_band();
2838 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2839 vc_conn.done;
2840 }
2841 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2843}
2844
2845testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2846 var ConnHdlr vc_conn;
2847 var ConnHdlrPars pars;
2848 f_init();
2849 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2850 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2851 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2852 pars.bts0_band := f_vty_get_bts0_band();
2853 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2854 vc_conn.done;
2855 }
2856 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2858}
2859
2860testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2861 var ConnHdlr vc_conn;
2862 var ConnHdlrPars pars;
2863 f_init();
2864 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2865 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2866 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2867 pars.bts0_band := f_vty_get_bts0_band();
2868 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2869 vc_conn.done;
2870 }
2871 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2873}
2874
2875testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2876 var ConnHdlr vc_conn;
2877 var ConnHdlrPars pars;
2878 f_init();
2879 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2880 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2881 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2882 pars.bts0_band := f_vty_get_bts0_band();
2883 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2884 vc_conn.done;
2885 }
2886 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2888}
2889
Eric Wild280ccb82019-06-17 11:11:52 +02002890testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2891 var ConnHdlr vc_conn;
2892 var ConnHdlrPars pars;
2893 f_init();
2894 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2895 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2896 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2897 pars.bts0_band := f_vty_get_bts0_band();
2898 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2899 vc_conn.done;
2900 }
2901 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2903}
2904
Eric Wild095024b2019-06-17 15:08:57 +02002905testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2906 var ConnHdlr vc_conn;
2907 var ConnHdlrPars pars;
2908 f_init();
2909 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2910 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2911 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2912 pars.bts0_band := f_vty_get_bts0_band();
2913 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2914 vc_conn.done;
2915 }
2916 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2918}
2919
Harald Welte70767382018-02-21 12:16:40 +01002920testcase TC_meas_res_sign_tchf() runs on test_CT {
2921 var ConnHdlr vc_conn;
2922 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002923 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002924 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2925 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002926 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2927 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002928 vc_conn.done;
2929 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002931}
2932testcase TC_meas_res_sign_tchh() runs on test_CT {
2933 var ConnHdlr vc_conn;
2934 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002935 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002936 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2937 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002938 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2939 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002940 vc_conn.done;
2941 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002943}
2944testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2945 var ConnHdlr vc_conn;
2946 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002947 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002948 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2949 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002950 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2951 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002952 vc_conn.done;
2953 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002955}
2956testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2957 var ConnHdlr vc_conn;
2958 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002959 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002960 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2961 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002962 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2963 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002964 vc_conn.done;
2965 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002967}
Harald Welte685d5982018-02-27 20:42:05 +01002968testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2969 var ConnHdlr vc_conn;
2970 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002971 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002972 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2973 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2974 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2975 pars.l1_pars.toa256_enabled := true;
2976 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2977 vc_conn.done;
2978 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002980}
2981
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002982/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2983 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002984private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002985 var L1ctlDlMessage l1_dl;
2986 var RSL_IE_MS_Power ms_power;
2987 var RSL_Message rsl;
2988 var uint5_t power_level := 0;
2989
2990 f_l1_tune(L1CTL);
2991 RSL.clear;
2992
2993 f_est_dchan();
2994
2995 ms_power.reserved := 0;
2996 ms_power.fpc_epc := false;
2997
2998 /* Send the first power control command. This will disable any BTS/TRX
2999 * internal power control and switch the MS (which is not in scope of
3000 * this test) to a constant power level. We start with a power level
3001 * of 0 */
3002 ms_power.power_level := power_level;
3003 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3004 RSL.send(rsl);
3005
3006 alt {
3007
3008 /* Pick all SACCH blocks for checking */
3009 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3010
3011 /* The first byte of the L1 header contains the power level.
3012 * The reserved bits and the fpc bit is set to 0, so we may
3013 * compare directly. */
3014 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3015 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3016 }
3017
3018 /* Signal a new power level via RSL for the next turn. */
3019 if (power_level < 31) {
3020 power_level := power_level + 1;
3021 ms_power.power_level := power_level;
3022 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3023 RSL.send(rsl);
3024 repeat;
3025 }
3026
3027 }
3028
3029 /* Ignore all other blocks */
3030 [] L1CTL.receive { repeat; }
3031
3032 }
3033
3034 f_rsl_chan_deact();
3035 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3036
3037 setverdict(pass);
3038}
3039
3040testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3041 var ConnHdlr vc_conn;
3042 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003043 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003044
3045 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3046 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3047 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3048 vc_conn.done;
3049 }
3050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3051}
Harald Welte70767382018-02-21 12:16:40 +01003052
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003053/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003054TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003055private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003056 var L1ctlDlMessage l1_dl;
3057 var uint5_t ta_to_test := 16;
3058
3059
3060 f_l1_tune(L1CTL);
3061 RSL.clear;
3062
3063 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003064 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003065
3066 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3067
3068
3069 alt {
3070
3071 /* Pick all SACCH blocks for checking */
3072 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3073
3074 /* The second byte of the L1 header contains the TA. */
3075 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3076 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3077 }
3078
3079 }
3080
3081 /* Ignore all other blocks */
3082 [] L1CTL.receive { repeat; }
3083
3084 }
3085
3086 f_rsl_chan_deact();
3087 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3088
3089 setverdict(pass);
3090}
3091
3092testcase TC_rsl_chan_initial_ta() runs on test_CT {
3093 var ConnHdlr vc_conn;
3094 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003095 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003096 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003097 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3098 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003099 vc_conn.done;
3100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3101}
3102
Eric Wilde57e1a62019-05-28 13:30:55 +02003103/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003104private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003105 var L1ctlDlMessage l1_dl;
3106 var uint5_t ms_power_level := 7;
3107
3108 var RSL_IE_MS_Power ms_power;
3109 ms_power.reserved := 0;
3110 ms_power.fpc_epc := false;
3111 ms_power.power_level := ms_power_level;
3112
3113 f_l1_tune(L1CTL);
3114 RSL.clear;
3115
3116 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3117
3118 timer T := 1.0;
3119 T.start;
3120 alt {
3121 /* Pick all SACCH blocks for checking */
3122 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3123 /* The first byte of the L1 header contains the power level.. */
3124 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3125 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3126 }
3127 }
3128 /* Ignore all other blocks */
3129 [] L1CTL.receive { repeat; }
3130 [] T.timeout {
3131 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3132 }
3133 }
3134
3135 f_rsl_chan_deact();
3136 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3137 setverdict(pass);
3138}
3139
3140testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3141 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3142 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3143}
3144
Harald Welte0472ab42018-03-12 15:02:26 +01003145/* 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 +01003146private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003147 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003148 RSL.clear;
3149
3150 f_est_dchan();
3151 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003152 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003153
3154 timer T := 40.0;
3155 T.start;
3156 alt {
3157 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3158 setverdict(pass)
3159 }
3160 [] RSL.receive { repeat };
3161 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003163 }
3164 }
3165 f_rsl_chan_deact();
3166}
3167testcase TC_conn_fail_crit() runs on test_CT {
3168 var ConnHdlr vc_conn;
3169 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003170 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003171 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3172 pars.t_guard := 60.0;
3173 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3174 vc_conn.done;
3175}
3176
Harald Welte93640c62018-02-25 16:59:33 +01003177/***********************************************************************
3178 * Paging
3179 ***********************************************************************/
3180
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003181private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003182 if (tmsi == 'FFFFFFFF'O) {
3183 return true;
3184 } else {
3185 return false;
3186 }
3187}
Harald Welte70767382018-02-21 12:16:40 +01003188
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003189private type record allowedFn { integer frame_nr }
3190private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3191private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3192private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3193private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3194private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3195private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3196private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3197private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3198private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003199{
3200 var integer frame_nr_51;
3201 frame_nr_51 := frame_nr mod 51
3202
3203 var allowedFn fn_check;
3204 fn_check.frame_nr := frame_nr_51;
3205
3206 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003208 return;
3209 }
3210
3211 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3212 return;
3213 }
3214 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3215 return;
3216 }
3217 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3218 return;
3219 }
3220 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3221 return;
3222 }
3223 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3224 return;
3225 }
3226 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3227 return;
3228 }
3229 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3230 return;
3231 }
3232 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3233 return;
3234 }
3235
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003237 return;
3238}
3239
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003240private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3241 inout integer num_paging_rcv_ids,
3242 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003243runs on test_CT {
3244 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003245 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003246 repeat;
3247 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003248 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003249 var octetstring without_plen :=
3250 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3251 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003252
3253 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3254
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003255 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3256 /* Ignore empty RR Paging Request (PCH filling) messages.
3257 * TODO: does it make sense to count them? */
3258 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003259 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3260 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003261 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003262 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3263 }
3264 } else if (match(rr, tr_PAGING_REQ2)) {
3265 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3266 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3267 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3268 }
3269 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3270 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3271 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003272 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003273 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3274 }
3275 } else if (match(rr, tr_PAGING_REQ3)) {
3276 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3277 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3278 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3279 }
3280 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3281 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3282 }
3283 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3284 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3285 }
3286 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3287 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3288 }
3289 }
3290 repeat;
3291 }
3292}
3293
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003294private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003295 boolean combined_ccch,
3296 integer bs_ag_blks_res,
3297 float load_factor,
3298 boolean exp_load_ind,
3299 boolean exp_overload,
3300 boolean use_tmsi
3301}
3302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003303private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 integer num_paging_sent,
3305 integer num_paging_rcv_msgs,
3306 integer num_paging_rcv_ids,
3307 integer num_overload
3308}
3309
Harald Welte68e495b2018-02-25 00:05:57 +01003310/* Helper function for paging related testing */
3311private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003312 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003313 f_init_l1ctl();
3314 f_l1_tune(L1CTL);
3315
3316 var PagingTestState st := {
3317 num_paging_sent := 0,
3318 num_paging_rcv_msgs := 0,
3319 num_paging_rcv_ids := 0,
3320 num_overload := 0
3321 };
3322
3323 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3324 var float max_pch_imsi_per_sec;
3325 if (cfg.use_tmsi) {
3326 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3327 } else {
3328 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3329 }
3330 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3331 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003332 var float time_total := 20.0;
3333 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3334 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003335
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003336 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3337 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003338
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003339 timer T_itv := 0.0;
3340 T_itv.start;
3341 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003342 alt {
3343 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003344 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003345 st.num_overload := st.num_overload + 1;
3346 repeat;
3347 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003348 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003350 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003351 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003352 log("Rx LOAD_IND");
3353 /* FIXME: analyze/verify interval + contents */
3354 repeat;
3355 }
3356 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003357 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003358 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003359 [] T_itv.timeout {
3360 /* Send paging cmds based on elapsed time */
3361 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3362 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003363 var MobileIdentityV mi;
3364
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003365 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003366 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003367 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003368 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003369 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003370 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003371
3372 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003373 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 +02003374
3375 st.num_paging_sent := st.num_paging_sent + 1;
3376 }
3377 if (st.num_paging_sent < pkt_total) {
3378 /* Wait for interval to next PAGING COMMAND */
3379 var float time_now := T_total.read;
3380 var float next_sched := int2float(st.num_paging_sent)*interval;
3381 if (next_sched > time_now) {
3382 T_itv.start(next_sched - time_now);
3383 } else {
3384 T_itv.start(0.0);
3385 }
3386 } else {
3387 /* We are done, no need to keep counting */
3388 T_total.stop;
3389 }
3390 }
3391 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003392 }
3393 }
3394
3395 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3396 timer T_wait := 18.0;
3397 T_wait.start;
3398 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003399 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003400 [] L1CTL.receive { repeat; }
3401 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003402 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3403 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003404 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003406 }
Harald Welte68e495b2018-02-25 00:05:57 +01003407 }
3408
3409 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3410 " rcvd_ids=", st.num_paging_rcv_ids);
3411 return st;
3412}
3413
3414/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3415 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3416 * - that CCCH LOAD IND (PCH) are being generated
3417 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3418testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003419 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003420 var PagingTestCfg cfg := {
3421 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003422 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003423 load_factor := 0.8,
3424 exp_load_ind := true,
3425 exp_overload := false,
3426 use_tmsi := false
3427 };
3428 var PagingTestState st := f_TC_paging(cfg);
3429 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3431 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003432 } else {
3433 setverdict(pass);
3434 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003436}
3437
3438/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3439 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3440 * - that CCCH LOAD IND (PCH) are being generated
3441 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3442testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003443 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003444 var PagingTestCfg cfg := {
3445 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003446 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003447 load_factor := 0.8,
3448 exp_load_ind := true,
3449 exp_overload := false,
3450 use_tmsi := true
3451 };
3452 var PagingTestState st := f_TC_paging(cfg);
3453 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3455 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003456 } else {
3457 setverdict(pass);
3458 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003460}
3461
3462/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3463 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3464 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3465 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3466testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003467 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003468 var PagingTestCfg cfg := {
3469 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003470 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003471 load_factor := 2.0,
3472 exp_load_ind := true,
3473 exp_overload := true,
3474 use_tmsi := false
3475 };
3476 var PagingTestState st := f_TC_paging(cfg);
3477 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3478 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003479 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003480 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003481 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 +01003482 } else {
3483 setverdict(pass);
3484 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003486}
3487
3488/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3489 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3490 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3491 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3492testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003493 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003494 var PagingTestCfg cfg := {
3495 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003496 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003497 load_factor := 2.0,
3498 exp_load_ind := true,
3499 exp_overload := true,
3500 use_tmsi := true
3501 };
3502 var PagingTestState st := f_TC_paging(cfg);
3503 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3504 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003505 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003506 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003507 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 +01003508 } else {
3509 setverdict(pass);
3510 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003512}
3513
3514
Harald Welte93640c62018-02-25 16:59:33 +01003515/***********************************************************************
3516 * Immediate Assignment / AGCH
3517 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003518private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003519 len := 0,
3520 ma := ''B
3521}
Harald Welte93640c62018-02-25 16:59:33 +01003522
Harald Weltee8d750e2018-06-10 21:41:35 +02003523private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3524 return int2str(num_tx) & " sent, "
3525 & int2str(num_rx) & " received, "
3526 & int2str(num_del) & " deleted";
3527}
3528
3529private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3530 var L1ctlDlMessage l1_dl;
3531 timer T := 10.0;
3532 var integer num_tx := 0;
3533 var integer num_rx := 0;
3534 var integer num_del := 0;
3535 var charstring res_str;
3536 var float rx_ratio;
3537
Harald Welte10474062019-05-30 16:48:17 +02003538 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003539 f_init_l1ctl();
3540 f_l1_tune(L1CTL);
3541
3542 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003543 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003544 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3545 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003546 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003547 num_tx := num_tx+1;
3548 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003549 }
3550 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003551 T.start;
3552 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003553 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003554 num_del := num_del+1;
3555 repeat;
3556 }
3557 [] RSL_CCHAN.receive {
3558 repeat;
3559 }
3560 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003561 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3562 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3563 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003564 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003565 } else {
3566 num_rx := num_rx+1;
3567 }
3568 repeat;
3569 }
3570 [] L1CTL.receive { repeat; }
3571 [] T.timeout { }
3572 }
3573 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3574 log("AGCH test: " & res_str);
3575 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003576 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003577 }
3578 rx_ratio := int2float(num_rx) / int2float(num_tx);
3579 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003580 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 +02003581 } else {
3582 setverdict(pass);
3583 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003585}
3586
Harald Weltee8d750e2018-06-10 21:41:35 +02003587/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3588testcase TC_imm_ass_1000_20ms() runs on test_CT {
3589 f_TC_imm_ass(1000, 0.02, 0.25);
3590}
3591
3592/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3593testcase TC_imm_ass_200_0ms() runs on test_CT {
3594 f_TC_imm_ass(200, 0.0, 0.05);
3595}
3596
3597/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3598testcase TC_imm_ass_200_76ms() runs on test_CT {
3599 f_TC_imm_ass(150, 0.076, 1.00);
3600}
3601
3602
3603
Harald Welte48494ca2018-02-25 16:59:50 +01003604/***********************************************************************
3605 * BCCH
3606 ***********************************************************************/
3607
3608/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003609private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003610 GsmFrameNumber frame_number,
3611 SystemInformation si
3612}
3613
3614/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003615private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003616
3617/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003618private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003619
3620/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003621private function f_si_vecslot_contains(SystemInformationVector arr,
3622 RrMessageType key,
3623 boolean bcch_ext := false)
3624return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003625 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3626 var integer fn_mod51 := arr[i].frame_number mod 51;
3627 if (not bcch_ext and fn_mod51 == 2 or
3628 bcch_ext and fn_mod51 == 6) {
3629 if (arr[i].si.header.message_type == key) {
3630 return true;
3631 }
3632 }
3633 }
3634 return false;
3635}
3636
3637/* 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 +07003638private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3639 integer tc, RrMessageType key,
3640 boolean ext_bcch := false)
3641{
Harald Welte48494ca2018-02-25 16:59:50 +01003642 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003644 }
3645}
3646
3647/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003648private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3649 RrMessageType key)
3650return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003651 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3652 if (f_si_vecslot_contains(arr[tc], key) or
3653 f_si_vecslot_contains(arr[tc], key, true)) {
3654 return true;
3655 }
3656 }
3657 return false;
3658}
3659
3660/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003661private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3662 RrMessageType key,
3663 boolean bcch_ext := false,
3664 integer n := 1, integer m := 4)
3665return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003666 var integer count := 0;
3667 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003669 }
3670 for (var integer i:= 0; i < m; i := i + 1) {
3671 var integer fn_mod51 := arr[i].frame_number mod 51;
3672 if (not bcch_ext and fn_mod51 == 2 or
3673 bcch_ext and fn_mod51 == 6) {
3674 if (arr[i].si.header.message_type == key) {
3675 count := count + 1;
3676 }
3677 }
3678 }
3679 if (count >= n) {
3680 return true;
3681 } else {
3682 return false;
3683 }
3684}
3685
3686/* 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 +07003687private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3688 integer tc, RrMessageType key,
3689 boolean ext_bcch := false,
3690 integer n, integer m)
3691{
Harald Welte48494ca2018-02-25 16:59:50 +01003692 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003694 }
3695}
3696
3697/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003698private function f_si_vecslot_contains_only(SystemInformationVector arr,
3699 RrMessageType key,
3700 boolean bcch_ext := false)
3701return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003702 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3703 var integer fn_mod51 := arr[i].frame_number mod 51;
3704 if (not bcch_ext and fn_mod51 == 2 or
3705 bcch_ext and fn_mod51 == 6) {
3706 if (arr[i].si.header.message_type != key) {
3707 return false;
3708 }
3709 }
3710 }
3711 return true;
3712}
3713
3714/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003715private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3716 integer tc, RrMessageType key,
3717 boolean ext_bcch := false)
3718{
Harald Welte48494ca2018-02-25 16:59:50 +01003719 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003721 }
3722}
3723
3724/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003725private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003726 boolean bcch_extended,
3727 boolean si1_present,
3728 boolean si2bis_present,
3729 boolean si2ter_present,
3730 boolean si2quater_present,
3731 boolean si7_present,
3732 boolean si8_present,
3733 boolean si9_present,
3734 boolean si13_present,
3735 boolean si13alt_present,
3736 boolean si15_present,
3737 boolean si16_present,
3738 boolean si17_present,
3739 boolean si2n_present,
3740 boolean si21_present,
3741 boolean si22_present
3742}
3743
3744/* 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 +07003745private function f_validate_si_scheduling(SystemInformationConfig cfg,
3746 SystemInformationVectorPerTc si_per_tc)
3747{
Harald Welte48494ca2018-02-25 16:59:50 +01003748 var integer i;
3749 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3750 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003752 }
3753 }
3754 if (cfg.si1_present) {
3755 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3756 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3757 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3758 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3759 /* make sure *ALL* contain SI1 */
3760 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3761 }
3762 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3763 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3764 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3765 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3766 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3767 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3768
3769 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3770 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3771 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3772 * consecutive occurrences of TC = 4. */
3773 if (cfg.si2bis_present and not cfg.si2ter_present) {
3774 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3775 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3776 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3777 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3778 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3779 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3780 }
3781
3782 if (cfg.si7_present or cfg.si8_present) {
3783 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3784 * if System Information type 4 does not contain all information needed for cell
3785 * selection and reselection. */
3786 if (not cfg.bcch_extended) {
3787 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3788 }
3789 if (cfg.si7_present) {
3790 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3791 }
3792 if (cfg.si8_present) {
3793 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3794 }
3795 }
3796
3797 if (cfg.si2quater_present) {
3798 /* iii) System information type 2 quater is sent if needed, as determined by the system
3799 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3800 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3801 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3802 * within any of 4 consecutive occurrences of TC = 5. */
3803 if (not (cfg.bcch_extended)) {
3804 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3805 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3806 } else {
3807 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3808 }
3809 } else {
3810 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3811 }
3812 }
3813 if (cfg.si9_present) {
3814 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3815 * in system information type 3 as defined in 3GPP TS 44.018. */
3816 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3817 }
3818 if (cfg.si13_present) {
3819 /* vii) System Information type 13 is only related to the GPRS service. System Information
3820 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3821 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3822 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3823 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3824 * within any of 4 consecutive occurrences of TC=4. */
3825 if (not cfg.bcch_extended) {
3826 log("not-bccch-extended");
3827 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3828 } else {
3829 log("bccch-extended");
3830 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3831 }
3832 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003834 }
3835 }
3836 if (cfg.si16_present or cfg.si17_present) {
3837 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3838 * should not be sent in a cell where network sharing is used (see rule xv). */
3839 if (cfg.si22_present) {
3840 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3841 }
3842 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003844 }
3845 if (not cfg.bcch_extended) {
3846 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3847 }
3848 if (cfg.si16_present) {
3849 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3850 }
3851 if (cfg.si17_present) {
3852 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3853 }
3854 }
3855
3856 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3857 * broadcast information. The frequency with which they are sent is determined by the
3858 * system operator. System Information type 9 identifies the scheduling of System
3859 * Information type 18 and 20 messages. */
3860
3861 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3862 * Information Type 19 is present, then its scheduling shall be indicated in System
3863 * Information Type 9. */
3864
3865 if (cfg.si15_present) {
3866 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3867 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3868 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3869 * 4 consecutive occurrences of TC = 1. */
3870 if (not cfg.bcch_extended) {
3871 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3872 } else {
3873 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3874 }
3875 }
3876 if (cfg.si13alt_present) {
3877 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3878 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3879 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3880 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3881 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3882 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3883 * of TC = 4. */
3884 if (cfg.si13_present) {
3885 testcase.stop("Error: Cannot have SI13alt and SI13");
3886 }
3887 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003889 }
3890 if (not cfg.bcch_extended) {
3891 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3892 } else {
3893 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3894 }
3895 }
3896 if (cfg.si2n_present) {
3897 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3898 * as determined by the system operator. In the case that the message is sent on the
3899 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3900 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3901 * consecutive occurrences of TC = 4. */
3902 if (not cfg.bcch_extended) {
3903 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3904 } else {
3905 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3906 }
3907 }
3908 if (cfg.si21_present) {
3909 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3910 * determined by the system operator. If Extended Access Barring is in use in the cell
3911 * then this message is sent at least once within any of 4 consecutive occurrences of
3912 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3913 * cell then this message shall only be sent on BCCH Ext. */
3914 if (not cfg.bcch_extended) {
3915 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3916 } else {
3917 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3918 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003920 }
3921 }
3922 }
3923 if (cfg.si22_present) {
3924 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3925 * should not be sent in a cell where SoLSA is used (see rule viii). System
3926 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3927 * =2 and TC=6. */
3928 if (cfg.si16_present or cfg.si17_present) {
3929 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3930 }
3931 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3932 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003934 }
3935 if (not cfg.bcch_extended) {
3936 testcase.stop("Error: SI22 requires BCCH Extd!");
3937 } else {
3938 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3939 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3940 }
3941 }
3942}
3943
3944/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003945private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3946return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003947 timer T := duration;
3948 var SystemInformationVectorPerTc si_per_tc;
3949 var L1ctlDlMessage l1_dl;
3950
3951 /* initialize all per-TC vectors empty */
3952 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3953 si_per_tc[i] := {};
3954 }
3955
3956 /* flush all previous L1 queued msgs */
3957 pt.clear;
3958
3959 T.start;
3960 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003961 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003962 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3963 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3964 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003965 repeat;
3966 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003967
Harald Welte48494ca2018-02-25 16:59:50 +01003968 var integer tc := f_gsm_compute_tc(sig.frame_number);
3969 log("SI received at TC=", tc, ": ", sig.si);
3970 /* append to the per-TC bucket */
3971 si_per_tc[tc] := si_per_tc[tc] & { sig };
3972 repeat;
3973 }
3974 [] pt.receive { repeat; }
3975 [] T.timeout { }
3976 }
3977
3978 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3979 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3980 }
3981 log("si_per_tc=", si_per_tc);
3982 return si_per_tc;
3983}
3984
3985/* helper function: Set given SI via RSL + validate scheduling.
3986 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003987private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003988 var SystemInformationVectorPerTc si_per_tc;
3989 f_init_l1ctl();
3990 f_l1_tune(L1CTL);
3991
3992 /* Sample + Validate Scheduling */
3993 si_per_tc := f_l1_sample_si(L1CTL);
3994 f_validate_si_scheduling(si_cfg, si_per_tc);
3995
3996 setverdict(pass);
3997}
3998
3999testcase TC_si_sched_default() runs on test_CT {
4000 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004001 /* 2+3+4 are mandatory and set in f_init() */
4002 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004004}
4005
4006testcase TC_si_sched_1() runs on test_CT {
4007 f_init();
4008 si_cfg.si1_present := true;
4009 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004010 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004012}
4013
4014testcase TC_si_sched_2bis() runs on test_CT {
4015 f_init();
4016 si_cfg.si2bis_present := true;
4017 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4018 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004020}
4021
4022testcase TC_si_sched_2ter() runs on test_CT {
4023 f_init();
4024 si_cfg.si2ter_present := true;
4025 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4026 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004028}
4029
4030testcase TC_si_sched_2ter_2bis() runs on test_CT {
4031 f_init();
4032 si_cfg.si2bis_present := true;
4033 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4034 si_cfg.si2ter_present := true;
4035 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4036 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004038}
4039
4040testcase TC_si_sched_2quater() runs on test_CT {
4041 f_init();
4042 si_cfg.si2quater_present := true;
4043 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4044 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004046}
4047
4048testcase TC_si_sched_13() runs on test_CT {
4049 f_init();
4050 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004051 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004052 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004054}
4055
4056testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4057 f_init();
4058 si_cfg.si2bis_present := true;
4059 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4060 si_cfg.si2ter_present := true;
4061 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4062 si_cfg.si2quater_present := true;
4063 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4064 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004065 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004066 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004068}
4069
4070
Harald Welte68e495b2018-02-25 00:05:57 +01004071testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004072 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004073 /* FIXME: enable / disable individual BCCH info */
4074 //ts_RSL_BCCH_INFO(si_type, info);
4075 /* expect no ERROR REPORT after either of them *
4076 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004078}
4079
Harald Welte93640c62018-02-25 16:59:33 +01004080/***********************************************************************
4081 * Low-Level Protocol Errors / ERROR REPORT
4082 ***********************************************************************/
4083
Harald Welte01d982c2018-02-25 01:31:40 +01004084private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4085 timer T := 5.0;
4086 T.start;
4087 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004088 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004089 setverdict(pass);
4090 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004091 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004093 }
4094 [] RSL_CCHAN.receive {
4095 repeat;
4096 }
4097 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004099 }
4100 }
4101}
4102
4103/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4104testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004105 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004106 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4107 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004108 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004109
4110 f_exp_err_rep(RSL_ERR_PROTO);
4111}
4112
4113/* Provoke a mandatory IE error and match on ERROR REPORT */
4114testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004115 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004116
4117 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4118 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004119 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004120
4121 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4122}
4123
4124/* Provoke an IE content error and match on ERROR REPORT */
4125testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004126 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004127 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4128 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004129 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004130
4131 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4132}
4133
Harald Welteee25aae2019-05-19 14:32:37 +02004134/* attempt to activate channel with wrong RSL Message Discriminator IE */
4135function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4136 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4137 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4138 RSL.send(rsl);
4139 f_rslem_unregister(0, g_chan_nr);
4140}
4141testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4142 var ConnHdlr vc_conn;
4143 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4144
Harald Welte10474062019-05-30 16:48:17 +02004145 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004146
4147 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4148 vc_conn.done;
4149 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4150
4151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4152}
4153
4154/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004155private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004156 var template (value) RSL_Message rsl_tx;
4157 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4158 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4159 RSL.send(rsl_tx);
4160 f_rslem_unregister(0, g_chan_nr);
4161}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004162private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004163 var template (value) RSL_Message rsl_tx;
4164 /* we first have to activate the dedicated channel */
4165 f_rsl_chan_act(g_pars.chan_mode);
4166 /* ... to then send an invalid RLL message */
4167 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4168 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4169 RSL.send(rsl_tx);
4170 f_rslem_unregister(0, g_chan_nr);
4171}
4172testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4173 var ConnHdlr vc_conn;
4174 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4175 var template (value) RSL_Message rsl_tx;
4176
Harald Welte10474062019-05-30 16:48:17 +02004177 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004178
4179 /* Common Channel with wrong message type */
4180 RSL_CCHAN.clear;
4181 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4182 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004183 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004184 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4185
4186 /* TRX Management */
4187 RSL_CCHAN.clear;
4188 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4189 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004190 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004191 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4192
4193 /* Dedicated Channel */
4194 RSL_CCHAN.clear;
4195 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4196 vc_conn.done;
4197 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4198
4199 /* RLL */
4200 RSL_CCHAN.clear;
4201 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4202 vc_conn.done;
4203 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4204}
4205
4206/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004207private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004208 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4209 f_rslem_unregister(0, g_chan_nr);
4210}
4211testcase TC_err_rep_wrong_sequence() runs on test_CT {
4212 var ConnHdlr vc_conn;
4213 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4214
Harald Welte10474062019-05-30 16:48:17 +02004215 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004216
4217 RSL_CCHAN.clear;
4218 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4219 vc_conn.done;
4220 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4221}
4222
Harald Welte93640c62018-02-25 16:59:33 +01004223/***********************************************************************
4224 * IPA CRCX/MDCX/DLCS media stream handling
4225 ***********************************************************************/
4226
Harald Weltea871a382018-02-25 02:03:14 +01004227/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004228private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004229 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4230 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004231}
4232testcase TC_ipa_dlcx_not_active() runs on test_CT {
4233 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004234 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004235 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4236 vc_conn.done;
4237}
Harald Welte68e495b2018-02-25 00:05:57 +01004238
Harald Weltea3f1df92018-02-25 12:49:55 +01004239/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004240private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004241 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4242 "IPA CRCX ACK");
4243 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4244 "IPA CRCX NACK");
4245}
4246testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4247 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004248 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004249 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4250 vc_conn.done;
4251}
4252
4253/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004254private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004255 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4256 "IPA CRCX ACK");
4257 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4258 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4259 var uint7_t rtp_pt2 := f_rnd_int(127);
4260 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4261 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4262 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4263 "IPA MDCX ACK");
4264 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4265 "IPA DLCX ACK");
4266}
4267testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4268 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004269 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004270 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4271 vc_conn.done;
4272}
4273
Harald Welte3ae11da2018-02-25 13:36:06 +01004274/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004275private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004276 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4277 "IPA CRCX ACK");
4278 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4279 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4280 var uint7_t rtp_pt2 := f_rnd_int(127);
4281 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
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 /* Second MDCX */
4286 remote_ip := f_rnd_int(c_UINT32_MAX);
4287 remote_port := f_rnd_int(c_UINT16_MAX);
4288 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4289 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4290 "IPA MDCX ACK");
4291 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4292 "IPA DLCX ACK");
4293}
4294testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4295 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004296 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004297 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4298 vc_conn.done;
4299}
4300
Harald Welte9912eb52018-02-25 13:30:15 +01004301/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004302private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004303 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4304 "IPA CRCX NACK");
4305}
4306testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4307 var ConnHdlrPars pars;
4308 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004309 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004310
4311 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4312 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4313 vc_conn.done;
4314
4315 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4316 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4317 vc_conn.done;
4318}
4319
Harald Weltea3f1df92018-02-25 12:49:55 +01004320
Harald Welte883340c2018-02-28 18:59:29 +01004321/***********************************************************************
4322 * PCU Socket related tests
4323 ***********************************************************************/
4324
Harald Welte07bd2d22019-05-25 11:03:30 +02004325/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004326friend 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 +01004327runs on test_CT {
4328 timer T := 3.0;
4329
4330 /* we don't expect any RTS.req before PDCH are active */
4331 T.start;
4332 alt {
4333 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004335 }
4336 [] PCU.receive { repeat; }
4337 [] T.timeout { }
4338 }
4339
4340 /* Send PDCH activate request for known PDCH timeslot */
4341 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4342
4343 /* we now expect RTS.req for this timeslot (only) */
4344 T.start;
4345 alt {
4346 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4347 setverdict(pass);
4348 }
4349 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4350 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004352 }
4353 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004355 }
4356 [] PCU.receive { repeat; }
4357 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004359 }
4360 [not exp_success] T.timeout {
4361 setverdict(pass);
4362 }
4363 }
4364}
4365
Harald Welte07bd2d22019-05-25 11:03:30 +02004366/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004367friend 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 +01004368runs on test_CT {
4369 timer T := 3.0;
4370
4371 /* Send PDCH activate request for known PDCH timeslot */
4372 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4373
4374 PCU.clear;
4375 /* we now expect no RTS.req for this timeslot */
4376 T.start;
4377 alt {
4378 [] 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 +02004379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004380 }
4381 [] PCU.receive { repeat; }
4382 [] T.timeout {
4383 setverdict(pass);
4384 }
4385 }
4386}
4387
Harald Weltead033dc2019-05-25 17:28:16 +02004388friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004389 f_init();
4390 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4391}
4392
Harald Welte883340c2018-02-28 18:59:29 +01004393/* PDCH activation via PCU socket; check for presence of RTS.req */
4394testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004395 f_init_pcu_test();
4396
Harald Welte883340c2018-02-28 18:59:29 +01004397 f_TC_pcu_act_req(0, 0, 7, true);
4398}
4399
4400/* PDCH activation via PCU socket on non-PDCU timeslot */
4401testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004402 f_init_pcu_test();
4403
Harald Welte883340c2018-02-28 18:59:29 +01004404 f_TC_pcu_act_req(0, 0, 1, false);
4405}
4406
4407/* PDCH activation via PCU socket on wrong BTS */
4408testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004409 f_init_pcu_test();
4410
Harald Welte883340c2018-02-28 18:59:29 +01004411 f_TC_pcu_act_req(23, 0, 7, false);
4412}
4413
4414/* PDCH activation via PCU socket on wrong TRX */
4415testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004416 f_init_pcu_test();
4417
Harald Welte883340c2018-02-28 18:59:29 +01004418 f_TC_pcu_act_req(0, 23, 7, false);
4419}
4420
4421/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4422testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004423 f_init_pcu_test();
4424
Harald Welte883340c2018-02-28 18:59:29 +01004425 /* Activate PDCH */
4426 f_TC_pcu_act_req(0, 0, 7, true);
4427 f_sleep(1.0);
4428 /* and De-Activate again */
4429 f_TC_pcu_deact_req(0, 0, 7);
4430}
4431
4432/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4433testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004434 f_init_pcu_test();
4435
Harald Welte883340c2018-02-28 18:59:29 +01004436 f_TC_pcu_deact_req(0, 0, 1);
4437}
4438
4439/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4440testcase TC_pcu_ver_si13() runs on test_CT {
4441 const octetstring si13 := '00010203040506070909'O;
4442 var PCUIF_send_data sd;
4443 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004444 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004445
4446 /* Set SI13 via RSL */
4447 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004448
Harald Welte883340c2018-02-28 18:59:29 +01004449 T.start;
4450 alt {
4451 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4452 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4453 setverdict(pass);
4454 } else {
4455 repeat;
4456 }
4457 }
4458 [] PCU.receive { repeat; }
4459 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004461 }
4462 }
4463}
4464
4465private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4466
4467/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004468friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004469 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4470runs on test_CT
4471{
4472 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4473 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4474}
4475
4476/* 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 +02004477friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4478 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004479runs on test_CT
4480{
4481 var PCUIF_send_data sd;
4482
4483 timer T := 3.0;
4484 T.start;
4485 alt {
4486 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4487 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4488 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4489 sd.data.u.rts_req.fn, sapi, data);
4490 }
4491 [] PCU.receive { repeat; }
4492 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004494 }
4495 }
4496}
4497
4498/* Send DATA.req on invalid BTS */
4499testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004500 var TfiUsfArr tua := f_TfiUsfArrInit();
4501 var octetstring data := '0000'O & f_rnd_octstring(21);
4502
4503 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004504
Harald Welte883340c2018-02-28 18:59:29 +01004505 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004506 f_TfiUsfArrSet(tua, 7, 0);
4507 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4508 f_sleep(1.0);
4509
4510 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004511}
4512
4513/* Send DATA.req on invalid TRX */
4514testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004515 var TfiUsfArr tua := f_TfiUsfArrInit();
4516 var octetstring data := '0000'O & f_rnd_octstring(21);
4517
4518 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004519
Harald Welte883340c2018-02-28 18:59:29 +01004520 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004521 f_TfiUsfArrSet(tua, 7, 0);
4522 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4523 f_sleep(1.0);
4524
4525 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004526}
4527
4528/* Send DATA.req on invalid timeslot */
4529testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004530 var TfiUsfArr tua := f_TfiUsfArrInit();
4531 var octetstring data := '0000'O & f_rnd_octstring(21);
4532
4533 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004534
Harald Welte883340c2018-02-28 18:59:29 +01004535 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004536 f_TfiUsfArrSet(tua, 7, 0);
4537 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4538 f_sleep(1.0);
4539
4540 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004541}
4542
4543/* Send DATA.req on timeslot that hasn't been activated */
4544testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004545 var TfiUsfArr tua := f_TfiUsfArrInit();
4546 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004547
Harald Welte7162a612019-05-26 12:56:09 +02004548 f_virtphy_common();
4549
4550 f_TfiUsfArrSet(tua, 7, 0);
4551 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4552 f_sleep(1.0);
4553
4554 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004555}
4556
Harald Weltead033dc2019-05-25 17:28:16 +02004557private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004558 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4559 boolean wait_rts := true)
4560runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004561 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004562 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004563
4564 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004565 if (wait_rts) {
4566 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4567 } else {
4568 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4569 }
Harald Weltead033dc2019-05-25 17:28:16 +02004570
4571 T.start;
4572 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004573 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004574 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4575 setverdict(pass);
4576 }
Harald Welte7162a612019-05-26 12:56:09 +02004577 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4578 setverdict(fail, "Received unexpected ", rx_dl);
4579 }
Harald Weltead033dc2019-05-25 17:28:16 +02004580 [] L1CTL.receive {
4581 repeat;
4582 }
Harald Welte7162a612019-05-26 12:56:09 +02004583 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004584 setverdict(fail, "Timeout waiting for ", data);
4585 }
Harald Welte7162a612019-05-26 12:56:09 +02004586 [not expect_data] T.timeout {
4587 setverdict(pass);
4588 }
Harald Weltead033dc2019-05-25 17:28:16 +02004589 }
4590}
4591
4592private function f_disable_dynamic_ts() runs on test_CT
4593{
4594 f_init_vty_bsc();
4595 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4596 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4597 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4598 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004599 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004600}
4601
4602private function f_virtphy_common() runs on test_CT {
4603 f_disable_dynamic_ts();
4604 f_init_l1ctl();
4605 f_l1_tune(L1CTL);
4606}
4607
4608testcase TC_pcu_data_req_pdtch() runs on test_CT {
4609 var TfiUsfArr tua := f_TfiUsfArrInit();
4610 var octetstring data := '0000'O & f_rnd_octstring(21);
4611
4612 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004613
Harald Welte883340c2018-02-28 18:59:29 +01004614 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004615 f_TfiUsfArrSet(tua, 7, 0);
4616 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4617 f_sleep(1.0);
4618
4619 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004620}
4621
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004622/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004623testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004624 var TfiUsfArr tua := f_TfiUsfArrInit();
4625 var octetstring data := '0000'O & f_rnd_octstring(21);
4626
4627 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004628
Harald Welte883340c2018-02-28 18:59:29 +01004629 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004630 f_TfiUsfArrSet(tua, 7, 0);
4631 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4632 f_sleep(1.0);
4633
4634 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004635}
4636
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004637private function f_TC_pcu_ptcch_ul(uint16_t ra)
4638runs on test_CT {
4639 var template PCUIF_Message pcu_rach_ind;
4640 var PCUIF_send_data sd;
4641 var GsmFrameNumber fn;
4642 timer T;
4643
4644 /* Send an Access Burst on PTCCH/U over the Um-interface */
4645 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4646 chan_nr := ts_RslChanNr_PDCH(7),
4647 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4648
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004649 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4650 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004651
4652 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4653 T.start(52.0 * 4.615 / 1000.0);
4654 alt {
4655 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4656 log("Rx an Access Burst on the PCU interface: ", sd.data);
4657 setverdict(pass);
4658 T.stop;
4659 }
4660 [] PCU.receive { repeat; }
4661 [] T.timeout {
4662 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4663 /* Keep going, that's not the end of the world */
4664 }
4665 }
4666}
4667
4668testcase TC_pcu_ptcch() runs on test_CT {
4669 var L1ctlDlMessage dl;
4670 var octetstring data;
4671 timer T;
4672
4673 f_init_pcu_test();
4674 f_init_l1ctl();
4675 f_l1_tune(L1CTL);
4676
4677 /* Activate PDCH channel on TS7 */
4678 f_TC_pcu_act_req(0, 0, 7, true);
4679
4680 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004681 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004682 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004683 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004684 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004685
4686 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4687 for (var integer i := 0; i < 16; i := i + 1) {
4688 log("Sending an Access Burst towards the L1CTL interface");
4689 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4690 }
4691
4692 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4693 data := f_rnd_octstring(23);
4694
4695 /* Verify PTCCH/D: send a random data block, make sure it's received */
4696 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4697 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4698
4699 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4700 * let's give it more time in case if we miss the beginning. */
4701 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4702 alt {
4703 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4704 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4705 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4706 frame := data)) -> value dl {
4707 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4708 setverdict(pass);
4709 T.stop;
4710 }
4711 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4712 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4713 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4714 l2_data := data)) -> value dl {
4715 log("Rx PTCCH/D data block on L1CTL: ", dl);
4716 setverdict(pass);
4717 T.stop;
4718 }
4719 [] L1CTL.receive { repeat; }
4720 [] T.timeout {
4721 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4722 }
4723 }
4724}
4725
Harald Welte883340c2018-02-28 18:59:29 +01004726/* Send AGCH from PCU; check it appears on Um side */
4727testcase TC_pcu_data_req_agch() runs on test_CT {
4728 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004729 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004730 f_init_l1ctl();
4731 f_l1_tune(L1CTL);
4732
4733 f_TC_pcu_act_req(0, 0, 7, true);
4734 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4735
4736 T.start;
4737 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004738 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004739 setverdict(pass);
4740 }
4741 [] L1CTL.receive { repeat; }
4742 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004744 }
4745 }
4746}
4747
Harald Welte928622b2019-05-26 13:22:59 +02004748/* Send AGCH from PCU; check it appears on Um side */
4749testcase TC_pcu_data_req_pch() runs on test_CT {
4750 timer T := 3.0;
4751 f_init_pcu_test();
4752 f_init_l1ctl();
4753 f_l1_tune(L1CTL);
4754
4755 f_TC_pcu_act_req(0, 0, 7, true);
4756 /* three characters prefix: last 3 digits of IMSI as ASCII */
4757 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4758
4759 T.start;
4760 alt {
4761 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4762 setverdict(pass);
4763 }
4764 [] L1CTL.receive { repeat; }
4765 [] T.timeout {
4766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4767 }
4768 }
4769}
4770
Harald Welte883340c2018-02-28 18:59:29 +01004771/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4772testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4773 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004774 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004775 f_init_l1ctl();
4776 f_l1_tune(L1CTL);
4777
4778 /* append 3 last imsi digits so BTS can compute pagng group */
4779 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4780
4781 timer T := 0.5;
4782 T.start;
4783 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004784 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004785 /* TODO: verify paging group */
4786 setverdict(pass);
4787 }
4788 [] L1CTL.receive { repeat; }
4789 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004791 }
4792 }
4793}
4794
4795/* Send RACH from Um side, expect it to show up on PCU socket */
4796testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004797 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004798 f_init_l1ctl();
4799 f_l1_tune(L1CTL);
4800
4801 var GsmFrameNumber fn_last := 0;
4802 for (var integer i := 0; i < 1000; i := i+1) {
4803 var OCT1 ra := f_rnd_ra_ps();
4804 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4805 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004807 }
4808 fn_last := fn;
4809
4810 timer T := 2.0;
4811 T.start;
4812 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004813 [] 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 +01004814 T.stop;
4815 }
4816 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004818 }
4819 [] PCU.receive { repeat; }
4820 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004822 }
4823 }
4824 }
4825 setverdict(pass);
4826}
4827
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004828/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4829 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4830testcase TC_pcu_ext_rach_content() runs on test_CT {
4831 var template PCUIF_Message pcu_rach_ind;
4832 var GsmFrameNumber fn_last := 0;
4833 var L1ctlRachSynchSeq synch_seq;
4834 var PCUIF_BurstType pcu_bt;
4835 var GsmFrameNumber fn;
4836 var BIT11 ra11;
4837
4838 f_init_pcu_test();
4839 f_init_l1ctl();
4840 f_l1_tune(L1CTL);
4841
4842 for (var integer i := 0; i < 1000; i := i+1) {
4843 /* We need to test both TS1 & TS2 */
4844 if (i rem 2 == 0) {
4845 synch_seq := RACH_SYNCH_SEQ_TS1;
4846 pcu_bt := BURST_TYPE_1;
4847 } else {
4848 synch_seq := RACH_SYNCH_SEQ_TS2;
4849 pcu_bt := BURST_TYPE_2;
4850 }
4851
4852 ra11 := f_rnd_ra11_ps();
4853 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4854 if (fn == fn_last) {
4855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4856 "Two RACH in same FN?!?");
4857 }
4858 fn_last := fn;
4859
4860 /* Compose the expected message */
4861 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004862 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004863 ra := bit2int(ra11),
4864 is_11bit := 1,
4865 burst_type := pcu_bt,
4866 fn := fn);
4867
4868 timer T := 2.0;
4869 T.start;
4870 alt {
4871 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4872 T.stop;
4873 }
4874 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4876 }
4877 [] PCU.receive { repeat; }
4878 [] T.timeout {
4879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4880 }
4881 }
4882 }
4883 setverdict(pass);
4884}
4885
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004886private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4887runs on test_CT {
4888 var template PCUIF_send_data sdt;
4889 var PCUIF_send_data sd;
4890 var int16_t lqual_cb;
4891 timer T := 1.0;
4892
4893 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4894 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4895
4896 /* Send a random PDTCH frame over Um */
4897 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4898 '0000'O & f_rnd_octstring(21)));
4899
4900 T.start;
4901 alt {
4902 /* If expected link quality is above the threshold */
4903 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4904 lqual_cb := sd.data.u.data_ind.lqual_cb;
4905 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4906
4907 /* Make sure the actual link quality matches the expected value */
4908 if (not match(lqual_cb, lqual_cb_exp)) {
4909 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4910 "expected value ", lqual_cb_exp));
4911 } else {
4912 setverdict(pass);
4913 }
4914 }
4915 /* If expected link quality is below the threshold */
4916 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4918 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4919 }
4920 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4921 [] PCU.receive { repeat; }
4922 [lqual_cb_exp < thresh] T.timeout {
4923 log("Rx nothing, as expected");
4924 setverdict(pass);
4925 }
4926 [lqual_cb_exp >= thresh] T.timeout {
4927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4928 "Timeout waiting for PCUIF_DATA.ind");
4929 }
4930 }
4931}
4932
4933/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4934testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4935 f_init_pcu_test();
4936 PCU.clear;
4937
4938 f_init_l1ctl();
4939 f_l1_tune(L1CTL);
4940
4941 /* Activate a PDCH channel on TS7 */
4942 f_TC_pcu_act_req(0, 0, 7, true);
4943
4944 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004945 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004946 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004947 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004948 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004949
4950 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4951 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4952 var TrxcMessage ret;
4953
4954 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4955 valueof(ts_TRXC_FAKE_CI(i)));
4956
4957 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4958 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4959 }
4960}
4961
Harald Welte883340c2018-02-28 18:59:29 +01004962/* Send PAGING via RSL, expect it to shw up on PCU socket */
4963testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004964 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004965
4966 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004967 var MobileIdentityLV mi_lv;
4968 var octetstring mi_lv_enc;
4969 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004970 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004971
Harald Welte883340c2018-02-28 18:59:29 +01004972 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004973 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004974 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004975 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004976 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004977
4978 /* Fancy encoding for PCUIF */
4979 mi_lv := valueof(ts_MI_LV(mi));
4980 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4981 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004982
4983 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004984 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004985 T.start;
4986 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004987 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004988 }
4989 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004991 }
4992 [] PCU.receive { repeat; }
4993 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004995 }
4996 }
4997 }
4998 setverdict(pass);
4999}
5000
Harald Welted66c9b82019-05-25 09:03:15 +02005001/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5002testcase TC_pcu_time_ind() runs on test_CT {
5003 var PCUIF_send_data pcu_sd;
5004 var integer num_time_ind := 0;
5005 var integer first_fn, last_fn;
5006 var float test_duration := 5.0;
5007 timer T;
5008
5009 f_init_pcu_test();
5010 f_TC_pcu_act_req(0, 0, 7, true);
5011
5012 PCU.clear;
5013 T.start(test_duration);
5014 alt {
5015 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5016 num_time_ind := num_time_ind + 1;
5017 if (not isbound(first_fn)) {
5018 first_fn := pcu_sd.data.u.time_ind.fn;
5019 }
5020 last_fn := pcu_sd.data.u.time_ind.fn;
5021 repeat;
5022 }
5023 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5024 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5025 repeat;
5026 }
5027 [] PCU.receive {
5028 repeat;
5029 }
5030 [] T.timeout {}
5031 }
5032 var integer fn_expired := last_fn - first_fn;
5033 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5034
5035 /* verify the number of frames expired matches our expectation */
5036 const float c_GSM_FN_DURATION_MS := 4.61538;
5037 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005038 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005039 if (not match(fn_expired, t_fn_expected)) {
5040 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5041 }
5042
5043 /* There are three TIME.ind in every fn MOD 13 */
5044 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5045 /* Add some tolerance */
5046 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5047 if (not match(num_time_ind, t_time_ind_exp)) {
5048 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5049 }
5050
5051 setverdict(pass);
5052}
5053
Harald Welte4832c862019-05-25 14:57:18 +02005054/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5055testcase TC_pcu_rts_req() runs on test_CT {
5056 var PCUIF_send_data pcu_sd;
5057 var integer first_fn, last_fn;
5058 var integer num_rts_pdtch := 0;
5059 var integer num_rts_ptcch := 0;
5060 var float test_duration := 5.0;
5061 timer T;
5062
5063 f_init_pcu_test();
5064 f_TC_pcu_act_req(0, 0, 7, true);
5065
5066 PCU.clear;
5067 T.start(test_duration);
5068 alt {
5069 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5070 -> value pcu_sd {
5071 num_rts_pdtch := num_rts_pdtch + 1;
5072 if (not isbound(first_fn)) {
5073 first_fn := pcu_sd.data.u.rts_req.fn;
5074 }
5075 last_fn := pcu_sd.data.u.rts_req.fn;
5076 repeat;
5077 }
5078 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5079 -> value pcu_sd {
5080 num_rts_ptcch := num_rts_ptcch + 1;
5081 if (not isbound(first_fn)) {
5082 first_fn := pcu_sd.data.u.rts_req.fn;
5083 }
5084 last_fn := pcu_sd.data.u.rts_req.fn;
5085 repeat;
5086 }
5087 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5088 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5089 repeat;
5090 }
5091 [] PCU.receive {
5092 repeat;
5093 }
5094 [] T.timeout {}
5095 }
5096 var integer fn_expired := last_fn - first_fn;
5097 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5098 ", num_rts_ptcch=", num_rts_ptcch);
5099
5100 /* verify the number of frames expired matches our expectation */
5101 const float c_GSM_FN_DURATION_MS := 4.61538;
5102 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005103 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005104 if (not match(fn_expired, t_fn_expected)) {
5105 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5106 }
5107
5108 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5109 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5110 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5111 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5112 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5113 t_ptcch_exp);
5114 }
5115
5116 /* We have 12 PDTCH blocks every 52-multiframe */
5117 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5118 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5119 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5120 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5121 t_pdtch_exp);
5122 }
5123
5124 setverdict(pass);
5125}
5126
Harald Welte07bd2d22019-05-25 11:03:30 +02005127/* test for generating Abis side OML ALERT from the PCU */
5128testcase TC_pcu_oml_alert() runs on test_CT {
5129 var PCUIF_send_data pcu_sd;
5130 var integer num_time_ind := 0;
5131 var integer first_fn, last_fn;
5132 var float test_duration := 5.0;
5133 timer T;
5134
5135 f_init_pcu_test();
5136 f_TC_pcu_act_req(0, 0, 7, true);
5137
5138 /* re-connect CTRL port from BTS to BSC */
5139 f_ipa_ctrl_stop();
5140 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5141
5142 /* Send that OML Alert */
5143 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5144
5145 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5146 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5147 setverdict(pass);
5148}
5149
Harald Welteeaa9a862019-05-26 23:01:08 +02005150/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5151private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5152 var PCUIF_Message first_info;
5153 var integer pcu_conn_id := -1;
5154 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5155 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5156 var OCT4 tlli := '01020304'O;
5157 var OCT1 cause := '23'O;
5158 timer T := 5.0;
5159
5160 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5161
5162 f_l1_tune(L1CTL);
5163 RSL.clear;
5164
5165 f_est_dchan();
5166 L1CTL.clear;
5167
5168 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5169
5170 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5171 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5172 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5173
5174 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5175 T.start;
5176 alt {
5177 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5178 setverdict(pass);
5179 }
5180 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5181 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5182 }
5183 [] PCU.receive {
5184 repeat;
5185 }
5186 [] T.timeout {
5187 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5188 }
5189 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005190
5191 /* release the channel */
5192 f_rsl_chan_deact();
5193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5194 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005195}
5196testcase TC_pcu_rr_suspend() runs on test_CT {
5197 var ConnHdlrPars pars;
5198 var ConnHdlr vc_conn;
5199
5200 f_init();
5201
5202 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5203 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5204 vc_conn.done;
5205}
Harald Welte07bd2d22019-05-25 11:03:30 +02005206
Harald Weltea2e0e942019-05-27 18:12:53 +02005207/* Ensure that PCUIF socket can accept only a single connection */
5208testcase TC_pcu_socket_connect_multi() runs on test_CT {
5209 timer T := 5.0;
5210
5211 /* this (among other things) establishes the first connection to the PCUIF socket */
5212 f_init();
5213
5214 /* try to establish a second connection, expect it to fail */
5215 PCU.send(UD_connect:{mp_pcu_socket, -1});
5216 T.start;
5217 alt {
5218 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5219 setverdict(pass);
5220 }
5221 [] PCU.receive(UD_connect_result:?) {
5222 setverdict(fail, "Unexpected unix domain connect result");
5223 }
5224 [] T.timeout {
5225 setverdict(pass);
5226 }
5227 }
5228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5229}
5230
Harald Weltec8effb72019-05-27 18:23:04 +02005231/* Ensure that PCUIF socket can disconnect + reconnect */
5232testcase TC_pcu_socket_reconnect() runs on test_CT {
5233 /* this (among other things) establishes the first connection to the PCUIF socket */
5234 f_init();
5235
5236 f_sleep(1.0);
5237
5238 f_pcuif_close(PCU, g_pcu_conn_id);
5239 g_pcu_conn_id := -1;
5240
5241 f_sleep(1.0);
5242
5243 /* re-connect */
5244 PCU.clear;
5245 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5246 setverdict(pass);
5247
5248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5249}
5250
Harald Weltebe030482019-05-27 22:29:35 +02005251/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005252private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5253runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005254 var L1ctlDlMessage l1_dl;
5255 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005256 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005257 timer T := 5.0;
5258 T.start;
5259 alt {
5260 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005261 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5262 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005263 repeat;
5264 }
5265 }
5266 [] pt.receive {
5267 repeat;
5268 }
5269 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5271 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005272 }
5273 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005274 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005275}
5276
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005277/* Check if GPRS Indicator is present in RR System Information of a given type */
5278private function f_si_has_gprs_indicator(RrMessageType si_type)
5279runs on test_CT return boolean {
5280 var SystemInformation si := f_get_si(L1CTL, si_type);
5281
5282 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005283 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005284 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005285 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005286 }
5287
5288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5289 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005290}
5291
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005292/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5293private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5294runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005295 /* don't call f_init() as this would connect PCU socket */
5296 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005297
5298 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005299 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005300 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005301
5302 f_init_l1ctl();
5303 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005304 f_sleep(2.0);
5305 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005306
5307 if (f_si_has_gprs_indicator(si_type)) {
5308 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005309 } else {
5310 setverdict(pass);
5311 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005312
Harald Weltebe030482019-05-27 22:29:35 +02005313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5314}
5315
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005316testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5317 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5318}
Harald Weltebe030482019-05-27 22:29:35 +02005319
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005320testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5321 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5322}
5323
5324/* Ensure that GPRS capability is advertised after PCU socket connect */
5325private function f_TC_pcu_socket_connect(RrMessageType si_type)
5326runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005327 /* this (among other things) establishes the first connection to the PCUIF socket */
5328 f_init();
5329 f_init_l1ctl();
5330 f_l1_tune(L1CTL);
5331
5332 f_sleep(2.0);
5333 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005334
5335 if (not f_si_has_gprs_indicator(si_type)) {
5336 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005337 } else {
5338 setverdict(pass);
5339 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005340
Harald Weltebe030482019-05-27 22:29:35 +02005341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5342}
5343
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005344testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5345 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5346}
Harald Weltebe030482019-05-27 22:29:35 +02005347
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005348testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5349 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5350}
5351
5352/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5353private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5354runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005355 /* this (among other things) establishes the first connection to the PCUIF socket */
5356 f_init();
5357 f_init_l1ctl();
5358 f_l1_tune(L1CTL);
5359
5360 f_pcuif_close(PCU, g_pcu_conn_id);
5361 g_pcu_conn_id := -1;
5362
5363 f_sleep(1.0);
5364
5365 /* re-connect */
5366 PCU.clear;
5367 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5368
5369 f_sleep(2.0);
5370 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005371
5372 if (f_si_has_gprs_indicator(si_type)) {
5373 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005374 } else {
5375 setverdict(pass);
5376 }
5377
5378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5379}
5380
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005381testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5382 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5383}
5384
5385testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5386 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5387}
5388
Oliver Smithf5239c72019-08-28 10:01:25 +02005389/* 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) */
5390testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5391 var SystemInformation si3 := valueof(ts_SI3_default);
5392
5393 f_init();
5394
Harald Welte76220222020-10-11 20:32:44 +02005395 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5396 * information */
5397 timer T := 2.0;
5398 T.start;
5399 alt {
5400 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5401 [] T.timeout {}
5402 }
5403
Oliver Smithf5239c72019-08-28 10:01:25 +02005404 /* Verify cell_id */
5405 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5406 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5407 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005408 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5409 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5410 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005411 }
5412
5413 /* Verify LAC */
5414 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5415 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5416 if (lac_si3 != lac_pcu) {
5417 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5418 }
5419
5420 setverdict(pass);
5421}
Harald Welted66c9b82019-05-25 09:03:15 +02005422
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005423/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5424testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5425 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005426 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005427
5428 f_init();
5429
5430 info_ind := g_pcu_last_info.u.info_ind;
5431
5432 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5433 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5434 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5435 /* Skip inactive timeslots */
5436 continue;
5437 }
5438
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005439 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005440 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005441 else
5442 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005443
5444 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005445 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005446 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005447 hsn := fhp.maio_hsn.hsn,
5448 maio := fhp.maio_hsn.maio,
5449 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005450 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005451 } else {
5452 tr_ts := tr_PCUIF_InfoTrxTsH0;
5453 }
5454
5455 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5456 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5457 if (not match(ts, tr_ts)) {
5458 setverdict(fail, "Hopping parameters do not match: ",
5459 "received ", ts, " vs expected ", tr_ts);
5460 } else {
5461 setverdict(pass);
5462 }
5463 }
5464 }
5465}
5466
Alexander Couzens5283f552020-07-28 15:39:04 +02005467/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5468testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5469 f_init_vty_bsc();
5470 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5471 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5472
5473 f_init();
5474
5475 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5476 if (not ischosen(remote_addr.v10)) {
5477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5478 log2str("Unexpected remote_addr: ", remote_addr));
5479 }
5480
5481 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5482 setverdict(fail, "Received address family is not IPv4");
5483 }
5484
5485 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5486 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5487 }
5488
5489 setverdict(pass);
5490}
5491
5492/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5493testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5494 f_init_vty_bsc();
5495 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5496
5497 f_init();
5498
5499 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5500 if (not ischosen(remote_addr.v10)) {
5501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5502 log2str("Unexpected remote_addr: ", remote_addr));
5503 }
5504
5505 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5506 setverdict(fail, "Received address family is not IPv6");
5507 }
5508
5509 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5510 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5511 }
5512
5513 setverdict(pass);
5514}
5515
Harald Welte3d04ae62018-04-04 20:29:05 +02005516/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005517 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005518 ***********************************************************************/
5519
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005520private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5521 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005522runs on ConnHdlr {
5523 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005524
5525 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005526 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005527 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5528 repeat;
5529 }
5530 }
5531}
5532
5533private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5534runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005535 /* Expect BTS to immediately acknowledge activation as PDCH */
5536 PCU.clear;
5537 f_rsl_chan_act(g_pars.chan_mode);
5538 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005539 timer T_wait := 2.0;
5540 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005541 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005542 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005543 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005544 [] T_wait.timeout {
5545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5546 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5547 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005548 }
5549 /* try to activate this PDCH from the PCU point of view */
5550 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5551 /* FIXME: is there a response? */
5552}
5553
5554private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5555runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005556 /* Send RSL CHAN REL (deactivate) */
5557 PCU.clear;
5558 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5559 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005560 timer T_wait := 2.0;
5561 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005562 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005563 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005564 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005565 [] T_wait.timeout {
5566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5567 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5568 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005569 }
5570 /* Emulate PCU asking BTS to deactivate PDCH */
5571 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5572 alt {
5573 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5574 setverdict(pass);
5575 }
5576 [] RSL.receive { repeat; }
5577 }
5578}
5579
5580/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005581private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005582 var PCUIF_Message first_info;
5583 var integer ts_nr := g_chan_nr.tn;
5584 var integer trx_nr := 0;
5585 var integer bts_nr := 0;
5586 var integer pcu_conn_id := -1;
5587
5588 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5589
5590 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5591 f_sleep(3.0);
5592 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5593 setverdict(pass);
5594}
5595testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5596 var ConnHdlrPars pars;
5597 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005598 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005599
5600 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5601 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5602 vc_conn.done;
5603}
5604
5605/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005606private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005607 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005608 var integer pcu_conn_id := -1;
5609
5610 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5611
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005612 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5613 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5614 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005615 setverdict(pass);
5616}
5617testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5618 var ConnHdlrPars pars;
5619 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005620 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005621
5622 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5623 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5624 vc_conn.done;
5625}
5626
5627/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005628private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005629 var PCUIF_Message first_info;
5630 var integer ts_nr := g_chan_nr.tn;
5631 var integer trx_nr := 0;
5632 var integer bts_nr := 0;
5633 var integer pcu_conn_id := -1;
5634
5635 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5636
5637 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005638 /* Send a second Chan Activ and expect it to be NACKed */
5639 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5640 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005641 setverdict(pass);
5642}
5643testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5644 var ConnHdlrPars pars;
5645 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005646 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005647
5648 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5649 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5650 vc_conn.done;
5651}
5652
5653/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005654private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005655 var PCUIF_Message first_info;
5656 var integer ts_nr := g_chan_nr.tn;
5657 var integer trx_nr := 0;
5658 var integer bts_nr := 0;
5659 var integer pcu_conn_id := -1;
5660 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5661
5662 /* register for the TCH/F channel number */
5663 f_rslem_register(0, chan_nr);
5664
5665 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5666
5667 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5668 "RSL CHAN ACT");
5669 setverdict(pass);
5670}
5671testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5672 var ConnHdlrPars pars;
5673 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005674 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005675
5676 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5677 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5678 vc_conn.done;
5679}
5680
5681/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005682private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005683 var PCUIF_Message first_info;
5684 var integer ts_nr := g_chan_nr.tn;
5685 var integer trx_nr := 0;
5686 var integer bts_nr := 0;
5687 var integer pcu_conn_id := -1;
5688 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5689 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5690
5691 /* register for the TCH/H channel numbers */
5692 f_rslem_register(0, chan_nr[0]);
5693 f_rslem_register(0, chan_nr[1]);
5694
5695 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5696
5697 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5698 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5699 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5700 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5701 setverdict(pass);
5702}
5703testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5704 var ConnHdlrPars pars;
5705 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005706 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005707
5708 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5709 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5710 vc_conn.done;
5711}
5712
Harald Welte9bbbfb52018-04-05 09:33:19 +02005713/***********************************************************************
5714 * IPA Style Dynamic Timeslot Support
5715 ***********************************************************************/
5716
5717private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5718runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005719 /* Expect BTS to immediately acknowledge activation as PDCH */
5720 PCU.clear;
5721 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5722 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005723 timer T_wait := 2.0;
5724 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005725 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005726 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005727 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005728 [] T_wait.timeout {
5729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5730 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5731 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005732 }
5733 /* try to activate this PDCH from the PCU point of view */
5734 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5735 /* FIXME: is there a response? */
5736
5737 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5738}
5739
5740private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5741runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005742 /* Send RSL CHAN REL (deactivate) */
5743 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5744 PCU.clear;
5745 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005746 timer T_wait := 2.0;
5747 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005748 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005749 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005750 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005751 [] T_wait.timeout {
5752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5753 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5754 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005755 }
5756 /* Emulate PCU asking BTS to deactivate PDCH */
5757 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5758 alt {
5759 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5760 setverdict(pass);
5761 }
5762 [] RSL.receive { repeat; }
5763 }
5764}
5765
5766/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005767private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005768 var PCUIF_Message first_info;
5769 var integer ts_nr := g_chan_nr.tn;
5770 var integer trx_nr := 0;
5771 var integer bts_nr := 0;
5772 var integer pcu_conn_id := -1;
5773
5774 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5775
5776 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5777 f_sleep(3.0);
5778 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5779
5780 setverdict(pass);
5781
5782}
5783testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5784 var ConnHdlrPars pars;
5785 var ConnHdlr vc_conn;
5786 f_init();
5787
5788 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5789 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5790 vc_conn.done;
5791}
5792
5793/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005794private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005795 var PCUIF_Message first_info;
5796 var integer ts_nr := g_chan_nr.tn;
5797 var integer trx_nr := 0;
5798 var integer bts_nr := 0;
5799 var integer pcu_conn_id := -1;
5800
5801 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5802
5803 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5804 "RSL CHAN ACT");
5805 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5806 "RF CHAN REL", true);
5807 setverdict(pass);
5808}
5809testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5810 var ConnHdlrPars pars;
5811 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005812 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005813
5814 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5815 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5816 vc_conn.done;
5817}
5818
5819/* 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 +07005820private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005821 var PCUIF_Message first_info;
5822 var integer ts_nr := g_chan_nr.tn;
5823 var integer trx_nr := 0;
5824 var integer bts_nr := 0;
5825 var integer pcu_conn_id := -1;
5826
5827 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5828
5829 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5830 "RSL CHAN ACT");
5831
5832 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5833 alt {
5834 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5835 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005837 }
5838 [] RSL.receive { repeat; }
5839 }
5840
5841 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5842 "RF CHAN REL", true);
5843 setverdict(pass);
5844}
5845testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5846 var ConnHdlrPars pars;
5847 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005848 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005849
5850 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5851 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5852 vc_conn.done;
5853}
5854
5855/* 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 +07005856private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005857 var PCUIF_Message first_info;
5858 var integer ts_nr := g_chan_nr.tn;
5859 var integer trx_nr := 0;
5860 var integer bts_nr := 0;
5861 var integer pcu_conn_id := -1;
5862
5863 /* register for the TCH/F channel number */
5864 f_rslem_register(0, g_chan_nr);
5865
5866 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5867
5868 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5869
5870 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5871 "RSL CHAN ACT");
5872
5873 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5874
5875 setverdict(pass);
5876}
5877testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5878 var ConnHdlrPars pars;
5879 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005880 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005881
5882 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5883 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5884 vc_conn.done;
5885}
5886
5887
Harald Welte0472ab42018-03-12 15:02:26 +01005888/***********************************************************************
5889 * LAPDm / RLL related
5890 ***********************************************************************/
5891
5892private function f_tx_lapdm(template (value) LapdmFrame l,
5893 template (value) RslLinkId link_id) runs on ConnHdlr {
5894 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005895 var template (value) SacchL1Header l1h;
5896
5897 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005898 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005899 /* Compose dummy L1 header */
5900 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5901 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 +02005902 } else {
5903 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005904 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 +01005905 }
Harald Welte0472ab42018-03-12 15:02:26 +01005906}
5907
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005908private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005909 uint3_t sapi,
5910 RslLinkId link_id,
5911 octetstring l3,
5912 boolean exp
5913}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005914private type record of RllTestCase RllTestCases;
5915private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5916 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005917 sapi := sapi,
5918 link_id := id,
5919 l3 := l3,
5920 exp := exp
5921}
5922
5923/* execute the same callback function with a set of different parameters (tcs) on a
5924 * variety of logical channels */
5925private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5926 var ConnHdlrPars pars;
5927 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005928 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005929
5930 /* test on each of the channels we have */
5931 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5932 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5933
5934 /* test each of the test cases on the current channel */
5935 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5936 pars.spec.rll := tcs[j];
5937 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5938 vc_conn := f_start_handler(fn, pars);
5939 vc_conn.done;
5940 }
5941 }
5942
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005944}
5945
5946/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5947private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5948 var RllTestCase tc := g_pars.spec.rll;
5949 timer T := 3.0;
5950
5951 f_l1_tune(L1CTL);
5952 RSL.clear;
5953
5954 /* activate the logical channel */
5955 f_est_dchan();
5956 L1CTL.clear;
5957
5958 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5959 T.start;
5960 alt {
5961 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5962 if (tc.exp) {
5963 setverdict(pass);
5964 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005966 }
5967 }
5968 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5969 if (tc.exp) {
5970 setverdict(pass);
5971 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005973 }
5974 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005975 /* We also expect to receive the measurements */
5976 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005977 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005979 }
5980 [not tc.exp] T.timeout {
5981 setverdict(pass);
5982 }
5983 }
5984
5985 f_rsl_chan_deact();
5986 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5987 f_rslem_unregister(0, g_chan_nr);
5988}
5989testcase TC_rll_est_ind() runs on test_CT {
5990 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005991 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005992 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005993 /* normal SAPI0 establishment */
5994 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005995 /* SAPI 3 doesn't support contention resolution */
5996 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5997 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5998 /* normal SAPI3 establishment on main DCCH */
5999 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6000 /* normal SAPI3 establishment on SACCH */
6001 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6002 };
6003 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6004}
6005
6006/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6007private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6008 var RllTestCase tc := g_pars.spec.rll;
6009 var L1ctlDlMessage dl;
6010 timer T := 3.0;
6011
6012 f_l1_tune(L1CTL);
6013 RSL.clear;
6014
6015 /* activate the logical channel */
6016 f_est_dchan();
6017 L1CTL.clear;
6018
6019 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6020 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6021 T.start;
6022 alt {
6023 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6024 var LapdmFrame lapdm;
6025 var octetstring l2 := dl.payload.data_ind.payload;
6026 if (dl.dl_info.link_id.c == SACCH) {
6027 /* remove L1 header */
6028 l2 := substr(l2, 2, lengthof(l2)-2);
6029 }
6030 lapdm.ab := dec_LapdmFrameAB(l2);
6031 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6032 setverdict(pass);
6033 } else {
6034 repeat;
6035 }
6036 }
6037 [] L1CTL.receive { repeat; }
6038 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006040 }
6041 }
6042
6043 f_rsl_chan_deact();
6044 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6045 f_rslem_unregister(0, g_chan_nr);
6046}
6047testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6048 var RllTestCases tcs := {
6049 /* normal SAPI3 establishment on main DCCH */
6050 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6051 };
6052 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6053}
6054testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6055 var RllTestCases tcs := {
6056 /* normal SAPI3 establishment on SACCH */
6057 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6058 }
6059 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6060}
6061
6062/* altstep to receive a LAPDm frame matching the given template */
6063private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6064 var L1ctlDlMessage dl;
6065 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6066 var LapdmFrame lapdm;
6067 var octetstring l2 := dl.payload.data_ind.payload;
6068 if (dl.dl_info.link_id.c == SACCH) {
6069 /* remove L1 header */
6070 l2 := substr(l2, 2, lengthof(l2)-2);
6071 }
6072 if (ischosen(exp.ab)) {
6073 lapdm.ab := dec_LapdmFrameAB(l2);
6074 } else if (ischosen(exp.b4)) {
6075 lapdm.b4 := dec_LapdmFrameB4(l2);
6076 } else if (ischosen(exp.bbis)) {
6077 lapdm.bbis := dec_LapdmFrameBbis(l2);
6078 }
6079 log("Rx LAPDm ", lapdm);
6080 if (match(lapdm, exp)) {
6081 setverdict(pass);
6082 } else {
6083 repeat;
6084 }
6085 }
6086 [] L1CTL.receive { repeat; }
6087}
6088private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6089 timer T := t;
6090 T.start;
6091 alt {
6092 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006094 }
6095 [] as_l1_exp_lapdm(exp);
6096 }
6097}
6098
6099/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6100private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6101 /* send SABM from MS -> BTS */
6102 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6103 /* expect RLL EST IND on Abis */
6104 alt {
6105 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6106 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6107 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006109 }
6110 [] RSL.receive { repeat; }
6111 }
6112 /* expect UA from BTS -> MS */
6113 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6114}
6115
6116/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6117private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6118 var RllTestCase tc := g_pars.spec.rll;
6119
6120 f_l1_tune(L1CTL);
6121 RSL.clear;
6122
6123 /* activate the logical channel */
6124 f_est_dchan();
6125 L1CTL.clear;
6126
6127 /* first establish the link-layer */
6128 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6129
6130 /* then send the DISC */
6131 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6132 /* ... and expect the REL IND on the RSL side */
6133 alt {
6134 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6135 setverdict(pass);
6136 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006137 /* We also expect to receive the measurements */
6138 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006139 }
6140
6141 /* release the channel */
6142 f_rsl_chan_deact();
6143 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6144 f_rslem_unregister(0, g_chan_nr);
6145}
6146testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6147 var RllTestCases tcs := {
6148 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6149 };
6150 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6151}
6152
6153testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6154 var RllTestCases tcs := {
6155 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6156 };
6157 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6158}
6159testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6160 var RllTestCases tcs := {
6161 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6162 };
6163 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6164}
6165testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6166 var RllTestCases tcs := {
6167 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6168 };
6169 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6170}
6171
6172/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6173private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6174 var RllTestCase tc := g_pars.spec.rll;
6175 f_l1_tune(L1CTL);
6176 RSL.clear;
6177
6178 /* activate the logical channel */
6179 f_est_dchan();
6180 L1CTL.clear;
6181
6182 /* first establish the link-layer */
6183 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6184
6185 /* then send the REL REQ via RSL */
6186 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6187 /* ... and expect the DISC on the Um side */
6188 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006189 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006190 /* FIXME: send a UA in resposne to the DISC */
6191 }
6192 }
6193
6194 /* release the channel */
6195 f_rsl_chan_deact();
6196 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6197 f_rslem_unregister(0, g_chan_nr);
6198}
6199testcase TC_rll_rel_req() runs on test_CT {
6200 var RllTestCases tcs := {
6201 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6202 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6203 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6204 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6205 };
6206 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6207}
6208
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006209/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006210testcase TC_rll_data_req() runs on test_CT {
6211}
6212
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006213/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006214testcase TC_rll_data_ind() runs on test_CT {
6215}
6216
6217/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6218private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6219 var RllTestCase tc := g_pars.spec.rll;
6220
6221 f_l1_tune(L1CTL);
6222 RSL.clear;
6223
6224 f_est_dchan();
6225 L1CTL.clear;
6226
6227 /* Send UNITDATA REQ on RSL side */
6228 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6229 /* Expect it to arrive on the other side */
6230 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006231 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006232 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006233 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006234 }
6235
6236 /* release the channel */
6237 f_rsl_chan_deact();
6238 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6239 f_rslem_unregister(0, g_chan_nr);
6240}
6241testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6242 var octetstring l3 := f_rnd_octstring(15);
6243 var RllTestCases tcs := {
6244 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6245 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6246 };
6247 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6248}
6249testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6250 var octetstring l3 := f_rnd_octstring(19);
6251 var RllTestCases tcs := {
6252 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6253 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6254 };
6255 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6256}
6257
6258/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6259private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6260 var RllTestCase tc := g_pars.spec.rll;
6261
6262 f_l1_tune(L1CTL);
6263 RSL.clear;
6264
6265 f_est_dchan();
6266 L1CTL.clear;
6267
6268 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006269 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006270 /* Expdct RLL UNITDATA IND on RSL side */
6271 alt {
6272 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6273 setverdict(pass);
6274 }
6275 [] RSL.receive { repeat; }
6276 }
6277
6278 /* release the channel */
6279 f_rsl_chan_deact();
6280 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6281 f_rslem_unregister(0, g_chan_nr);
6282}
6283testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006284 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006285 var RllTestCases tcs := {
6286 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6287 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6288 };
6289 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6290}
6291testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6292 var octetstring l3 := f_rnd_octstring(18);
6293 var RllTestCases tcs := {
6294 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6295 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6296 };
6297 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6298}
6299
Harald Weltee613f962018-04-18 22:38:16 +02006300/***********************************************************************
6301 * Encryption Related
6302 ***********************************************************************/
6303
6304/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006305private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006306 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6307 if (link_id.c == SACCH) {
6308 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6309 } else {
6310 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6311 }
6312}
6313
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006314/* Expect (or not expect) other kinds of messages */
6315private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6316 [exp_any] RSL.receive { repeat; }
6317 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006319 }
6320}
6321
Harald Weltee613f962018-04-18 22:38:16 +02006322/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006323private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006324 RslLinkId link_id,
6325 octetstring l3,
6326 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006327 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006328) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006329 timer T := 3.0;
6330 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6331 T.start;
6332 /* Expect RLL UNITDATA IND on RSL side */
6333 alt {
6334 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6335 setverdict(pass);
6336 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006337 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006338 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006339 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006341 }
Harald Weltee613f962018-04-18 22:38:16 +02006342 }
6343}
6344
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006345/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6346private function f_data_mo(
6347 RslLinkId link_id,
6348 boolean p, uint3_t nr, uint3_t ns,
6349 octetstring l3,
6350 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006351 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006352) runs on ConnHdlr {
6353 timer T := 3.0;
6354 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6355 T.start;
6356 /* Expect RLL DATA IND on RSL side */
6357 alt {
6358 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6359 setverdict(pass);
6360 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006361 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006362 [] as_rsl_any_ind(exp_any);
6363 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006365 }
6366 }
6367}
6368
Harald Weltee613f962018-04-18 22:38:16 +02006369/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006370private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006371 f_l1_tune(L1CTL);
6372 f_est_dchan(true);
6373
6374 /* now we actually need to transmit some data both ways to check if the encryption works */
6375 var L1ctlDlMessage dl;
6376
Stefan Sperling603d98e2018-07-25 16:47:28 +02006377 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006378 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6379
6380 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6381 f_unitdata_mt(link_id, l3);
6382
6383 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6384 f_unitdata_mo(link_id, l3);
6385
6386 /* release the channel */
6387 f_rsl_chan_deact();
6388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6389 f_rslem_unregister(0, g_chan_nr);
6390}
6391testcase TC_chan_act_a51() runs on test_CT {
6392 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6393 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6394 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6395}
6396testcase TC_chan_act_a52() runs on test_CT {
6397 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6398 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6399 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6400}
6401testcase TC_chan_act_a53() runs on test_CT {
6402 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6403 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6404 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6405}
6406
Eric Wildf1827a72019-05-28 17:37:35 +02006407/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6408 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 +07006409private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006410 f_l1_tune(L1CTL);
6411 f_est_dchan(true);
6412
6413 /* now we actually need to transmit some data both ways to check if the encryption works */
6414 var L1ctlDlMessage dl;
6415
6416 var octetstring l3 := f_rnd_octstring(20);
6417 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6418
6419 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6420 f_unitdata_mt(link_id, l3);
6421
6422 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6423 f_unitdata_mo(link_id, l3);
6424
6425 var RSL_Message rsl;
6426 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6427
6428 /* modify key to break proper encryption */
6429 g_pars.encr.key := f_rnd_octstring(8);
6430 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6431 rsl.ies := rsl.ies & { ei };
6432 RSL.send(rsl);
6433
6434 timer T0 := 1.0;
6435 T0.start;
6436 /* Expect RSL MODIFY ACK */
6437 alt {
6438 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6439 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6441 }
6442 [] T0.timeout {
6443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6444 }
6445 }
6446
6447 var octetstring l3msg := f_rnd_octstring(15);
6448 timer T1 := 3.0;
6449 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6450 due to broken encryption */
6451 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6452 T1.start;
6453 alt {
6454 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6456 }
6457 [] T1.timeout {
6458 setverdict(pass);
6459 }
6460 }
6461
6462 /* release the channel */
6463 f_rsl_chan_deact();
6464 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6465 f_rslem_unregister(0, g_chan_nr);
6466}
6467testcase TC_rsl_modify_encr() runs on test_CT {
6468 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6469 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6470 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6471}
Harald Weltee613f962018-04-18 22:38:16 +02006472
6473/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006474private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006475 /* L3 payload doesn't matter, as it is passed transparently */
6476 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6477 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6478 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6479
6480 f_l1_tune(L1CTL);
6481
6482 /* first establish a dedicated channel in the clear */
6483 f_est_dchan(false);
6484
6485 /* Establish ABM */
6486 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6487
6488 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6489 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6490 /* expect the L3 to arrive still unencrypted on the MS side */
6491 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6492
6493 /* configure L1 to apply ciphering */
6494 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6495 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6496
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006497 /* send first ciphered I-frame in response and expect it on RSL */
6498 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006499
6500 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6501 * and hence enable encryption also on the downlink */
6502
6503 /* expect bi-directional communication work in encrypted mode */
6504 f_unitdata_mo(link_id, f_rnd_octstring(15));
6505 f_unitdata_mt(link_id, f_rnd_octstring(15));
6506
6507 /* release the channel */
6508 f_rsl_chan_deact();
6509 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6510 f_rslem_unregister(0, g_chan_nr);
6511}
6512testcase TC_encr_cmd_a51() runs on test_CT {
6513 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6514 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6515 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6516}
6517testcase TC_encr_cmd_a52() runs on test_CT {
6518 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6519 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6520 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6521}
6522testcase TC_encr_cmd_a53() runs on test_CT {
6523 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6524 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6525 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6526}
6527
6528private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6529 var LapdmFrame lf;
6530 var octetstring reenc;
6531
6532 /* decode the LAPDm frame */
6533 if (ischosen(exp_match.ab)) {
6534 lf.ab := dec_LapdmFrameAB(enc);
6535 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006537 }
6538
6539 /* check if decoder result matches expectation */
6540 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006542 } else {
6543 log(name, ": matched");
6544 setverdict(pass);
6545 }
6546
6547 /* test if re-encoded frame equals original input */
6548 reenc := enc_LapdmFrame(lf);
6549 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006551 } else {
6552 setverdict(pass);
6553 }
6554}
6555
6556testcase TC_lapdm_selftest() runs on test_CT {
6557 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6558 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6559 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6560 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6561 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6562 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6563 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6564}
6565
Stefan Sperling4880be42018-08-07 18:12:59 +02006566/***********************************************************************
6567 * DTX Related (see GSM 05.08, section 8.3)
6568 ***********************************************************************/
6569
6570/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006571private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006572 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6573 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6574 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6575 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6576}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006577private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006578 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6579 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6580}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006581private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006582 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6583 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6584 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6585 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6586}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006587private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006588 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6589 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6590 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6591 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6592 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6593 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6594 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6595 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6596}
6597
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006598private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 var L1ctlDlMessage dl;
6600 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6601 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6602 var GsmFrameNumber first_fn;
6603 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006604 var integer nfill_frames_sacch := 0;
6605 var integer nfill_frames_nonsacch := 0;
6606 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006607 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6608 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006609 const integer frame_dtx_tchf_mod := 104;
6610 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6611 * which operates in terms of blocks rather than frames. */
6612 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6613 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006614 timer T := 5.0;
6615
6616 f_l1_tune(L1CTL);
6617 RSL.clear;
6618 L1CTL.clear;
6619
6620 /* activate TCHF signalling channel */
6621 f_est_dchan(false);
6622
6623 T.start;
6624 alt {
6625 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6626 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6627 var octetstring l2 := dl.payload.data_ind.payload;
6628
6629 if (is_first_frame) {
6630 is_first_frame := false;
6631 first_fn := dl.dl_info.frame_nr;
6632 }
6633
6634 if (dl.dl_info.link_id.c == SACCH) {
6635 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6636 if (not match(l2_fill_frame_sacch, l2)) {
6637 repeat;
6638 }
6639 } else if (not match(l2_fill_frame, l2)) {
6640 repeat;
6641 }
6642
6643 if (dtxd) {
6644 if (not f_g_chan_is_tchf()) {
6645 T.stop;
6646 f_rsl_chan_deact();
6647 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006648 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 +02006649 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006650 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006651 T.stop;
6652 f_rsl_chan_deact();
6653 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006654
6655 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6656 * 2 SACCH, 1 TCH/F */
6657 expected_fill_frames := 3;
6658
6659 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6660 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6661 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006663 } else {
6664 setverdict(pass);
6665 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006666 } else {
6667 if (dl.dl_info.link_id.c == SACCH) {
6668 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006669 repeat;
6670 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006671 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6672 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6673 * we should only see the subset of frames numbers which correspond to a block boundary.
6674 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6675 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6676 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6677 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6678 repeat;
6679 }
6680 }
6681 log("Received DTX TCH fill frame with bad frame number: ", fn,
6682 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6683 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6684 f_rsl_chan_deact();
6685 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006687 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006688 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006689 if (dl.dl_info.link_id.c == SACCH) {
6690 nfill_frames_sacch := nfill_frames_sacch + 1;
6691 } else {
6692 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6693 }
6694 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006695 T.stop;
6696 if (f_g_chan_is_tchf()) {
6697 /* Without DTX we can expect 25 fill frames for every 104 frames.
6698 * (24 FACCH + 1 SACCH filling) */
6699 expected_fill_frames := 25;
6700 } else if (f_g_chan_is_tchh()) {
6701 /* We can expect 2 fill frames for every 104 frames. */
6702 expected_fill_frames := 2;
6703 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6704 /* We can expect 5 fill frames for every 104 frames. */
6705 expected_fill_frames := 5;
6706 } else {
6707 f_rsl_chan_deact();
6708 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006710 }
6711
6712 f_rsl_chan_deact();
6713 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006714
6715 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006716 setverdict(pass);
6717 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006718 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6719 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006721 }
6722 } else {
6723 repeat;
6724 }
6725 }
6726 }
6727 [] L1CTL.receive { repeat; }
6728 [] T.timeout {
6729 f_rsl_chan_deact();
6730 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006732 }
6733 }
6734}
6735
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006736private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006737 f_test_l2_fill_frames(false);
6738}
6739
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006740private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006741 f_test_l2_fill_frames(true);
6742}
6743
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006744private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006745 var ConnHdlr vc_conn;
6746 var ConnHdlrPars pars;
6747 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006748 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006749 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6750 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6751 if (dtxd) {
6752 if (i >= 4) { /* DTX is only allowed on TCH/F */
6753 break;
6754 }
6755 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6756 } else {
6757 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6758 }
6759 vc_conn.done;
6760 }
6761}
6762
6763/* Verify that L2 fill frames are sent on TCH in signaling mode if
6764 * there is nothing to transmit while DTX is disabled on downlink. */
6765testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6766 f_tch_sign_l2_fill_frame(false);
6767}
6768
6769/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6770 * there is nothing to transmit while DTX is enabled on downlink. */
6771testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6772 f_tch_sign_l2_fill_frame(true);
6773}
Harald Welte0472ab42018-03-12 15:02:26 +01006774
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006775testcase TC_chopped_ipa_ping() runs on test_CT {
6776 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6777}
6778
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006779testcase TC_chopped_ipa_payload() runs on test_CT {
6780 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6781}
6782
Harald Welte0472ab42018-03-12 15:02:26 +01006783/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6784/* protocol error as per 44.006 */
6785/* link layer failure (repetition of I-frame N200 times without ACK */
6786/* repetition of SABM or DISC N200 times without ACK */
6787/* receptiom of SABM in multi-frame established state */
6788
6789
Harald Welte68e495b2018-02-25 00:05:57 +01006790/* TODO Areas:
6791
6792* channel activation
6793** with BS_Power / MS_Power, bypassing power control loop
6794** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006795** with timing advance from initial activation on
6796* mode modify
6797** encryption
6798** multirate
6799* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006800** unsupported algorithm
6801* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006802* BS Power Control
6803* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006804* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006805* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006806** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006807* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006808** DATA_IND from BTS->PCU
6809** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006810
6811*/
Harald Welte70767382018-02-21 12:16:40 +01006812
6813control {
6814 execute( TC_chan_act_stress() );
6815 execute( TC_chan_act_react() );
6816 execute( TC_chan_deact_not_active() );
6817 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006818 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006819 execute( TC_sacch_filling() );
6820 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006821 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006822 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006823 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006824 execute( TC_sacch_chan_act_ho_async() );
6825 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006826 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006827 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006828 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006829 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006830 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006831 execute( TC_rach_load_idle_thresh0() );
6832 execute( TC_rach_load_idle_below_thresh() );
6833 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006834 execute( TC_meas_res_sign_tchf() );
6835 execute( TC_meas_res_sign_tchh() );
6836 execute( TC_meas_res_sign_sdcch4() );
6837 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006838 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006839 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006840 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006841 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006842 execute( TC_rsl_bs_pwr_static_ass() );
6843 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006844 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006845 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006846 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006847 execute( TC_rsl_ms_pwr_dyn_up() );
6848 execute( TC_rsl_ms_pwr_dyn_down() );
6849 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6850 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006851 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006852 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006853 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006854 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006855 execute( TC_paging_imsi_80percent() );
6856 execute( TC_paging_tmsi_80percent() );
6857 execute( TC_paging_imsi_200percent() );
6858 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006859 execute( TC_rsl_protocol_error() );
6860 execute( TC_rsl_mand_ie_error() );
6861 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006862 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006863 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006864 execute( TC_si_sched_2bis() );
6865 execute( TC_si_sched_2ter() );
6866 execute( TC_si_sched_2ter_2bis() );
6867 execute( TC_si_sched_2quater() );
6868 execute( TC_si_sched_13() );
6869 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006870 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006871 execute( TC_ipa_crcx_twice_not_active() );
6872 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006873 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006874 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006875
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006876 if (mp_pcu_socket != "") {
6877 execute( TC_pcu_act_req() );
6878 execute( TC_pcu_act_req_wrong_ts() );
6879 execute( TC_pcu_act_req_wrong_bts() );
6880 execute( TC_pcu_act_req_wrong_trx() );
6881 execute( TC_pcu_deact_req() );
6882 execute( TC_pcu_deact_req_wrong_ts() );
6883 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006884 if (mp_l1_supports_gprs) {
6885 execute( TC_pcu_data_req_pdtch() );
6886 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006887 execute( TC_pcu_data_req_wrong_bts() );
6888 execute( TC_pcu_data_req_wrong_trx() );
6889 execute( TC_pcu_data_req_wrong_ts() );
6890 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006891 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006892 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006893 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006894 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006895 execute( TC_pcu_data_req_imm_ass_pch() );
6896 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006897 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006898 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006899 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006900 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006901 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006902 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006903 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006904 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006905 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006906 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006907 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006908 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006909 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006910 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006911 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006912 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006913 execute( TC_dyn_osmo_pdch_act_deact() );
6914 execute( TC_dyn_osmo_pdch_double_act() );
6915 execute( TC_dyn_ipa_pdch_act_deact() );
6916 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6917
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006918 if (PCUIF_Types.mp_pcuif_version >= 10) {
6919 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006920 execute( TC_pcu_socket_nsvc_ipv4() );
6921 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006922 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006923 } else {
6924 log("PCU socket path not available, skipping PCU tests");
6925 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006926
Harald Welte3d04ae62018-04-04 20:29:05 +02006927 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006928 execute( TC_dyn_osmo_pdch_tchf_act() );
6929 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006930 execute( TC_dyn_ipa_pdch_tchf_act() );
6931 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006932
6933 execute( TC_rll_est_ind() );
6934 execute( TC_rll_est_req_DCCH_3() );
6935 execute( TC_rll_est_req_ACCH_3() );
6936 execute( TC_rll_rel_ind_DCCH_0() );
6937 execute( TC_rll_rel_ind_DCCH_3() );
6938 execute( TC_rll_rel_ind_ACCH_0() );
6939 execute( TC_rll_rel_ind_ACCH_3() );
6940 execute( TC_rll_rel_req() );
6941 execute( TC_rll_unit_data_req_DCCH() );
6942 execute( TC_rll_unit_data_req_ACCH() );
6943 execute( TC_rll_unit_data_ind_DCCH() );
6944 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006945
6946 execute( TC_chan_act_a51() );
6947 execute( TC_chan_act_a52() );
6948 execute( TC_chan_act_a53() );
6949 execute( TC_encr_cmd_a51() );
6950 execute( TC_encr_cmd_a52() );
6951 execute( TC_encr_cmd_a53() );
6952
Harald Welteee25aae2019-05-19 14:32:37 +02006953 execute( TC_err_rep_wrong_mdisc() );
6954 execute( TC_err_rep_wrong_msg_type() );
6955 execute( TC_err_rep_wrong_sequence() );
6956
Harald Weltee613f962018-04-18 22:38:16 +02006957 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006958
6959 execute( TC_tch_sign_l2_fill_frame() );
6960 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006961
6962 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006963 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006964}
6965
6966
6967}