blob: b381893c6d1e38a69acc74f3746fa1f77b141b48 [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
Harald Welte52ae1682020-10-11 20:45:55 +02001541 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1542 alt {
1543 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1544 [] RSL_CCHAN.receive { repeat }
1545 }
1546
Harald Welte3453ab42019-05-24 21:19:58 +02001547 var GsmFrameNumber fn_last := 0;
1548 for (var integer i := 0; i < 1000; i := i+1) {
1549 var OCT1 ra := f_rnd_ra_cs();
1550 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1551 if (fn == fn_last) {
1552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1553 }
1554 fn_last := fn;
1555 }
1556
1557 timer T := 5.0;
1558 T.start;
1559 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001560 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001561 -> value rx_ud {
1562 var RSL_IE_Body ie;
1563 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1564 load_access_count := load_access_count + ie.rach_load.access_count;
1565 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1566 setverdict(fail, "Access count cannot be < Busy count");
1567 }
1568 repeat;
1569 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001570 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001571 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1572 repeat;
1573 }
1574 [] RSL_CCHAN.receive {
1575 repeat;
1576 }
1577 [] T.timeout { }
1578 }
1579 if (load_access_count == 1000) {
1580 setverdict(pass);
1581 } else {
1582 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1583 }
1584
1585 f_vty_load_ind_thresh(10);
1586 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1587}
1588
Harald Welte54a2a2d2018-02-26 09:14:05 +01001589private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001590 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001591 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001592 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001593 f_sleep(0.5);
1594
1595 /* Transmit RACH request + wait for confirmation */
1596 var OCT1 ra := f_rnd_ra_cs();
1597 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1598
1599 /* Check for expected result */
1600 timer T := 1.5;
1601 T.start;
1602 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001603 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001604 setverdict(pass);
1605 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001606 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608 }
1609 [] RSL_CCHAN.receive { repeat; }
1610 [not expect_pass] T.timeout {
1611 setverdict(pass);
1612 }
1613 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001615 }
1616 }
1617}
1618
1619/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1620testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001621 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001622 f_init_l1ctl();
1623 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001624 f_sleep(1.0);
1625
1626 /* default max-ta is 63 (full range of GSM timing advance */
1627
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001628 /* We allow early arrival up to 2 symbols */
1629 f_rach_toffs(-1*256, true);
1630 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001631 f_rach_toffs(-10*256, false);
1632
1633 /* 0 / 32 / 63 bits is legal / permitted */
1634 f_rach_toffs(0, true);
1635 f_rach_toffs(32*256, true);
1636 f_rach_toffs(63*256, true);
1637
1638 /* more than 63 bits is not legal / permitted */
1639 f_rach_toffs(64*256, false);
1640 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001643
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001644private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001645 var GsmFrameNumber fn;
1646 var RSL_Message rm;
1647
1648 f_l1_tune(L1CTL);
1649 RSL.clear;
1650
1651 /* Generate a random Handover Reference */
1652 var integer ho_ref := oct2int(f_rnd_octstring(1));
1653
1654 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1655 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1656 RSL_IE_Body:{ handover_ref := ho_ref }));
1657
1658 /* Activate a channel on the BTS side (no encryption) */
1659 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1660 act_type := t_RSL_IE_ActType_HO_SYNC);
1661
1662 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1663 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001664 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001665
1666 /* Send handover Access Burst */
1667 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1668
1669 /* TODO: test mismatching Handover Reference, and missing IE */
1670
1671 /* Wait for handover detection */
1672 timer T := 3.0;
1673 T.start;
1674 alt {
1675 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1676 log("Handover RACH has been detected: ", rm);
1677 setverdict(pass);
1678 }
1679 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1681 log2str("RSL_CHAN_RQD was not expected: ", rm));
1682 }
1683 [] RSL.receive { repeat; }
1684 [] T.timeout {
1685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1686 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1687 }
1688 }
1689
1690 /* Release the channel */
1691 f_rsl_chan_deact();
1692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1693}
1694
1695/* Test handover RACH detection */
1696testcase TC_ho_rach() runs on test_CT {
1697 var ConnHdlrPars pars;
1698 var ConnHdlr vc_conn;
1699
1700 f_init();
1701
1702 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1703 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1704 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1705 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1706 vc_conn.done;
1707 }
1708
1709 /* TODO: do the above in parallel, rather than sequentially? */
1710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1711}
1712
Harald Welte93640c62018-02-25 16:59:33 +01001713/***********************************************************************
1714 * Measurement Processing / Reporting
1715 ***********************************************************************/
1716
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001717private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001718 spare := '0'B,
1719 lpd := 0,
1720 sapi := sapi,
1721 c_r := c_r,
1722 ea := true
1723}
1724
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001725private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001726 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001727 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001728 len := 0, /* overwritten */
1729 m := false,
1730 el := 1,
1731 payload := pl
1732}
1733
1734/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001735private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001736 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001737 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001738 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001739 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 +01001740 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001741 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001742
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001743 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1744 g_pars.l1_pars.ms_power_level, false,
1745 g_pars.l1_pars.ms_actual_ta);
1746
1747 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1748 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1749
1750 log("Sending Measurement Report: ", l1h, l2);
1751 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001752 repeat;
1753 }
1754}
1755
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001756private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001757 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001758 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001759 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1760 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001761 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1762 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001763 repeat;
1764 }
1765}
1766
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001767private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001768 uint6_t rxlev,
1769 uint3_t rxqual
1770}
1771
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001772private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001773 MeasElem full,
1774 MeasElem sub
1775}
1776
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001777private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001778 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001779 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001780 MeasElemFS meas_ul,
1781 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001782 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001783 uint5_t ms_power_level,
1784 uint8_t ms_actual_ta
1785}
1786
1787/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1788private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1789 return 63 + (toffs256s/256);
1790}
1791
Harald Welted5684392018-03-10 18:22:04 +01001792private function f_max(integer a, integer b) return integer {
1793 if (a > b) {
1794 return a;
1795 } else {
1796 return b;
1797 }
1798}
1799
1800private function f_min(integer a, integer b) return integer {
1801 if (a < b) {
1802 return a;
1803 } else {
1804 return b;
1805 }
1806}
1807
1808/* compute negative tolerance val-tolerance, ensure >= min */
1809private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1810 val := val - tolerance;
1811 return f_max(val, min);
1812}
1813
1814/* compute positive tolerance val+tolerance, ensure <= max */
1815private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1816 val := val + tolerance;
1817 return f_min(val, max);
1818}
1819
1820/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1821private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1822return template integer {
1823 var template integer ret;
1824 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1825 return ret;
1826}
1827
1828
Harald Welte70767382018-02-21 12:16:40 +01001829/* build a template for matching measurement results against */
1830private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1831 var ConnL1Pars l1p := g_pars.l1_pars;
1832 var template RSL_IE_UplinkMeas ul_meas := {
1833 len := 3,
1834 rfu := '0'B,
1835 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001836 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001837 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001838 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001839 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001840 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1841 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001842 supp_meas_info := omit
1843 };
Harald Welte685d5982018-02-27 20:42:05 +01001844 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001845 ul_meas.len := (3+8);
1846 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001847 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001848 toa256_min := ?,
1849 toa256_max := ?,
1850 toa256_std_dev := ?
1851 }
Harald Welte685d5982018-02-27 20:42:05 +01001852 }
Harald Welte70767382018-02-21 12:16:40 +01001853 var template RSL_IE_BS_Power bs_power := {
1854 reserved := 0,
1855 epc := false,
1856 fpc := false,
1857 power_level := l1p.bs_power_level
1858 };
1859 var template RSL_IE_L1Info l1_info := {
1860 ms_power_lvl := l1p.ms_power_level,
1861 fpc := false,
1862 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001863 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001864 };
1865 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001866 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001867 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1868 ?, t_toffs);
1869}
1870
Philipp Maierdd841d32019-12-17 14:44:54 +01001871/* build a template for matching measurement results that do not contain any
1872 * MS related measurement (l1_info, l3_info and ms timing offset). */
1873private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1874 var ConnL1Pars l1p := g_pars.l1_pars;
1875 var template RSL_IE_UplinkMeas ul_meas := {
1876 len := 3,
1877 rfu := '0'B,
1878 dtx_d := l1p.dtx_enabled,
1879 rxlev_f_u := ?,
1880 reserved1 := '00'B,
1881 rxlev_s_u := ?,
1882 reserved2 := '00'B,
1883 rxq_f_u := ?,
1884 rxq_s_u := ?,
1885 supp_meas_info := omit
1886 };
1887 if (l1p.toa256_enabled) {
1888 ul_meas.len := (3+8);
1889 ul_meas.supp_meas_info := {
1890 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1891 toa256_min := ?,
1892 toa256_max := ?,
1893 toa256_std_dev := ?
1894 }
1895 }
1896 var template RSL_IE_BS_Power bs_power := {
1897 reserved := 0,
1898 epc := false,
1899 fpc := false,
1900 power_level := l1p.bs_power_level
1901 };
1902
1903 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1904}
1905
Harald Welte70767382018-02-21 12:16:40 +01001906/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001907private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001908 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001909 var boolean chan_est := false;
1910
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001911 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001912
1913 /* Receive osmocom specific measurement reports. This is the normal
1914 * case. Here we verify that the measurement reports we sent are
1915 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001916 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1917 /* increment counter of next to-be-expected meas rep */
1918 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1919 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001920 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001921
1922 /* The following two cases may only happen in the beginning
1923 * of the channel establishment phase. Once we have received
1924 * the "our" measurement report the first time, the channel
1925 * is established and empty or hardcoded TRXCON reports must
1926 * not occur anymore. */
1927 chan_est := true;
1928
1929 repeat;
1930 }
1931
1932 /* When the BTS has established the channel, the MS might need slightly
1933 * more time to establish the channel and actually start sending. The
1934 * result is then a measurement report that just lacks the measurement
1935 * information of the MS. This is normal and we tolerate this behavior. */
1936 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1937 /* increment counter of next to-be-expected meas rep */
1938 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1939 /* Re-start the timer expecting the next MEAS RES */
1940 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001941 repeat;
1942 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001943
1944 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1945 * measurements if the TTCN3 side does not supply measurement input in
1946 * time. In those cases TRXCON will either use a cached measurement
1947 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1948 * report the templates above will not match. We tolerate this
1949 * behavior, but only once. */
1950 [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 +01001951 /* increment counter of next to-be-expected meas rep */
1952 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1953 if (g_first_meas_res) {
1954 g_first_meas_res := false;
1955 repeat;
1956 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001958 }
Harald Welte70767382018-02-21 12:16:40 +01001959 }
1960 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001962 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001963 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001965 }
1966}
1967
Harald Weltee613f962018-04-18 22:38:16 +02001968private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1969 select (rsl_alg_id) {
1970 case (RSL_ALG_ID_A5_0) { return 0; }
1971 case (RSL_ALG_ID_A5_1) { return 1; }
1972 case (RSL_ALG_ID_A5_2) { return 2; }
1973 case (RSL_ALG_ID_A5_3) { return 3; }
1974 case (RSL_ALG_ID_A5_4) { return 4; }
1975 case (RSL_ALG_ID_A5_5) { return 5; }
1976 case (RSL_ALG_ID_A5_6) { return 6; }
1977 case (RSL_ALG_ID_A5_7) { return 7; }
1978 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1980 /* Make compiler happy by calling mtc.stop here. It is already
1981 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001982 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001983 }
1984 }
1985}
1986
1987private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1988 select (rsl_alg_id) {
1989 case (RSL_ALG_ID_A5_1) { return '000'B; }
1990 case (RSL_ALG_ID_A5_2) { return '001'B; }
1991 case (RSL_ALG_ID_A5_3) { return '010'B; }
1992 case (RSL_ALG_ID_A5_4) { return '011'B; }
1993 case (RSL_ALG_ID_A5_5) { return '100'B; }
1994 case (RSL_ALG_ID_A5_6) { return '101'B; }
1995 case (RSL_ALG_ID_A5_7) { return '110'B; }
1996 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1998 /* Make compiler happy by calling mtc.stop here. It is already
1999 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002000 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002001 }
2002 }
2003}
2004
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002005/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2006private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2007 var GsmFrameNumber fn;
2008 timer T := 8.0;
2009
2010 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2011 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2012
2013 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2014 /* Send the actual RACH */
2015 fn := f_L1CTL_RACH(L1CTL, ra);
2016
2017 T.start;
2018 alt {
2019 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2020 [] T.timeout {
2021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2022 }
2023 }
2024 T.stop
2025 return fn;
2026}
Harald Weltee613f962018-04-18 22:38:16 +02002027
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002028/* Tune to a dedicated channel: L1CTL only */
2029private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002030 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002031 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2032 7 /* TODO: mp_tsc */,
2033 mp_trx0_arfcn));
2034 } else {
2035 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2036 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002037 pars.fhp.maio_hsn.hsn,
2038 pars.fhp.maio_hsn.maio,
2039 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002040 }
2041}
2042
Harald Welte70767382018-02-21 12:16:40 +01002043/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002044private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002045 var GsmFrameNumber fn;
2046 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002047 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002048 var integer ra := 23;
2049
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002050 /* Send RACH request and wait for ChanReq */
2051 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002052
2053 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002054 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002055
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002056 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002057 if (g_pars.fhp.enabled) {
2058 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002059 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002060 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002061 }
2062
Harald Welte70767382018-02-21 12:16:40 +01002063 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002064 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 +01002065 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2066
2067 /* receive IMM.ASS on MS side */
2068 var ImmediateAssignment ia_um;
2069 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002070
2071 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2072 if (ch_desc.h != ia_um.chan_desc.h) {
2073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2074 }
2075
Harald Welte70767382018-02-21 12:16:40 +01002076 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002077 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002078 /* enable encryption, if requested */
2079 if (encr_enable) {
2080 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2081 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2082 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002083
2084 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002085}
2086
2087/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002088private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002089 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002090 RSL.clear;
2091
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002092 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002093 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002094 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002095 }
Harald Welte70767382018-02-21 12:16:40 +01002096
2097 f_est_dchan();
2098
2099 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2100 * RSL measurement reports on Abis side */
2101 timer T := 8.0;
2102 T.start;
2103 alt {
2104 [] as_l1_sacch();
2105 [] as_meas_res();
2106 [] as_l1_dcch();
2107 [] L1CTL.receive { repeat; }
2108 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002109 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002110 * of any earlier errors, so if we reach this timeout, we're good */
2111 setverdict(pass);
2112 }
2113 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002115 }
2116 }
2117 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002119}
Harald Welte0472ab42018-03-12 15:02:26 +01002120
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002121/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2122private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002123 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002124 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2125 timer Tup := 10.0;
2126 Tup.start;
2127 alt {
2128 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2129 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2130 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002131
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002132 if (rx_lvl != max_rx_lvl) {
2133 repeat;
2134 }
2135 Tup.stop;
2136 }
2137 [] L1CTL.receive { repeat; }
2138 [] Tup.timeout {
2139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2140 log2str("Didn't reach full power ", max_rx_lvl));
2141 }
2142 }
2143 return max_rx_lvl;
2144}
2145
2146/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2147private function f_verify_ramp_up() runs on ConnHdlr {
2148 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002149 var integer initial_rx_lvl := -1;
2150 var integer last_rx_lvl := -1;
2151 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2152
2153 timer T := 2.0;
2154 alt {
2155 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2156 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2157 log("Received rx_level=", rx_lvl);
2158 if (initial_rx_lvl == -1) {
2159 initial_rx_lvl := rx_lvl;
2160 last_rx_lvl := rx_lvl;
2161
2162 /* Expect a somehow low value during first received messages */
2163 if (initial_rx_lvl >= max_rx_lvl / 2) {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 log2str("Detected high initial tx power during ramp up: ",
2166 initial_rx_lvl , ", full power is", max_rx_lvl));
2167 }
2168 }
2169
2170 /* received Rx level bigger than maximum allowed power by CN */
2171 if (rx_lvl > max_rx_lvl) {
2172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2173 log2str("Detected Tx power higher than full power: ",
2174 rx_lvl , " > ", max_rx_lvl));
2175 }
2176
2177 /* Make sure it never decreases, since we are rumping up */
2178 if (last_rx_lvl > rx_lvl) {
2179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2180 log2str("Detected Tx power decrease during ramp up: ",
2181 last_rx_lvl , " -> ", rx_lvl));
2182 }
2183
2184 if (rx_lvl == max_rx_lvl and not T.running) {
2185 /* We reached the maximum power, start timer and receive
2186 /* a few more to make sure we don't surpass it */
2187 log("Reached full power, wating a bit more until success");
2188 T.start;
2189 }
2190
2191 last_rx_lvl := rx_lvl;
2192 repeat;
2193 }
2194 [] L1CTL.receive { repeat; }
2195 [] T.timeout { }
2196 }
2197
2198 /* We didn't increase tx power during ramp up */
2199 if (initial_rx_lvl < last_rx_lvl) {
2200 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2201 } else {
2202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2203 log2str("No Tx power increase during whole ramp up: ",
2204 initial_rx_lvl , " -> ", last_rx_lvl));
2205 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002206}
2207
2208/* verify BTS ramps power down to rx_level 0 */
2209private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2210 var L1ctlDlMessage l1_dl;
2211 var integer last_rx_lvl := max_rx_lvl;
2212
2213 timer Tdown := 5.0;
2214 Tdown.start;
2215 alt {
2216 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2217 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2218 log("Received rx_level=", rx_lvl);
2219
2220 /* received Rx level bigger than maximum allowed power by CN */
2221 if (rx_lvl > max_rx_lvl) {
2222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2223 log2str("Detected Tx power higher than full power: ",
2224 rx_lvl , " > ", max_rx_lvl));
2225 }
2226
2227 /* Make sure it never increases, since we are rumping down */
2228 if (last_rx_lvl < rx_lvl) {
2229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2230 log2str("Detected Tx power increase during ramp up: ",
2231 last_rx_lvl , " -> ", rx_lvl));
2232 }
2233
2234 last_rx_lvl := rx_lvl;
2235 if (last_rx_lvl != 0) {
2236 repeat;
2237 }
2238 /* we reached power level 0, we are done */
2239 Tdown.stop;
2240 }
2241 [] L1CTL.receive { repeat; }
2242 [] Tdown.timeout { }
2243 }
2244
2245 /* We didn't increase tx power during ramp down */
2246 if (max_rx_lvl > last_rx_lvl) {
2247 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2248 } else {
2249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2250 log2str("No Tx power decrease during whole ramp down: ",
2251 max_rx_lvl , " -> ", last_rx_lvl));
2252 }
2253}
2254
2255/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002256private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002257 f_l1_tune(L1CTL);
2258 RSL.clear;
2259
2260 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002261
2262 setverdict(pass);
2263}
2264testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2265 var ConnHdlr vc_conn;
2266 var ConnHdlrPars pars;
2267 f_init();
2268 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2269 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2270 pcu_comp := false, trxc_comp := true);
2271 vc_conn.done;
2272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2273}
2274
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002275/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002276private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002277 f_connhdlr_init_vty_bsc();
2278
2279 f_l1_tune(L1CTL);
2280 RSL.clear;
2281
2282 /* Wait until BTS is started and at full power */
2283 var integer max_rx_lvl := f_wait_ramp_up();
2284 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2285
2286 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2287 f_verify_ramp_down(max_rx_lvl);
2288
2289 setverdict(pass);
2290}
2291testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2292 var ConnHdlr vc_conn;
2293 var ConnHdlrPars pars;
2294 f_init();
2295 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2296 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2297 pcu_comp := false, trxc_comp := true);
2298 vc_conn.done;
2299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2300}
2301
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002302/* Verify Tx power:
2303 * + ramping down during ADM state UNLOCKED->LOCKED
2304 * + ramping up during ADM state LOCKED->UNLOCKED
2305 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002306private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002307 var L1ctlDlMessage l1_dl;
2308 var integer last_rx_lvl;
2309
2310 f_connhdlr_init_vty_bsc();
2311
2312 f_l1_tune(L1CTL);
2313 RSL.clear;
2314
2315 /* Wait until BTS is started and at full power */
2316 var integer max_rx_lvl := f_wait_ramp_up();
2317 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2318
2319 log("ADM STATE UNLOCKED->LOCKED");
2320 f_vty_enter_cfg_trx(BSCVTY);
2321 f_vty_transceive(BSCVTY, "rf_locked 1");
2322 last_rx_lvl := max_rx_lvl;
2323 f_verify_ramp_down(max_rx_lvl);
2324
2325 /* Let some time after we received 0dBm, then check we don't receive BCCH
2326 * anymore because scheduler has stopped after ramping down */
2327 f_sleep(2.0);
2328 L1CTL.clear;
2329 timer Tlocked := 2.0;
2330 Tlocked.start;
2331 alt {
2332 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2334 log2str("Received data_ind during rf_locked: ", l1_dl));
2335 }
2336 [] L1CTL.receive { repeat; }
2337 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2338 }
2339
2340 log("ADM STATE LOCKED->UNLOCKED");
2341 f_vty_transceive(BSCVTY, "rf_locked 0");
2342 f_verify_ramp_up();
2343 setverdict(pass);
2344}
2345testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2346 var ConnHdlr vc_conn;
2347 var ConnHdlrPars pars;
2348 f_init();
2349 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2350 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2351 pcu_comp := false, trxc_comp := true);
2352 vc_conn.done;
2353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2354}
2355
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002356private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002357 timer T := 8.0;
2358 T.start;
2359 var RSL_Message rsl;
2360 alt {
2361 [] as_l1_sacch();
2362 [] L1CTL.receive { repeat; }
2363 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2364 if (rsl.ies[3].body.bs_power.power_level == level) {
2365 setverdict(pass)
2366 } else {
2367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2368 }
2369 }
2370 [] T.timeout {
2371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2372 }
2373 }
2374}
2375
2376/* see if the rsl meas res contains our expeced bs power level
2377bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002378private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002379 f_l1_tune(L1CTL);
2380 RSL.clear;
2381
2382 if (mp_bts_trxc_port != -1) {
2383 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2384 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2385 }
2386
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002387 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002388 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2389 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2390
2391 f_est_dchan(more_ies :={valueof(pwr)});
2392
2393 f_check_meas_bs_power_level(pwr_var);
2394
2395 f_rsl_chan_deact();
2396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2397}
2398
2399/* see if the rsl meas res contains our expeced bs power level
2400bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002401private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002402 f_l1_tune(L1CTL);
2403 RSL.clear;
2404
2405 if (mp_bts_trxc_port != -1) {
2406 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2407 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2408 }
2409
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002410 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002411 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2412
2413 f_est_dchan();
2414
2415 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2416
2417 f_check_meas_bs_power_level(pwr_var);
2418
2419 f_rsl_chan_deact();
2420 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2421}
2422
2423testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2424 var ConnHdlr vc_conn;
2425 var ConnHdlrPars pars;
2426 f_init();
2427 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2428 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2429 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2430 pcu_comp := false, trxc_comp := true);
2431 vc_conn.done;
2432 }
2433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2434}
2435
2436testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2437 var ConnHdlr vc_conn;
2438 var ConnHdlrPars pars;
2439 f_init();
2440 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2441 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2442 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2443 pcu_comp := false, trxc_comp := true);
2444 vc_conn.done;
2445 }
2446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2447}
2448
Eric Wild61edb7e2019-06-03 12:38:31 +02002449/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2450second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2451These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002452private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002453 var uint5_t pwr_var := 7;
2454 var L1ctlDlMessage l1_dl;
2455
2456 f_trxc_fake_rssi(rxlev2dbm(10));
2457 f_l1_tune(L1CTL);
2458 RSL.clear;
2459
2460 var RSL_IE_List addl_ies;
2461 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2462
2463 addl_ies := {
2464 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2465 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2466 };
2467
2468 /* establish with power parameters */
2469 f_est_dchan(more_ies := addl_ies);
2470
2471 /* set a high value to ensure L1 power control level increases */
2472 f_trxc_fake_rssi(rxlev2dbm(20));
2473
2474 timer T2 := 6.0;
2475 T2.start;
2476 alt {
2477 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002478 /* Update sent MS power to follow what BTS requests */
2479 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2480 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002481 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002482 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002483 T2.stop;
2484 }
2485 [] L1CTL.receive { repeat; }
2486 [] T2.timeout {
2487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2488 "Power Level in L1 header has not increased sufficiently");
2489 }
2490 }
2491
2492 /* set a low value to ensure L1 power control level decreases */
2493 f_trxc_fake_rssi(rxlev2dbm(0));
2494
2495 timer T4 := 6.0;
2496 T4.start;
2497 alt {
2498 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002499 /* Update sent MS power to follow what BTS requests */
2500 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2501 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002502 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002503 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002504 T4.stop;
2505 setverdict(pass, "Power level in L1 decreased/increased as expected");
2506 }
2507 [] L1CTL.receive { repeat; }
2508 [] T4.timeout {
2509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2510 "Power Level in L1 header has not decreased sufficiently");
2511 }
2512 }
2513
2514 f_rsl_chan_deact();
2515 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2516
2517}
2518
2519/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002520private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002521 var uint5_t pwr_var := 7;
2522 var L1ctlDlMessage l1_dl;
2523
2524 /* set a low value to ensure power increases */
2525 f_trxc_fake_rssi(rxlev2dbm(10));
2526 f_l1_tune(L1CTL);
2527 RSL.clear;
2528
2529 var RSL_IE_List addl_ies;
2530 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2531
2532 addl_ies := {
2533 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2534 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2535 };
2536
2537 /* establish with power parameters */
2538 f_est_dchan(more_ies := addl_ies);
2539
2540 timer T1 := 10.0;
2541 T1.start;
2542 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002543 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2544 /* Update sent MS power to follow what BTS requests */
2545 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2546 repeat;
2547 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002548 [] L1CTL.receive { repeat; }
2549 [] T1.timeout {
2550 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2551 setverdict(fail, "Power level in L1 header should not have changed");
2552 }
2553 }
2554 }
2555
2556 f_rsl_chan_deact();
2557 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2558
2559}
2560
2561/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002562private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 var L1ctlDlMessage l1_dl;
2564 var uint5_t pwr_var := 15;
2565 var uint5_t pwr_max_var := f_get_max_power_from_band();
2566
2567 /* set a low value to ensure power increases */
2568 f_trxc_fake_rssi(rxlev2dbm(10));
2569 f_l1_tune(L1CTL);
2570 RSL.clear;
2571
2572 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2573 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2574
2575 /* establish with fixed power level */
2576 f_est_dchan(more_ies :={valueof(pwr)});
2577
2578 /* check our initial power level */
2579 f_wait_for_l1_power_level(pwr_var);
2580
2581 /* update power param to enable power loop
2582 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2583 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2584
2585 /* wait, then check that our power level was reduced */
2586 timer T1 := 10.0;
2587 T1.start;
2588 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002589 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2590 /* Update sent MS power to follow what BTS requests */
2591 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2592 repeat;
2593 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002594 [] L1CTL.receive { repeat; }
2595 [] T1.timeout {
2596 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2597 if( f_power_level_is_highest_dbm(rcv) ){
2598 setverdict(pass, "Power level in L1 header reduced as expected");
2599 } else {
2600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2601 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2602 }
2603 }
2604 }
2605
2606 f_rsl_chan_deact();
2607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2608
2609}
2610
2611/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002612private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002613 var L1ctlDlMessage l1_dl;
2614
2615 /* set a high value to ensure power decreases */
2616 f_trxc_fake_rssi(rxlev2dbm(50));
2617 f_l1_tune(L1CTL);
2618 RSL.clear;
2619
2620 var uint5_t pwr_var := 5;
2621 var uint5_t pwr_target_val := 15;
2622
2623 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2624 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2625
2626 /* establish with fixed power level */
2627 f_est_dchan(more_ies :={valueof(pwr)});
2628
2629 /* check our initial power level */
2630 f_wait_for_l1_power_level(pwr_var);
2631
2632 /* update power param to enable power loop
2633 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002634 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002635
2636 /* wait, then check that our power level was increased */
2637 timer T1 := 10.0;
2638 T1.start;
2639 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002640 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2641 /* Update sent MS power to follow what BTS requests */
2642 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2643 repeat;
2644 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002645 [] L1CTL.receive { repeat; }
2646 [] T1.timeout {
2647 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2648 setverdict(pass, "Power level in L1 header increased to lowest power value");
2649 } else {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 "Power level in L1 header NOT increased to lowest power value");
2652 }
2653 }
2654 }
2655
2656 f_rsl_chan_deact();
2657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2658
2659}
2660
Eric Wild095024b2019-06-17 15:08:57 +02002661/* see if we change the power level without receiving power parameters, which should not happen
2662rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002663private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002664 var L1ctlDlMessage l1_dl;
2665
2666 /* set a high value to ensure power decreases */
2667 f_trxc_fake_rssi(rxlev2dbm(50));
2668 f_l1_tune(L1CTL);
2669 RSL.clear;
2670
2671 var uint5_t pwr_var := 5;
2672
2673 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2674 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2675
2676 /* establish with fixed power level */
2677 f_est_dchan(more_ies :={valueof(pwr)});
2678
2679 /* check our initial power level */
2680 f_wait_for_l1_power_level(pwr_var);
2681
2682 /* wait, then check that our power level did not change */
2683 timer T1 := 10.0;
2684 T1.start;
2685 alt {
2686 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2687 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2689 "BS power control should not be active unless we receive a power parameters IE!");
2690 }
2691 repeat;
2692 }
2693 [] L1CTL.receive { repeat; }
2694 [] T1.timeout { setverdict(pass); }
2695 }
2696
2697 f_rsl_chan_deact();
2698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2699
2700}
2701
Eric Wild095024b2019-06-17 15:08:57 +02002702/* see if we change the power level without receiving power parameters, which should not happen
2703ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002704private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002705 var L1ctlDlMessage l1_dl;
2706
2707 /* set a high value to ensure power decreases */
2708 f_trxc_fake_rssi(rxlev2dbm(50));
2709 f_l1_tune(L1CTL);
2710 RSL.clear;
2711
2712 var uint5_t pwr_var := 5;
2713
2714 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2715 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2716
2717 /* establish with fixed power level */
2718 f_est_dchan(more_ies :={valueof(pwr)});
2719
2720 /* check our initial power level */
2721 f_wait_for_l1_power_level(pwr_var);
2722
2723 /* pwr control without power params IE, should NOT activate MS power control*/
2724 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2725
2726 /* wait, then check that our power level did not change */
2727 timer T1 := 10.0;
2728 T1.start;
2729 alt {
2730 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2731 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2733 "BS power control should not be active unless we receive a power parameters IE!");
2734 }
2735 repeat;
2736 }
2737 [] L1CTL.receive { repeat; }
2738 [] T1.timeout { setverdict(pass); }
2739 }
2740
2741 f_rsl_chan_deact();
2742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2743
2744}
2745
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002746private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002747 var L1ctlDlMessage l1_dl;
2748 timer T0 := 10.0;
2749 T0.start;
2750 alt {
2751 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2752 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2754 "Power level in L1 header != signaled (RSL) power level.");
2755 }
2756 }
2757 [] L1CTL.receive { repeat; }
2758 [] T0.timeout {
2759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2760 "Timeout waiting for initial power level");
2761 }
2762 }
2763 T0.stop;
2764}
2765
2766private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2767 var IntegerRecord min_dbm_level;
2768 var IntegerRecord max_dbm_level;
2769 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2770
2771 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2772 if (min_dbm_level[i] == level) {
2773 return true;
2774 }
2775 }
2776 return false;
2777}
2778
2779private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2780 var IntegerRecord min_dbm_level;
2781 var IntegerRecord max_dbm_level;
2782 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2783
2784 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2785 if (max_dbm_level[i] == level) {
2786 return true;
2787 }
2788 }
2789 return false;
2790}
2791
2792private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2793 var IntegerRecord min_dbm_level;
2794 var IntegerRecord max_dbm_level;
2795 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2796 return max_dbm_level[0];
2797}
2798
2799type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002800private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002801private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2802 // 45.005 4.1.1
2803 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2804 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2805 2, 1, 0};
2806 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2807 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2808 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2809 var IntegerRecord rv;
2810
2811 select(band){
2812 case (BtsBand_allGSM){
2813 rv := gsm_power;
2814 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2815 max_dbm_level := {2, 1, 0};
2816 }
2817 case("DCS1800"){
2818 rv := dcs_power;
2819 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2820 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2821 }
2822 case("PCS1900"){
2823 rv := pcs_power;
2824 min_dbm_level := {15};
2825 max_dbm_level := {30};
2826 }
Harald Welte194b6912020-10-11 21:01:55 +02002827 case else {
2828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2829 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002830 }
2831
2832 return rv;
2833}
2834
2835private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002836 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of*type* in band (\w+),*", 0);
Eric Wild61edb7e2019-06-03 12:38:31 +02002837}
2838
2839testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2840 var ConnHdlr vc_conn;
2841 var ConnHdlrPars pars;
2842 f_init();
2843 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2844 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2845 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2846 pars.bts0_band := f_vty_get_bts0_band();
2847 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2848 vc_conn.done;
2849 }
2850 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2852}
2853
2854testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2855 var ConnHdlr vc_conn;
2856 var ConnHdlrPars pars;
2857 f_init();
2858 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2859 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2860 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2861 pars.bts0_band := f_vty_get_bts0_band();
2862 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2863 vc_conn.done;
2864 }
2865 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2867}
2868
2869testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2870 var ConnHdlr vc_conn;
2871 var ConnHdlrPars pars;
2872 f_init();
2873 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2874 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2875 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2876 pars.bts0_band := f_vty_get_bts0_band();
2877 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2878 vc_conn.done;
2879 }
2880 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2882}
2883
2884testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2885 var ConnHdlr vc_conn;
2886 var ConnHdlrPars pars;
2887 f_init();
2888 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2889 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2890 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2891 pars.bts0_band := f_vty_get_bts0_band();
2892 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2893 vc_conn.done;
2894 }
2895 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2897}
2898
Eric Wild280ccb82019-06-17 11:11:52 +02002899testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2900 var ConnHdlr vc_conn;
2901 var ConnHdlrPars pars;
2902 f_init();
2903 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2904 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2905 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2906 pars.bts0_band := f_vty_get_bts0_band();
2907 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2908 vc_conn.done;
2909 }
2910 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2912}
2913
Eric Wild095024b2019-06-17 15:08:57 +02002914testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2915 var ConnHdlr vc_conn;
2916 var ConnHdlrPars pars;
2917 f_init();
2918 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2919 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2920 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2921 pars.bts0_band := f_vty_get_bts0_band();
2922 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2923 vc_conn.done;
2924 }
2925 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2927}
2928
Harald Welte70767382018-02-21 12:16:40 +01002929testcase TC_meas_res_sign_tchf() runs on test_CT {
2930 var ConnHdlr vc_conn;
2931 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002932 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002933 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2934 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002935 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2936 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002937 vc_conn.done;
2938 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002940}
2941testcase TC_meas_res_sign_tchh() runs on test_CT {
2942 var ConnHdlr vc_conn;
2943 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002944 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002945 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2946 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002947 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2948 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002949 vc_conn.done;
2950 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002952}
2953testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2954 var ConnHdlr vc_conn;
2955 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002956 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002957 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2958 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002959 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2960 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002961 vc_conn.done;
2962 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002964}
2965testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2966 var ConnHdlr vc_conn;
2967 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002968 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002969 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2970 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002971 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2972 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002973 vc_conn.done;
2974 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002976}
Harald Welte685d5982018-02-27 20:42:05 +01002977testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2978 var ConnHdlr vc_conn;
2979 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002980 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002981 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2982 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2983 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2984 pars.l1_pars.toa256_enabled := true;
2985 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2986 vc_conn.done;
2987 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002989}
2990
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002991/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2992 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002993private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002994 var L1ctlDlMessage l1_dl;
2995 var RSL_IE_MS_Power ms_power;
2996 var RSL_Message rsl;
2997 var uint5_t power_level := 0;
2998
2999 f_l1_tune(L1CTL);
3000 RSL.clear;
3001
3002 f_est_dchan();
3003
3004 ms_power.reserved := 0;
3005 ms_power.fpc_epc := false;
3006
3007 /* Send the first power control command. This will disable any BTS/TRX
3008 * internal power control and switch the MS (which is not in scope of
3009 * this test) to a constant power level. We start with a power level
3010 * of 0 */
3011 ms_power.power_level := power_level;
3012 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3013 RSL.send(rsl);
3014
3015 alt {
3016
3017 /* Pick all SACCH blocks for checking */
3018 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3019
3020 /* The first byte of the L1 header contains the power level.
3021 * The reserved bits and the fpc bit is set to 0, so we may
3022 * compare directly. */
3023 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3024 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3025 }
3026
3027 /* Signal a new power level via RSL for the next turn. */
3028 if (power_level < 31) {
3029 power_level := power_level + 1;
3030 ms_power.power_level := power_level;
3031 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3032 RSL.send(rsl);
3033 repeat;
3034 }
3035
3036 }
3037
3038 /* Ignore all other blocks */
3039 [] L1CTL.receive { repeat; }
3040
3041 }
3042
3043 f_rsl_chan_deact();
3044 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3045
3046 setverdict(pass);
3047}
3048
3049testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3050 var ConnHdlr vc_conn;
3051 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003052 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003053
3054 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3055 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3056 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3057 vc_conn.done;
3058 }
3059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3060}
Harald Welte70767382018-02-21 12:16:40 +01003061
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003062/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003063TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003064private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003065 var L1ctlDlMessage l1_dl;
3066 var uint5_t ta_to_test := 16;
3067
3068
3069 f_l1_tune(L1CTL);
3070 RSL.clear;
3071
3072 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003073 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003074
3075 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3076
3077
3078 alt {
3079
3080 /* Pick all SACCH blocks for checking */
3081 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3082
3083 /* The second byte of the L1 header contains the TA. */
3084 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3085 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3086 }
3087
3088 }
3089
3090 /* Ignore all other blocks */
3091 [] L1CTL.receive { repeat; }
3092
3093 }
3094
3095 f_rsl_chan_deact();
3096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3097
3098 setverdict(pass);
3099}
3100
3101testcase TC_rsl_chan_initial_ta() runs on test_CT {
3102 var ConnHdlr vc_conn;
3103 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003104 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003105 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003106 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3107 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003108 vc_conn.done;
3109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3110}
3111
Eric Wilde57e1a62019-05-28 13:30:55 +02003112/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003113private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003114 var L1ctlDlMessage l1_dl;
3115 var uint5_t ms_power_level := 7;
3116
3117 var RSL_IE_MS_Power ms_power;
3118 ms_power.reserved := 0;
3119 ms_power.fpc_epc := false;
3120 ms_power.power_level := ms_power_level;
3121
3122 f_l1_tune(L1CTL);
3123 RSL.clear;
3124
3125 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3126
3127 timer T := 1.0;
3128 T.start;
3129 alt {
3130 /* Pick all SACCH blocks for checking */
3131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3132 /* The first byte of the L1 header contains the power level.. */
3133 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3134 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3135 }
3136 }
3137 /* Ignore all other blocks */
3138 [] L1CTL.receive { repeat; }
3139 [] T.timeout {
3140 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3141 }
3142 }
3143
3144 f_rsl_chan_deact();
3145 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3146 setverdict(pass);
3147}
3148
3149testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3150 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3151 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3152}
3153
Harald Welte0472ab42018-03-12 15:02:26 +01003154/* 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 +01003155private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003156 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003157 RSL.clear;
3158
3159 f_est_dchan();
3160 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003161 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003162
3163 timer T := 40.0;
3164 T.start;
3165 alt {
3166 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3167 setverdict(pass)
3168 }
3169 [] RSL.receive { repeat };
3170 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003172 }
3173 }
3174 f_rsl_chan_deact();
3175}
3176testcase TC_conn_fail_crit() runs on test_CT {
3177 var ConnHdlr vc_conn;
3178 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003179 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003180 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3181 pars.t_guard := 60.0;
3182 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3183 vc_conn.done;
3184}
3185
Harald Welte93640c62018-02-25 16:59:33 +01003186/***********************************************************************
3187 * Paging
3188 ***********************************************************************/
3189
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003190private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003191 if (tmsi == 'FFFFFFFF'O) {
3192 return true;
3193 } else {
3194 return false;
3195 }
3196}
Harald Welte70767382018-02-21 12:16:40 +01003197
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003198private type record allowedFn { integer frame_nr }
3199private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3200private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3201private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3202private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3203private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3204private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3205private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3206private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3207private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003208{
3209 var integer frame_nr_51;
3210 frame_nr_51 := frame_nr mod 51
3211
3212 var allowedFn fn_check;
3213 fn_check.frame_nr := frame_nr_51;
3214
3215 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003217 return;
3218 }
3219
3220 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3221 return;
3222 }
3223 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3224 return;
3225 }
3226 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3227 return;
3228 }
3229 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3230 return;
3231 }
3232 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3233 return;
3234 }
3235 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3236 return;
3237 }
3238 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3239 return;
3240 }
3241 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3242 return;
3243 }
3244
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003246 return;
3247}
3248
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003249private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3250 inout integer num_paging_rcv_ids,
3251 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003252runs on test_CT {
3253 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003254 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003255 repeat;
3256 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003257 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003258 var octetstring without_plen :=
3259 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3260 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003261
3262 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3263
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003264 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3265 /* Ignore empty RR Paging Request (PCH filling) messages.
3266 * TODO: does it make sense to count them? */
3267 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003268 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3269 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003270 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003271 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3272 }
3273 } else if (match(rr, tr_PAGING_REQ2)) {
3274 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3275 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3276 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3277 }
3278 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3279 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3280 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003281 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003282 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3283 }
3284 } else if (match(rr, tr_PAGING_REQ3)) {
3285 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3286 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3287 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3288 }
3289 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3290 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3291 }
3292 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3293 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3294 }
3295 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3296 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3297 }
3298 }
3299 repeat;
3300 }
3301}
3302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003303private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 boolean combined_ccch,
3305 integer bs_ag_blks_res,
3306 float load_factor,
3307 boolean exp_load_ind,
3308 boolean exp_overload,
3309 boolean use_tmsi
3310}
3311
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003312private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003313 integer num_paging_sent,
3314 integer num_paging_rcv_msgs,
3315 integer num_paging_rcv_ids,
3316 integer num_overload
3317}
3318
Harald Welte68e495b2018-02-25 00:05:57 +01003319/* Helper function for paging related testing */
3320private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003321 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003322 f_init_l1ctl();
3323 f_l1_tune(L1CTL);
3324
3325 var PagingTestState st := {
3326 num_paging_sent := 0,
3327 num_paging_rcv_msgs := 0,
3328 num_paging_rcv_ids := 0,
3329 num_overload := 0
3330 };
3331
3332 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3333 var float max_pch_imsi_per_sec;
3334 if (cfg.use_tmsi) {
3335 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3336 } else {
3337 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3338 }
3339 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3340 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003341 var float time_total := 20.0;
3342 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3343 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003344
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003345 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3346 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003347
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003348 timer T_itv := 0.0;
3349 T_itv.start;
3350 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003351 alt {
3352 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003353 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003354 st.num_overload := st.num_overload + 1;
3355 repeat;
3356 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003357 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003359 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003360 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003361 log("Rx LOAD_IND");
3362 /* FIXME: analyze/verify interval + contents */
3363 repeat;
3364 }
3365 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003366 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003367 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003368 [] T_itv.timeout {
3369 /* Send paging cmds based on elapsed time */
3370 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3371 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003372 var MobileIdentityV mi;
3373
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003374 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003375 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003376 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003377 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003378 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003379 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003380
3381 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003382 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 +02003383
3384 st.num_paging_sent := st.num_paging_sent + 1;
3385 }
3386 if (st.num_paging_sent < pkt_total) {
3387 /* Wait for interval to next PAGING COMMAND */
3388 var float time_now := T_total.read;
3389 var float next_sched := int2float(st.num_paging_sent)*interval;
3390 if (next_sched > time_now) {
3391 T_itv.start(next_sched - time_now);
3392 } else {
3393 T_itv.start(0.0);
3394 }
3395 } else {
3396 /* We are done, no need to keep counting */
3397 T_total.stop;
3398 }
3399 }
3400 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003401 }
3402 }
3403
3404 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3405 timer T_wait := 18.0;
3406 T_wait.start;
3407 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003408 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003409 [] L1CTL.receive { repeat; }
3410 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003411 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3412 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003413 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003415 }
Harald Welte68e495b2018-02-25 00:05:57 +01003416 }
3417
3418 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3419 " rcvd_ids=", st.num_paging_rcv_ids);
3420 return st;
3421}
3422
3423/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3424 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3425 * - that CCCH LOAD IND (PCH) are being generated
3426 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3427testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003428 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003429 var PagingTestCfg cfg := {
3430 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003431 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003432 load_factor := 0.8,
3433 exp_load_ind := true,
3434 exp_overload := false,
3435 use_tmsi := false
3436 };
3437 var PagingTestState st := f_TC_paging(cfg);
3438 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3440 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003441 } else {
3442 setverdict(pass);
3443 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003445}
3446
3447/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3448 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3449 * - that CCCH LOAD IND (PCH) are being generated
3450 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3451testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003452 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003453 var PagingTestCfg cfg := {
3454 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003455 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003456 load_factor := 0.8,
3457 exp_load_ind := true,
3458 exp_overload := false,
3459 use_tmsi := true
3460 };
3461 var PagingTestState st := f_TC_paging(cfg);
3462 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3464 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003465 } else {
3466 setverdict(pass);
3467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003469}
3470
3471/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3472 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3473 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3474 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3475testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003476 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003477 var PagingTestCfg cfg := {
3478 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003479 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003480 load_factor := 2.0,
3481 exp_load_ind := true,
3482 exp_overload := true,
3483 use_tmsi := false
3484 };
3485 var PagingTestState st := f_TC_paging(cfg);
3486 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3487 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003488 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003489 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003491 } else {
3492 setverdict(pass);
3493 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003495}
3496
3497/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3498 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3499 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3500 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3501testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003502 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003503 var PagingTestCfg cfg := {
3504 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003505 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003506 load_factor := 2.0,
3507 exp_load_ind := true,
3508 exp_overload := true,
3509 use_tmsi := true
3510 };
3511 var PagingTestState st := f_TC_paging(cfg);
3512 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3513 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003514 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003515 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003516 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 +01003517 } else {
3518 setverdict(pass);
3519 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003521}
3522
3523
Harald Welte93640c62018-02-25 16:59:33 +01003524/***********************************************************************
3525 * Immediate Assignment / AGCH
3526 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003527private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003528 len := 0,
3529 ma := ''B
3530}
Harald Welte93640c62018-02-25 16:59:33 +01003531
Harald Weltee8d750e2018-06-10 21:41:35 +02003532private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3533 return int2str(num_tx) & " sent, "
3534 & int2str(num_rx) & " received, "
3535 & int2str(num_del) & " deleted";
3536}
3537
3538private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3539 var L1ctlDlMessage l1_dl;
3540 timer T := 10.0;
3541 var integer num_tx := 0;
3542 var integer num_rx := 0;
3543 var integer num_del := 0;
3544 var charstring res_str;
3545 var float rx_ratio;
3546
Harald Welte10474062019-05-30 16:48:17 +02003547 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003548 f_init_l1ctl();
3549 f_l1_tune(L1CTL);
3550
3551 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003552 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003553 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3554 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003555 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003556 num_tx := num_tx+1;
3557 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003558 }
3559 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003560 T.start;
3561 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003562 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003563 num_del := num_del+1;
3564 repeat;
3565 }
3566 [] RSL_CCHAN.receive {
3567 repeat;
3568 }
3569 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003570 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3571 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3572 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003573 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003574 } else {
3575 num_rx := num_rx+1;
3576 }
3577 repeat;
3578 }
3579 [] L1CTL.receive { repeat; }
3580 [] T.timeout { }
3581 }
3582 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3583 log("AGCH test: " & res_str);
3584 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003586 }
3587 rx_ratio := int2float(num_rx) / int2float(num_tx);
3588 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003589 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 +02003590 } else {
3591 setverdict(pass);
3592 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003594}
3595
Harald Weltee8d750e2018-06-10 21:41:35 +02003596/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3597testcase TC_imm_ass_1000_20ms() runs on test_CT {
3598 f_TC_imm_ass(1000, 0.02, 0.25);
3599}
3600
3601/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3602testcase TC_imm_ass_200_0ms() runs on test_CT {
3603 f_TC_imm_ass(200, 0.0, 0.05);
3604}
3605
3606/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3607testcase TC_imm_ass_200_76ms() runs on test_CT {
3608 f_TC_imm_ass(150, 0.076, 1.00);
3609}
3610
3611
3612
Harald Welte48494ca2018-02-25 16:59:50 +01003613/***********************************************************************
3614 * BCCH
3615 ***********************************************************************/
3616
3617/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003618private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003619 GsmFrameNumber frame_number,
3620 SystemInformation si
3621}
3622
3623/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003624private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003625
3626/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003627private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003628
3629/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003630private function f_si_vecslot_contains(SystemInformationVector arr,
3631 RrMessageType key,
3632 boolean bcch_ext := false)
3633return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003634 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3635 var integer fn_mod51 := arr[i].frame_number mod 51;
3636 if (not bcch_ext and fn_mod51 == 2 or
3637 bcch_ext and fn_mod51 == 6) {
3638 if (arr[i].si.header.message_type == key) {
3639 return true;
3640 }
3641 }
3642 }
3643 return false;
3644}
3645
3646/* 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 +07003647private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3648 integer tc, RrMessageType key,
3649 boolean ext_bcch := false)
3650{
Harald Welte48494ca2018-02-25 16:59:50 +01003651 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003653 }
3654}
3655
3656/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003657private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3658 RrMessageType key)
3659return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003660 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3661 if (f_si_vecslot_contains(arr[tc], key) or
3662 f_si_vecslot_contains(arr[tc], key, true)) {
3663 return true;
3664 }
3665 }
3666 return false;
3667}
3668
3669/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003670private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3671 RrMessageType key,
3672 boolean bcch_ext := false,
3673 integer n := 1, integer m := 4)
3674return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003675 var integer count := 0;
3676 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003678 }
3679 for (var integer i:= 0; i < m; i := i + 1) {
3680 var integer fn_mod51 := arr[i].frame_number mod 51;
3681 if (not bcch_ext and fn_mod51 == 2 or
3682 bcch_ext and fn_mod51 == 6) {
3683 if (arr[i].si.header.message_type == key) {
3684 count := count + 1;
3685 }
3686 }
3687 }
3688 if (count >= n) {
3689 return true;
3690 } else {
3691 return false;
3692 }
3693}
3694
3695/* 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 +07003696private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3697 integer tc, RrMessageType key,
3698 boolean ext_bcch := false,
3699 integer n, integer m)
3700{
Harald Welte48494ca2018-02-25 16:59:50 +01003701 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003703 }
3704}
3705
3706/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003707private function f_si_vecslot_contains_only(SystemInformationVector arr,
3708 RrMessageType key,
3709 boolean bcch_ext := false)
3710return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003711 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3712 var integer fn_mod51 := arr[i].frame_number mod 51;
3713 if (not bcch_ext and fn_mod51 == 2 or
3714 bcch_ext and fn_mod51 == 6) {
3715 if (arr[i].si.header.message_type != key) {
3716 return false;
3717 }
3718 }
3719 }
3720 return true;
3721}
3722
3723/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003724private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3725 integer tc, RrMessageType key,
3726 boolean ext_bcch := false)
3727{
Harald Welte48494ca2018-02-25 16:59:50 +01003728 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003730 }
3731}
3732
3733/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003734private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003735 boolean bcch_extended,
3736 boolean si1_present,
3737 boolean si2bis_present,
3738 boolean si2ter_present,
3739 boolean si2quater_present,
3740 boolean si7_present,
3741 boolean si8_present,
3742 boolean si9_present,
3743 boolean si13_present,
3744 boolean si13alt_present,
3745 boolean si15_present,
3746 boolean si16_present,
3747 boolean si17_present,
3748 boolean si2n_present,
3749 boolean si21_present,
3750 boolean si22_present
3751}
3752
3753/* 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 +07003754private function f_validate_si_scheduling(SystemInformationConfig cfg,
3755 SystemInformationVectorPerTc si_per_tc)
3756{
Harald Welte48494ca2018-02-25 16:59:50 +01003757 var integer i;
3758 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3759 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003761 }
3762 }
3763 if (cfg.si1_present) {
3764 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3765 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3766 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3767 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3768 /* make sure *ALL* contain SI1 */
3769 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3770 }
3771 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3772 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3773 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3774 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3775 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3776 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3777
3778 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3779 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3780 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3781 * consecutive occurrences of TC = 4. */
3782 if (cfg.si2bis_present and not cfg.si2ter_present) {
3783 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3784 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3785 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3786 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3787 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3788 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3789 }
3790
3791 if (cfg.si7_present or cfg.si8_present) {
3792 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3793 * if System Information type 4 does not contain all information needed for cell
3794 * selection and reselection. */
3795 if (not cfg.bcch_extended) {
3796 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3797 }
3798 if (cfg.si7_present) {
3799 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3800 }
3801 if (cfg.si8_present) {
3802 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3803 }
3804 }
3805
3806 if (cfg.si2quater_present) {
3807 /* iii) System information type 2 quater is sent if needed, as determined by the system
3808 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3809 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3810 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3811 * within any of 4 consecutive occurrences of TC = 5. */
3812 if (not (cfg.bcch_extended)) {
3813 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3814 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3815 } else {
3816 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3817 }
3818 } else {
3819 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3820 }
3821 }
3822 if (cfg.si9_present) {
3823 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3824 * in system information type 3 as defined in 3GPP TS 44.018. */
3825 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3826 }
3827 if (cfg.si13_present) {
3828 /* vii) System Information type 13 is only related to the GPRS service. System Information
3829 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3830 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3831 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3832 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3833 * within any of 4 consecutive occurrences of TC=4. */
3834 if (not cfg.bcch_extended) {
3835 log("not-bccch-extended");
3836 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3837 } else {
3838 log("bccch-extended");
3839 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3840 }
3841 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003843 }
3844 }
3845 if (cfg.si16_present or cfg.si17_present) {
3846 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3847 * should not be sent in a cell where network sharing is used (see rule xv). */
3848 if (cfg.si22_present) {
3849 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3850 }
3851 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003853 }
3854 if (not cfg.bcch_extended) {
3855 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3856 }
3857 if (cfg.si16_present) {
3858 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3859 }
3860 if (cfg.si17_present) {
3861 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3862 }
3863 }
3864
3865 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3866 * broadcast information. The frequency with which they are sent is determined by the
3867 * system operator. System Information type 9 identifies the scheduling of System
3868 * Information type 18 and 20 messages. */
3869
3870 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3871 * Information Type 19 is present, then its scheduling shall be indicated in System
3872 * Information Type 9. */
3873
3874 if (cfg.si15_present) {
3875 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3876 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3877 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3878 * 4 consecutive occurrences of TC = 1. */
3879 if (not cfg.bcch_extended) {
3880 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3881 } else {
3882 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3883 }
3884 }
3885 if (cfg.si13alt_present) {
3886 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3887 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3888 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3889 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3890 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3891 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3892 * of TC = 4. */
3893 if (cfg.si13_present) {
3894 testcase.stop("Error: Cannot have SI13alt and SI13");
3895 }
3896 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003898 }
3899 if (not cfg.bcch_extended) {
3900 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3901 } else {
3902 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3903 }
3904 }
3905 if (cfg.si2n_present) {
3906 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3907 * as determined by the system operator. In the case that the message is sent on the
3908 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3909 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3910 * consecutive occurrences of TC = 4. */
3911 if (not cfg.bcch_extended) {
3912 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3913 } else {
3914 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3915 }
3916 }
3917 if (cfg.si21_present) {
3918 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3919 * determined by the system operator. If Extended Access Barring is in use in the cell
3920 * then this message is sent at least once within any of 4 consecutive occurrences of
3921 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3922 * cell then this message shall only be sent on BCCH Ext. */
3923 if (not cfg.bcch_extended) {
3924 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3925 } else {
3926 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3927 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003929 }
3930 }
3931 }
3932 if (cfg.si22_present) {
3933 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3934 * should not be sent in a cell where SoLSA is used (see rule viii). System
3935 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3936 * =2 and TC=6. */
3937 if (cfg.si16_present or cfg.si17_present) {
3938 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3939 }
3940 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3941 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003943 }
3944 if (not cfg.bcch_extended) {
3945 testcase.stop("Error: SI22 requires BCCH Extd!");
3946 } else {
3947 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3948 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3949 }
3950 }
3951}
3952
3953/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003954private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3955return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003956 timer T := duration;
3957 var SystemInformationVectorPerTc si_per_tc;
3958 var L1ctlDlMessage l1_dl;
3959
3960 /* initialize all per-TC vectors empty */
3961 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3962 si_per_tc[i] := {};
3963 }
3964
3965 /* flush all previous L1 queued msgs */
3966 pt.clear;
3967
3968 T.start;
3969 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003970 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003971 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3972 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3973 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003974 repeat;
3975 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003976
Harald Welte48494ca2018-02-25 16:59:50 +01003977 var integer tc := f_gsm_compute_tc(sig.frame_number);
3978 log("SI received at TC=", tc, ": ", sig.si);
3979 /* append to the per-TC bucket */
3980 si_per_tc[tc] := si_per_tc[tc] & { sig };
3981 repeat;
3982 }
3983 [] pt.receive { repeat; }
3984 [] T.timeout { }
3985 }
3986
3987 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3988 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3989 }
3990 log("si_per_tc=", si_per_tc);
3991 return si_per_tc;
3992}
3993
3994/* helper function: Set given SI via RSL + validate scheduling.
3995 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003996private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003997 var SystemInformationVectorPerTc si_per_tc;
3998 f_init_l1ctl();
3999 f_l1_tune(L1CTL);
4000
4001 /* Sample + Validate Scheduling */
4002 si_per_tc := f_l1_sample_si(L1CTL);
4003 f_validate_si_scheduling(si_cfg, si_per_tc);
4004
4005 setverdict(pass);
4006}
4007
4008testcase TC_si_sched_default() runs on test_CT {
4009 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004010 /* 2+3+4 are mandatory and set in f_init() */
4011 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004013}
4014
4015testcase TC_si_sched_1() runs on test_CT {
4016 f_init();
4017 si_cfg.si1_present := true;
4018 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004019 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004021}
4022
4023testcase TC_si_sched_2bis() runs on test_CT {
4024 f_init();
4025 si_cfg.si2bis_present := true;
4026 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4027 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004029}
4030
4031testcase TC_si_sched_2ter() runs on test_CT {
4032 f_init();
4033 si_cfg.si2ter_present := true;
4034 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4035 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004037}
4038
4039testcase TC_si_sched_2ter_2bis() runs on test_CT {
4040 f_init();
4041 si_cfg.si2bis_present := true;
4042 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4043 si_cfg.si2ter_present := true;
4044 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4045 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004047}
4048
4049testcase TC_si_sched_2quater() runs on test_CT {
4050 f_init();
4051 si_cfg.si2quater_present := true;
4052 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4053 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004055}
4056
4057testcase TC_si_sched_13() runs on test_CT {
4058 f_init();
4059 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004060 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004061 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004063}
4064
4065testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4066 f_init();
4067 si_cfg.si2bis_present := true;
4068 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4069 si_cfg.si2ter_present := true;
4070 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4071 si_cfg.si2quater_present := true;
4072 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4073 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004074 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004075 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004077}
4078
4079
Harald Welte68e495b2018-02-25 00:05:57 +01004080testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004081 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004082 /* FIXME: enable / disable individual BCCH info */
4083 //ts_RSL_BCCH_INFO(si_type, info);
4084 /* expect no ERROR REPORT after either of them *
4085 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004087}
4088
Harald Welte93640c62018-02-25 16:59:33 +01004089/***********************************************************************
4090 * Low-Level Protocol Errors / ERROR REPORT
4091 ***********************************************************************/
4092
Harald Welte01d982c2018-02-25 01:31:40 +01004093private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4094 timer T := 5.0;
4095 T.start;
4096 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004097 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004098 setverdict(pass);
4099 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004100 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004102 }
4103 [] RSL_CCHAN.receive {
4104 repeat;
4105 }
4106 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004108 }
4109 }
4110}
4111
4112/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4113testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004114 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004115 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4116 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004117 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004118
4119 f_exp_err_rep(RSL_ERR_PROTO);
4120}
4121
4122/* Provoke a mandatory IE error and match on ERROR REPORT */
4123testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004124 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004125
4126 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4127 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004128 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004129
4130 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4131}
4132
4133/* Provoke an IE content error and match on ERROR REPORT */
4134testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004135 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004136 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4137 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004138 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004139
4140 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4141}
4142
Harald Welteee25aae2019-05-19 14:32:37 +02004143/* attempt to activate channel with wrong RSL Message Discriminator IE */
4144function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4145 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4146 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4147 RSL.send(rsl);
4148 f_rslem_unregister(0, g_chan_nr);
4149}
4150testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4151 var ConnHdlr vc_conn;
4152 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4153
Harald Welte10474062019-05-30 16:48:17 +02004154 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004155
4156 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4157 vc_conn.done;
4158 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4159
4160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4161}
4162
4163/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004164private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004165 var template (value) RSL_Message rsl_tx;
4166 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4167 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4168 RSL.send(rsl_tx);
4169 f_rslem_unregister(0, g_chan_nr);
4170}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004171private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004172 var template (value) RSL_Message rsl_tx;
4173 /* we first have to activate the dedicated channel */
4174 f_rsl_chan_act(g_pars.chan_mode);
4175 /* ... to then send an invalid RLL message */
4176 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4177 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4178 RSL.send(rsl_tx);
4179 f_rslem_unregister(0, g_chan_nr);
4180}
4181testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4182 var ConnHdlr vc_conn;
4183 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4184 var template (value) RSL_Message rsl_tx;
4185
Harald Welte10474062019-05-30 16:48:17 +02004186 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004187
4188 /* Common Channel with wrong message type */
4189 RSL_CCHAN.clear;
4190 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4191 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004192 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004193 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4194
4195 /* TRX Management */
4196 RSL_CCHAN.clear;
4197 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4198 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004199 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004200 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4201
4202 /* Dedicated Channel */
4203 RSL_CCHAN.clear;
4204 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4205 vc_conn.done;
4206 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4207
4208 /* RLL */
4209 RSL_CCHAN.clear;
4210 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4211 vc_conn.done;
4212 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4213}
4214
4215/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004216private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004217 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4218 f_rslem_unregister(0, g_chan_nr);
4219}
4220testcase TC_err_rep_wrong_sequence() runs on test_CT {
4221 var ConnHdlr vc_conn;
4222 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4223
Harald Welte10474062019-05-30 16:48:17 +02004224 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004225
4226 RSL_CCHAN.clear;
4227 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4228 vc_conn.done;
4229 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4230}
4231
Harald Welte93640c62018-02-25 16:59:33 +01004232/***********************************************************************
4233 * IPA CRCX/MDCX/DLCS media stream handling
4234 ***********************************************************************/
4235
Harald Weltea871a382018-02-25 02:03:14 +01004236/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004237private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004238 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4239 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004240}
4241testcase TC_ipa_dlcx_not_active() runs on test_CT {
4242 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004243 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004244 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4245 vc_conn.done;
4246}
Harald Welte68e495b2018-02-25 00:05:57 +01004247
Harald Weltea3f1df92018-02-25 12:49:55 +01004248/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004249private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004250 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4251 "IPA CRCX ACK");
4252 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4253 "IPA CRCX NACK");
4254}
4255testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4256 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004257 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004258 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4259 vc_conn.done;
4260}
4261
4262/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004263private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004264 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4265 "IPA CRCX ACK");
4266 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4267 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4268 var uint7_t rtp_pt2 := f_rnd_int(127);
4269 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4270 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4271 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4272 "IPA MDCX ACK");
4273 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4274 "IPA DLCX ACK");
4275}
4276testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004278 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004279 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4280 vc_conn.done;
4281}
4282
Harald Welte3ae11da2018-02-25 13:36:06 +01004283/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004284private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004285 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4286 "IPA CRCX ACK");
4287 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4288 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4289 var uint7_t rtp_pt2 := f_rnd_int(127);
4290 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4291 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4292 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4293 "IPA MDCX ACK");
4294 /* Second MDCX */
4295 remote_ip := f_rnd_int(c_UINT32_MAX);
4296 remote_port := f_rnd_int(c_UINT16_MAX);
4297 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4298 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4299 "IPA MDCX ACK");
4300 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4301 "IPA DLCX ACK");
4302}
4303testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4304 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004305 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004306 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4307 vc_conn.done;
4308}
4309
Harald Welte9912eb52018-02-25 13:30:15 +01004310/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004311private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004312 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4313 "IPA CRCX NACK");
4314}
4315testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4316 var ConnHdlrPars pars;
4317 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004318 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004319
4320 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4321 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4322 vc_conn.done;
4323
4324 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4325 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4326 vc_conn.done;
4327}
4328
Harald Weltea3f1df92018-02-25 12:49:55 +01004329
Harald Welte883340c2018-02-28 18:59:29 +01004330/***********************************************************************
4331 * PCU Socket related tests
4332 ***********************************************************************/
4333
Harald Welte07bd2d22019-05-25 11:03:30 +02004334/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004335friend 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 +01004336runs on test_CT {
4337 timer T := 3.0;
4338
4339 /* we don't expect any RTS.req before PDCH are active */
4340 T.start;
4341 alt {
4342 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004344 }
4345 [] PCU.receive { repeat; }
4346 [] T.timeout { }
4347 }
4348
4349 /* Send PDCH activate request for known PDCH timeslot */
4350 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4351
4352 /* we now expect RTS.req for this timeslot (only) */
4353 T.start;
4354 alt {
4355 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4356 setverdict(pass);
4357 }
4358 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4359 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004361 }
4362 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004364 }
4365 [] PCU.receive { repeat; }
4366 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004368 }
4369 [not exp_success] T.timeout {
4370 setverdict(pass);
4371 }
4372 }
4373}
4374
Harald Welte07bd2d22019-05-25 11:03:30 +02004375/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004376friend 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 +01004377runs on test_CT {
4378 timer T := 3.0;
4379
4380 /* Send PDCH activate request for known PDCH timeslot */
4381 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
Harald Weltec87d81f2020-10-11 18:17:25 +02004382 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4383 * when it will actually have been executed in the BTS */
4384 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004385 PCU.clear;
4386 /* we now expect no RTS.req for this timeslot */
4387 T.start;
4388 alt {
4389 [] 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 +02004390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004391 }
4392 [] PCU.receive { repeat; }
4393 [] T.timeout {
4394 setverdict(pass);
4395 }
4396 }
4397}
4398
Harald Weltead033dc2019-05-25 17:28:16 +02004399friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004400 f_init();
4401 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4402}
4403
Harald Welte883340c2018-02-28 18:59:29 +01004404/* PDCH activation via PCU socket; check for presence of RTS.req */
4405testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004406 f_init_pcu_test();
4407
Harald Welte883340c2018-02-28 18:59:29 +01004408 f_TC_pcu_act_req(0, 0, 7, true);
4409}
4410
4411/* PDCH activation via PCU socket on non-PDCU timeslot */
4412testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004413 f_init_pcu_test();
4414
Harald Welte883340c2018-02-28 18:59:29 +01004415 f_TC_pcu_act_req(0, 0, 1, false);
4416}
4417
4418/* PDCH activation via PCU socket on wrong BTS */
4419testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004420 f_init_pcu_test();
4421
Harald Welte883340c2018-02-28 18:59:29 +01004422 f_TC_pcu_act_req(23, 0, 7, false);
4423}
4424
4425/* PDCH activation via PCU socket on wrong TRX */
4426testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004427 f_init_pcu_test();
4428
Harald Welte883340c2018-02-28 18:59:29 +01004429 f_TC_pcu_act_req(0, 23, 7, false);
4430}
4431
4432/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4433testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004434 f_init_pcu_test();
4435
Harald Welte883340c2018-02-28 18:59:29 +01004436 /* Activate PDCH */
4437 f_TC_pcu_act_req(0, 0, 7, true);
4438 f_sleep(1.0);
4439 /* and De-Activate again */
4440 f_TC_pcu_deact_req(0, 0, 7);
4441}
4442
4443/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4444testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004445 f_init_pcu_test();
4446
Harald Welte883340c2018-02-28 18:59:29 +01004447 f_TC_pcu_deact_req(0, 0, 1);
4448}
4449
4450/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4451testcase TC_pcu_ver_si13() runs on test_CT {
4452 const octetstring si13 := '00010203040506070909'O;
4453 var PCUIF_send_data sd;
4454 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004455 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004456
4457 /* Set SI13 via RSL */
4458 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004459
Harald Welte883340c2018-02-28 18:59:29 +01004460 T.start;
4461 alt {
4462 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4463 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4464 setverdict(pass);
4465 } else {
4466 repeat;
4467 }
4468 }
4469 [] PCU.receive { repeat; }
4470 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004472 }
4473 }
4474}
4475
4476private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4477
4478/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004479friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004480 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4481runs on test_CT
4482{
4483 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4484 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4485}
4486
4487/* 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 +02004488friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4489 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004490runs on test_CT
4491{
4492 var PCUIF_send_data sd;
4493
4494 timer T := 3.0;
4495 T.start;
4496 alt {
4497 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4498 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4499 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4500 sd.data.u.rts_req.fn, sapi, data);
4501 }
4502 [] PCU.receive { repeat; }
4503 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004505 }
4506 }
4507}
4508
4509/* Send DATA.req on invalid BTS */
4510testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004511 var TfiUsfArr tua := f_TfiUsfArrInit();
4512 var octetstring data := '0000'O & f_rnd_octstring(21);
4513
4514 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004515
Harald Welte883340c2018-02-28 18:59:29 +01004516 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004517 f_TfiUsfArrSet(tua, 7, 0);
4518 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4519 f_sleep(1.0);
4520
4521 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004522}
4523
4524/* Send DATA.req on invalid TRX */
4525testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004526 var TfiUsfArr tua := f_TfiUsfArrInit();
4527 var octetstring data := '0000'O & f_rnd_octstring(21);
4528
4529 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004530
Harald Welte883340c2018-02-28 18:59:29 +01004531 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004532 f_TfiUsfArrSet(tua, 7, 0);
4533 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4534 f_sleep(1.0);
4535
4536 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004537}
4538
4539/* Send DATA.req on invalid timeslot */
4540testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004541 var TfiUsfArr tua := f_TfiUsfArrInit();
4542 var octetstring data := '0000'O & f_rnd_octstring(21);
4543
4544 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004545
Harald Welte883340c2018-02-28 18:59:29 +01004546 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004547 f_TfiUsfArrSet(tua, 7, 0);
4548 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4549 f_sleep(1.0);
4550
4551 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004552}
4553
4554/* Send DATA.req on timeslot that hasn't been activated */
4555testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004556 var TfiUsfArr tua := f_TfiUsfArrInit();
4557 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004558
Harald Welte7162a612019-05-26 12:56:09 +02004559 f_virtphy_common();
4560
4561 f_TfiUsfArrSet(tua, 7, 0);
4562 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4563 f_sleep(1.0);
4564
4565 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004566}
4567
Harald Weltead033dc2019-05-25 17:28:16 +02004568private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004569 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4570 boolean wait_rts := true)
4571runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004572 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004573 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004574
4575 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004576 if (wait_rts) {
4577 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4578 } else {
4579 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4580 }
Harald Weltead033dc2019-05-25 17:28:16 +02004581
4582 T.start;
4583 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004584 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004585 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4586 setverdict(pass);
4587 }
Harald Welte7162a612019-05-26 12:56:09 +02004588 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4589 setverdict(fail, "Received unexpected ", rx_dl);
4590 }
Harald Weltead033dc2019-05-25 17:28:16 +02004591 [] L1CTL.receive {
4592 repeat;
4593 }
Harald Welte7162a612019-05-26 12:56:09 +02004594 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004595 setverdict(fail, "Timeout waiting for ", data);
4596 }
Harald Welte7162a612019-05-26 12:56:09 +02004597 [not expect_data] T.timeout {
4598 setverdict(pass);
4599 }
Harald Weltead033dc2019-05-25 17:28:16 +02004600 }
4601}
4602
4603private function f_disable_dynamic_ts() runs on test_CT
4604{
4605 f_init_vty_bsc();
4606 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4607 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4608 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4609 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004610 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004611}
4612
4613private function f_virtphy_common() runs on test_CT {
4614 f_disable_dynamic_ts();
4615 f_init_l1ctl();
4616 f_l1_tune(L1CTL);
4617}
4618
4619testcase TC_pcu_data_req_pdtch() runs on test_CT {
4620 var TfiUsfArr tua := f_TfiUsfArrInit();
4621 var octetstring data := '0000'O & f_rnd_octstring(21);
4622
4623 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004624
Harald Welte883340c2018-02-28 18:59:29 +01004625 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004626 f_TfiUsfArrSet(tua, 7, 0);
4627 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4628 f_sleep(1.0);
4629
4630 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004631}
4632
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004633/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004634testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004635 var TfiUsfArr tua := f_TfiUsfArrInit();
4636 var octetstring data := '0000'O & f_rnd_octstring(21);
4637
4638 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004639
Harald Welte883340c2018-02-28 18:59:29 +01004640 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004641 f_TfiUsfArrSet(tua, 7, 0);
4642 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4643 f_sleep(1.0);
4644
4645 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004646}
4647
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004648private function f_TC_pcu_ptcch_ul(uint16_t ra)
4649runs on test_CT {
4650 var template PCUIF_Message pcu_rach_ind;
4651 var PCUIF_send_data sd;
4652 var GsmFrameNumber fn;
4653 timer T;
4654
4655 /* Send an Access Burst on PTCCH/U over the Um-interface */
4656 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4657 chan_nr := ts_RslChanNr_PDCH(7),
4658 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4659
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004660 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4661 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004662
4663 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4664 T.start(52.0 * 4.615 / 1000.0);
4665 alt {
4666 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4667 log("Rx an Access Burst on the PCU interface: ", sd.data);
4668 setverdict(pass);
4669 T.stop;
4670 }
4671 [] PCU.receive { repeat; }
4672 [] T.timeout {
4673 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4674 /* Keep going, that's not the end of the world */
4675 }
4676 }
4677}
4678
4679testcase TC_pcu_ptcch() runs on test_CT {
4680 var L1ctlDlMessage dl;
4681 var octetstring data;
4682 timer T;
4683
4684 f_init_pcu_test();
4685 f_init_l1ctl();
4686 f_l1_tune(L1CTL);
4687
4688 /* Activate PDCH channel on TS7 */
4689 f_TC_pcu_act_req(0, 0, 7, true);
4690
4691 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004692 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004693 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004694 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004695 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004696
4697 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4698 for (var integer i := 0; i < 16; i := i + 1) {
4699 log("Sending an Access Burst towards the L1CTL interface");
4700 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4701 }
4702
4703 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4704 data := f_rnd_octstring(23);
4705
4706 /* Verify PTCCH/D: send a random data block, make sure it's received */
4707 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4708 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4709
4710 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4711 * let's give it more time in case if we miss the beginning. */
4712 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4713 alt {
4714 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4715 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4716 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4717 frame := data)) -> value dl {
4718 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4719 setverdict(pass);
4720 T.stop;
4721 }
4722 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4723 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4724 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4725 l2_data := data)) -> value dl {
4726 log("Rx PTCCH/D data block on L1CTL: ", dl);
4727 setverdict(pass);
4728 T.stop;
4729 }
4730 [] L1CTL.receive { repeat; }
4731 [] T.timeout {
4732 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4733 }
4734 }
4735}
4736
Harald Welte883340c2018-02-28 18:59:29 +01004737/* Send AGCH from PCU; check it appears on Um side */
4738testcase TC_pcu_data_req_agch() runs on test_CT {
4739 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004740 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004741 f_init_l1ctl();
4742 f_l1_tune(L1CTL);
4743
4744 f_TC_pcu_act_req(0, 0, 7, true);
4745 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4746
4747 T.start;
4748 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004749 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004750 setverdict(pass);
4751 }
4752 [] L1CTL.receive { repeat; }
4753 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004755 }
4756 }
4757}
4758
Harald Welte928622b2019-05-26 13:22:59 +02004759/* Send AGCH from PCU; check it appears on Um side */
4760testcase TC_pcu_data_req_pch() runs on test_CT {
4761 timer T := 3.0;
4762 f_init_pcu_test();
4763 f_init_l1ctl();
4764 f_l1_tune(L1CTL);
4765
4766 f_TC_pcu_act_req(0, 0, 7, true);
4767 /* three characters prefix: last 3 digits of IMSI as ASCII */
4768 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4769
4770 T.start;
4771 alt {
4772 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4773 setverdict(pass);
4774 }
4775 [] L1CTL.receive { repeat; }
4776 [] T.timeout {
4777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4778 }
4779 }
4780}
4781
Harald Welte883340c2018-02-28 18:59:29 +01004782/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4783testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4784 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004785 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004786 f_init_l1ctl();
4787 f_l1_tune(L1CTL);
4788
4789 /* append 3 last imsi digits so BTS can compute pagng group */
4790 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4791
4792 timer T := 0.5;
4793 T.start;
4794 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004795 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004796 /* TODO: verify paging group */
4797 setverdict(pass);
4798 }
4799 [] L1CTL.receive { repeat; }
4800 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004802 }
4803 }
4804}
4805
4806/* Send RACH from Um side, expect it to show up on PCU socket */
4807testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004808 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004809 f_init_l1ctl();
4810 f_l1_tune(L1CTL);
4811
4812 var GsmFrameNumber fn_last := 0;
4813 for (var integer i := 0; i < 1000; i := i+1) {
4814 var OCT1 ra := f_rnd_ra_ps();
4815 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4816 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004818 }
4819 fn_last := fn;
4820
4821 timer T := 2.0;
4822 T.start;
4823 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004824 [] 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 +01004825 T.stop;
4826 }
4827 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004829 }
4830 [] PCU.receive { repeat; }
4831 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004833 }
4834 }
4835 }
4836 setverdict(pass);
4837}
4838
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004839/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4840 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4841testcase TC_pcu_ext_rach_content() runs on test_CT {
4842 var template PCUIF_Message pcu_rach_ind;
4843 var GsmFrameNumber fn_last := 0;
4844 var L1ctlRachSynchSeq synch_seq;
4845 var PCUIF_BurstType pcu_bt;
4846 var GsmFrameNumber fn;
4847 var BIT11 ra11;
4848
4849 f_init_pcu_test();
4850 f_init_l1ctl();
4851 f_l1_tune(L1CTL);
4852
4853 for (var integer i := 0; i < 1000; i := i+1) {
4854 /* We need to test both TS1 & TS2 */
4855 if (i rem 2 == 0) {
4856 synch_seq := RACH_SYNCH_SEQ_TS1;
4857 pcu_bt := BURST_TYPE_1;
4858 } else {
4859 synch_seq := RACH_SYNCH_SEQ_TS2;
4860 pcu_bt := BURST_TYPE_2;
4861 }
4862
4863 ra11 := f_rnd_ra11_ps();
4864 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4865 if (fn == fn_last) {
4866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4867 "Two RACH in same FN?!?");
4868 }
4869 fn_last := fn;
4870
4871 /* Compose the expected message */
4872 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004873 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004874 ra := bit2int(ra11),
4875 is_11bit := 1,
4876 burst_type := pcu_bt,
4877 fn := fn);
4878
4879 timer T := 2.0;
4880 T.start;
4881 alt {
4882 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4883 T.stop;
4884 }
4885 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4887 }
4888 [] PCU.receive { repeat; }
4889 [] T.timeout {
4890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4891 }
4892 }
4893 }
4894 setverdict(pass);
4895}
4896
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004897private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4898runs on test_CT {
4899 var template PCUIF_send_data sdt;
4900 var PCUIF_send_data sd;
4901 var int16_t lqual_cb;
4902 timer T := 1.0;
4903
4904 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4905 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4906
4907 /* Send a random PDTCH frame over Um */
4908 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4909 '0000'O & f_rnd_octstring(21)));
4910
4911 T.start;
4912 alt {
4913 /* If expected link quality is above the threshold */
4914 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4915 lqual_cb := sd.data.u.data_ind.lqual_cb;
4916 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4917
4918 /* Make sure the actual link quality matches the expected value */
4919 if (not match(lqual_cb, lqual_cb_exp)) {
4920 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4921 "expected value ", lqual_cb_exp));
4922 } else {
4923 setverdict(pass);
4924 }
4925 }
4926 /* If expected link quality is below the threshold */
4927 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4929 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4930 }
4931 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4932 [] PCU.receive { repeat; }
4933 [lqual_cb_exp < thresh] T.timeout {
4934 log("Rx nothing, as expected");
4935 setverdict(pass);
4936 }
4937 [lqual_cb_exp >= thresh] T.timeout {
4938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4939 "Timeout waiting for PCUIF_DATA.ind");
4940 }
4941 }
4942}
4943
4944/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4945testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4946 f_init_pcu_test();
4947 PCU.clear;
4948
4949 f_init_l1ctl();
4950 f_l1_tune(L1CTL);
4951
4952 /* Activate a PDCH channel on TS7 */
4953 f_TC_pcu_act_req(0, 0, 7, true);
4954
4955 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004956 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004957 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004958 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004959 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004960
4961 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4962 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4963 var TrxcMessage ret;
4964
4965 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4966 valueof(ts_TRXC_FAKE_CI(i)));
4967
4968 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4969 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4970 }
4971}
4972
Harald Welte883340c2018-02-28 18:59:29 +01004973/* Send PAGING via RSL, expect it to shw up on PCU socket */
4974testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004975 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004976
4977 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004978 var MobileIdentityLV mi_lv;
4979 var octetstring mi_lv_enc;
4980 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004981 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004982
Harald Welte883340c2018-02-28 18:59:29 +01004983 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004984 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004985 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004986 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004987 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004988
4989 /* Fancy encoding for PCUIF */
4990 mi_lv := valueof(ts_MI_LV(mi));
4991 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4992 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004993
4994 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004995 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004996 T.start;
4997 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004998 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004999 }
5000 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005002 }
5003 [] PCU.receive { repeat; }
5004 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005006 }
5007 }
5008 }
5009 setverdict(pass);
5010}
5011
Harald Welted66c9b82019-05-25 09:03:15 +02005012/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5013testcase TC_pcu_time_ind() runs on test_CT {
5014 var PCUIF_send_data pcu_sd;
5015 var integer num_time_ind := 0;
5016 var integer first_fn, last_fn;
5017 var float test_duration := 5.0;
5018 timer T;
5019
5020 f_init_pcu_test();
5021 f_TC_pcu_act_req(0, 0, 7, true);
5022
5023 PCU.clear;
5024 T.start(test_duration);
5025 alt {
5026 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5027 num_time_ind := num_time_ind + 1;
5028 if (not isbound(first_fn)) {
5029 first_fn := pcu_sd.data.u.time_ind.fn;
5030 }
5031 last_fn := pcu_sd.data.u.time_ind.fn;
5032 repeat;
5033 }
5034 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5035 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5036 repeat;
5037 }
5038 [] PCU.receive {
5039 repeat;
5040 }
5041 [] T.timeout {}
5042 }
5043 var integer fn_expired := last_fn - first_fn;
5044 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5045
5046 /* verify the number of frames expired matches our expectation */
5047 const float c_GSM_FN_DURATION_MS := 4.61538;
5048 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005049 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005050 if (not match(fn_expired, t_fn_expected)) {
5051 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5052 }
5053
5054 /* There are three TIME.ind in every fn MOD 13 */
5055 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5056 /* Add some tolerance */
5057 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5058 if (not match(num_time_ind, t_time_ind_exp)) {
5059 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5060 }
5061
5062 setverdict(pass);
5063}
5064
Harald Welte4832c862019-05-25 14:57:18 +02005065/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5066testcase TC_pcu_rts_req() runs on test_CT {
5067 var PCUIF_send_data pcu_sd;
5068 var integer first_fn, last_fn;
5069 var integer num_rts_pdtch := 0;
5070 var integer num_rts_ptcch := 0;
5071 var float test_duration := 5.0;
5072 timer T;
5073
5074 f_init_pcu_test();
5075 f_TC_pcu_act_req(0, 0, 7, true);
5076
5077 PCU.clear;
5078 T.start(test_duration);
5079 alt {
5080 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5081 -> value pcu_sd {
5082 num_rts_pdtch := num_rts_pdtch + 1;
5083 if (not isbound(first_fn)) {
5084 first_fn := pcu_sd.data.u.rts_req.fn;
5085 }
5086 last_fn := pcu_sd.data.u.rts_req.fn;
5087 repeat;
5088 }
5089 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5090 -> value pcu_sd {
5091 num_rts_ptcch := num_rts_ptcch + 1;
5092 if (not isbound(first_fn)) {
5093 first_fn := pcu_sd.data.u.rts_req.fn;
5094 }
5095 last_fn := pcu_sd.data.u.rts_req.fn;
5096 repeat;
5097 }
5098 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5099 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5100 repeat;
5101 }
5102 [] PCU.receive {
5103 repeat;
5104 }
5105 [] T.timeout {}
5106 }
5107 var integer fn_expired := last_fn - first_fn;
5108 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5109 ", num_rts_ptcch=", num_rts_ptcch);
5110
5111 /* verify the number of frames expired matches our expectation */
5112 const float c_GSM_FN_DURATION_MS := 4.61538;
5113 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005114 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005115 if (not match(fn_expired, t_fn_expected)) {
5116 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5117 }
5118
5119 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5120 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5121 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5122 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5123 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5124 t_ptcch_exp);
5125 }
5126
5127 /* We have 12 PDTCH blocks every 52-multiframe */
5128 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5129 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5130 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5131 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5132 t_pdtch_exp);
5133 }
5134
5135 setverdict(pass);
5136}
5137
Harald Welte07bd2d22019-05-25 11:03:30 +02005138/* test for generating Abis side OML ALERT from the PCU */
5139testcase TC_pcu_oml_alert() runs on test_CT {
5140 var PCUIF_send_data pcu_sd;
5141 var integer num_time_ind := 0;
5142 var integer first_fn, last_fn;
5143 var float test_duration := 5.0;
5144 timer T;
5145
5146 f_init_pcu_test();
5147 f_TC_pcu_act_req(0, 0, 7, true);
5148
5149 /* re-connect CTRL port from BTS to BSC */
5150 f_ipa_ctrl_stop();
5151 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5152
5153 /* Send that OML Alert */
5154 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5155
5156 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5157 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5158 setverdict(pass);
5159}
5160
Harald Welteeaa9a862019-05-26 23:01:08 +02005161/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5162private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5163 var PCUIF_Message first_info;
5164 var integer pcu_conn_id := -1;
5165 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5166 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5167 var OCT4 tlli := '01020304'O;
5168 var OCT1 cause := '23'O;
5169 timer T := 5.0;
5170
5171 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5172
5173 f_l1_tune(L1CTL);
5174 RSL.clear;
5175
5176 f_est_dchan();
5177 L1CTL.clear;
5178
5179 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5180
5181 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5182 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5183 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5184
5185 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5186 T.start;
5187 alt {
5188 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5189 setverdict(pass);
5190 }
5191 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5192 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5193 }
5194 [] PCU.receive {
5195 repeat;
5196 }
5197 [] T.timeout {
5198 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5199 }
5200 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005201
5202 /* release the channel */
5203 f_rsl_chan_deact();
5204 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5205 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005206}
5207testcase TC_pcu_rr_suspend() runs on test_CT {
5208 var ConnHdlrPars pars;
5209 var ConnHdlr vc_conn;
5210
5211 f_init();
5212
5213 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5214 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5215 vc_conn.done;
5216}
Harald Welte07bd2d22019-05-25 11:03:30 +02005217
Harald Weltea2e0e942019-05-27 18:12:53 +02005218/* Ensure that PCUIF socket can accept only a single connection */
5219testcase TC_pcu_socket_connect_multi() runs on test_CT {
5220 timer T := 5.0;
5221
5222 /* this (among other things) establishes the first connection to the PCUIF socket */
5223 f_init();
5224
5225 /* try to establish a second connection, expect it to fail */
5226 PCU.send(UD_connect:{mp_pcu_socket, -1});
5227 T.start;
5228 alt {
5229 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5230 setverdict(pass);
5231 }
5232 [] PCU.receive(UD_connect_result:?) {
5233 setverdict(fail, "Unexpected unix domain connect result");
5234 }
5235 [] T.timeout {
5236 setverdict(pass);
5237 }
5238 }
5239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5240}
5241
Harald Weltec8effb72019-05-27 18:23:04 +02005242/* Ensure that PCUIF socket can disconnect + reconnect */
5243testcase TC_pcu_socket_reconnect() runs on test_CT {
5244 /* this (among other things) establishes the first connection to the PCUIF socket */
5245 f_init();
5246
5247 f_sleep(1.0);
5248
5249 f_pcuif_close(PCU, g_pcu_conn_id);
5250 g_pcu_conn_id := -1;
5251
5252 f_sleep(1.0);
5253
5254 /* re-connect */
5255 PCU.clear;
5256 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5257 setverdict(pass);
5258
5259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5260}
5261
Harald Weltebe030482019-05-27 22:29:35 +02005262/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005263private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5264runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005265 var L1ctlDlMessage l1_dl;
5266 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005267 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005268 timer T := 5.0;
5269 T.start;
5270 alt {
5271 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005272 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5273 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005274 repeat;
5275 }
5276 }
5277 [] pt.receive {
5278 repeat;
5279 }
5280 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5282 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005283 }
5284 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005285 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005286}
5287
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005288/* Check if GPRS Indicator is present in RR System Information of a given type */
5289private function f_si_has_gprs_indicator(RrMessageType si_type)
5290runs on test_CT return boolean {
5291 var SystemInformation si := f_get_si(L1CTL, si_type);
5292
5293 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005294 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005295 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005296 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005297 }
5298
5299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5300 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005301}
5302
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005303/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5304private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5305runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005306 /* don't call f_init() as this would connect PCU socket */
5307 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005308
5309 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005310 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005311 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005312
5313 f_init_l1ctl();
5314 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005315 f_sleep(2.0);
5316 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005317
5318 if (f_si_has_gprs_indicator(si_type)) {
5319 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005320 } else {
5321 setverdict(pass);
5322 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005323
Harald Weltebe030482019-05-27 22:29:35 +02005324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5325}
5326
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005327testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5328 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5329}
Harald Weltebe030482019-05-27 22:29:35 +02005330
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005331testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5332 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5333}
5334
5335/* Ensure that GPRS capability is advertised after PCU socket connect */
5336private function f_TC_pcu_socket_connect(RrMessageType si_type)
5337runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005338 /* this (among other things) establishes the first connection to the PCUIF socket */
5339 f_init();
5340 f_init_l1ctl();
5341 f_l1_tune(L1CTL);
5342
5343 f_sleep(2.0);
5344 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005345
5346 if (not f_si_has_gprs_indicator(si_type)) {
5347 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005348 } else {
5349 setverdict(pass);
5350 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005351
Harald Weltebe030482019-05-27 22:29:35 +02005352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5353}
5354
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005355testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5356 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5357}
Harald Weltebe030482019-05-27 22:29:35 +02005358
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005359testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5360 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5361}
5362
5363/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5364private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5365runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005366 /* this (among other things) establishes the first connection to the PCUIF socket */
5367 f_init();
5368 f_init_l1ctl();
5369 f_l1_tune(L1CTL);
5370
5371 f_pcuif_close(PCU, g_pcu_conn_id);
5372 g_pcu_conn_id := -1;
5373
5374 f_sleep(1.0);
5375
5376 /* re-connect */
5377 PCU.clear;
5378 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5379
5380 f_sleep(2.0);
5381 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005382
5383 if (f_si_has_gprs_indicator(si_type)) {
5384 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005385 } else {
5386 setverdict(pass);
5387 }
5388
5389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5390}
5391
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005392testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5393 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5394}
5395
5396testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5397 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5398}
5399
Oliver Smithf5239c72019-08-28 10:01:25 +02005400/* 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) */
5401testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5402 var SystemInformation si3 := valueof(ts_SI3_default);
5403
5404 f_init();
5405
Harald Welte76220222020-10-11 20:32:44 +02005406 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5407 * information */
5408 timer T := 2.0;
5409 T.start;
5410 alt {
5411 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5412 [] T.timeout {}
5413 }
5414
Oliver Smithf5239c72019-08-28 10:01:25 +02005415 /* Verify cell_id */
5416 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5417 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5418 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005419 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5420 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5421 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005422 }
5423
5424 /* Verify LAC */
5425 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5426 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5427 if (lac_si3 != lac_pcu) {
5428 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5429 }
5430
5431 setverdict(pass);
5432}
Harald Welted66c9b82019-05-25 09:03:15 +02005433
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005434/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5435testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5436 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005437 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005438
5439 f_init();
5440
5441 info_ind := g_pcu_last_info.u.info_ind;
5442
5443 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5444 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5445 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5446 /* Skip inactive timeslots */
5447 continue;
5448 }
5449
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005450 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005451 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005452 else
5453 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005454
5455 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005456 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005457 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005458 hsn := fhp.maio_hsn.hsn,
5459 maio := fhp.maio_hsn.maio,
5460 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005461 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005462 } else {
5463 tr_ts := tr_PCUIF_InfoTrxTsH0;
5464 }
5465
5466 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5467 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5468 if (not match(ts, tr_ts)) {
5469 setverdict(fail, "Hopping parameters do not match: ",
5470 "received ", ts, " vs expected ", tr_ts);
5471 } else {
5472 setverdict(pass);
5473 }
5474 }
5475 }
5476}
5477
Alexander Couzens5283f552020-07-28 15:39:04 +02005478/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5479testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5480 f_init_vty_bsc();
5481 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5482 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5483
5484 f_init();
5485
5486 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5487 if (not ischosen(remote_addr.v10)) {
5488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5489 log2str("Unexpected remote_addr: ", remote_addr));
5490 }
5491
5492 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5493 setverdict(fail, "Received address family is not IPv4");
5494 }
5495
5496 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5497 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5498 }
5499
5500 setverdict(pass);
5501}
5502
5503/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5504testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5505 f_init_vty_bsc();
5506 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5507
5508 f_init();
5509
5510 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5511 if (not ischosen(remote_addr.v10)) {
5512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5513 log2str("Unexpected remote_addr: ", remote_addr));
5514 }
5515
5516 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5517 setverdict(fail, "Received address family is not IPv6");
5518 }
5519
5520 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5521 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5522 }
5523
5524 setverdict(pass);
5525}
5526
Harald Welte3d04ae62018-04-04 20:29:05 +02005527/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005528 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005529 ***********************************************************************/
5530
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005531private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5532 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005533runs on ConnHdlr {
5534 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005535
5536 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005537 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005538 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5539 repeat;
5540 }
5541 }
5542}
5543
5544private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5545runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005546 /* Expect BTS to immediately acknowledge activation as PDCH */
5547 PCU.clear;
5548 f_rsl_chan_act(g_pars.chan_mode);
5549 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005550 timer T_wait := 2.0;
5551 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005552 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005553 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005554 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005555 [] T_wait.timeout {
5556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5557 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5558 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005559 }
5560 /* try to activate this PDCH from the PCU point of view */
5561 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5562 /* FIXME: is there a response? */
5563}
5564
5565private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5566runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005567 /* Send RSL CHAN REL (deactivate) */
5568 PCU.clear;
5569 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5570 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005571 timer T_wait := 2.0;
5572 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005573 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005574 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005575 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005576 [] T_wait.timeout {
5577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5578 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5579 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005580 }
5581 /* Emulate PCU asking BTS to deactivate PDCH */
5582 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5583 alt {
5584 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5585 setverdict(pass);
5586 }
5587 [] RSL.receive { repeat; }
5588 }
5589}
5590
5591/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005592private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005593 var PCUIF_Message first_info;
5594 var integer ts_nr := g_chan_nr.tn;
5595 var integer trx_nr := 0;
5596 var integer bts_nr := 0;
5597 var integer pcu_conn_id := -1;
5598
5599 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5600
5601 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5602 f_sleep(3.0);
5603 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5604 setverdict(pass);
5605}
5606testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5607 var ConnHdlrPars pars;
5608 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005609 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005610
5611 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5612 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5613 vc_conn.done;
5614}
5615
5616/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005617private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005618 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005619 var integer pcu_conn_id := -1;
5620
5621 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5622
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005623 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5624 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5625 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005626 setverdict(pass);
5627}
5628testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5629 var ConnHdlrPars pars;
5630 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005631 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005632
5633 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5634 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5635 vc_conn.done;
5636}
5637
5638/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005639private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005640 var PCUIF_Message first_info;
5641 var integer ts_nr := g_chan_nr.tn;
5642 var integer trx_nr := 0;
5643 var integer bts_nr := 0;
5644 var integer pcu_conn_id := -1;
5645
5646 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5647
5648 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005649 /* Send a second Chan Activ and expect it to be NACKed */
5650 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5651 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005652 setverdict(pass);
5653}
5654testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5655 var ConnHdlrPars pars;
5656 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005657 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005658
5659 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5660 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5661 vc_conn.done;
5662}
5663
5664/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005665private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005666 var PCUIF_Message first_info;
5667 var integer ts_nr := g_chan_nr.tn;
5668 var integer trx_nr := 0;
5669 var integer bts_nr := 0;
5670 var integer pcu_conn_id := -1;
5671 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5672
5673 /* register for the TCH/F channel number */
5674 f_rslem_register(0, chan_nr);
5675
5676 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5677
5678 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5679 "RSL CHAN ACT");
5680 setverdict(pass);
5681}
5682testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5683 var ConnHdlrPars pars;
5684 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005685 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005686
5687 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5688 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5689 vc_conn.done;
5690}
5691
5692/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005693private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005694 var PCUIF_Message first_info;
5695 var integer ts_nr := g_chan_nr.tn;
5696 var integer trx_nr := 0;
5697 var integer bts_nr := 0;
5698 var integer pcu_conn_id := -1;
5699 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5700 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5701
5702 /* register for the TCH/H channel numbers */
5703 f_rslem_register(0, chan_nr[0]);
5704 f_rslem_register(0, chan_nr[1]);
5705
5706 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5707
5708 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5709 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5710 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5711 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5712 setverdict(pass);
5713}
5714testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5715 var ConnHdlrPars pars;
5716 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005717 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005718
5719 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5720 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5721 vc_conn.done;
5722}
5723
Harald Welte9bbbfb52018-04-05 09:33:19 +02005724/***********************************************************************
5725 * IPA Style Dynamic Timeslot Support
5726 ***********************************************************************/
5727
5728private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5729runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005730 /* Expect BTS to immediately acknowledge activation as PDCH */
5731 PCU.clear;
5732 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5733 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005734 timer T_wait := 2.0;
5735 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005736 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005737 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005738 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005739 [] T_wait.timeout {
5740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5741 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5742 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005743 }
5744 /* try to activate this PDCH from the PCU point of view */
5745 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5746 /* FIXME: is there a response? */
5747
5748 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5749}
5750
5751private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5752runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005753 /* Send RSL CHAN REL (deactivate) */
5754 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5755 PCU.clear;
5756 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005757 timer T_wait := 2.0;
5758 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005759 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005760 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005761 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005762 [] T_wait.timeout {
5763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5764 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5765 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005766 }
5767 /* Emulate PCU asking BTS to deactivate PDCH */
5768 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5769 alt {
5770 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5771 setverdict(pass);
5772 }
5773 [] RSL.receive { repeat; }
5774 }
5775}
5776
5777/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005778private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005779 var PCUIF_Message first_info;
5780 var integer ts_nr := g_chan_nr.tn;
5781 var integer trx_nr := 0;
5782 var integer bts_nr := 0;
5783 var integer pcu_conn_id := -1;
5784
5785 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5786
5787 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5788 f_sleep(3.0);
5789 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5790
5791 setverdict(pass);
5792
5793}
5794testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5795 var ConnHdlrPars pars;
5796 var ConnHdlr vc_conn;
5797 f_init();
5798
5799 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5800 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5801 vc_conn.done;
5802}
5803
5804/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005805private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005806 var PCUIF_Message first_info;
5807 var integer ts_nr := g_chan_nr.tn;
5808 var integer trx_nr := 0;
5809 var integer bts_nr := 0;
5810 var integer pcu_conn_id := -1;
5811
5812 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5813
5814 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5815 "RSL CHAN ACT");
5816 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5817 "RF CHAN REL", true);
5818 setverdict(pass);
5819}
5820testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5821 var ConnHdlrPars pars;
5822 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005823 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005824
5825 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5826 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5827 vc_conn.done;
5828}
5829
5830/* 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 +07005831private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005832 var PCUIF_Message first_info;
5833 var integer ts_nr := g_chan_nr.tn;
5834 var integer trx_nr := 0;
5835 var integer bts_nr := 0;
5836 var integer pcu_conn_id := -1;
5837
5838 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5839
5840 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5841 "RSL CHAN ACT");
5842
5843 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5844 alt {
5845 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5846 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005848 }
5849 [] RSL.receive { repeat; }
5850 }
5851
5852 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5853 "RF CHAN REL", true);
5854 setverdict(pass);
5855}
5856testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5857 var ConnHdlrPars pars;
5858 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005859 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005860
5861 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5862 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5863 vc_conn.done;
5864}
5865
5866/* 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 +07005867private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005868 var PCUIF_Message first_info;
5869 var integer ts_nr := g_chan_nr.tn;
5870 var integer trx_nr := 0;
5871 var integer bts_nr := 0;
5872 var integer pcu_conn_id := -1;
5873
5874 /* register for the TCH/F channel number */
5875 f_rslem_register(0, g_chan_nr);
5876
5877 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5878
5879 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5880
5881 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5882 "RSL CHAN ACT");
5883
5884 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5885
5886 setverdict(pass);
5887}
5888testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5889 var ConnHdlrPars pars;
5890 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005891 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005892
5893 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5894 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5895 vc_conn.done;
5896}
5897
5898
Harald Welte0472ab42018-03-12 15:02:26 +01005899/***********************************************************************
5900 * LAPDm / RLL related
5901 ***********************************************************************/
5902
5903private function f_tx_lapdm(template (value) LapdmFrame l,
5904 template (value) RslLinkId link_id) runs on ConnHdlr {
5905 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005906 var template (value) SacchL1Header l1h;
5907
5908 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005909 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005910 /* Compose dummy L1 header */
5911 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5912 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 +02005913 } else {
5914 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005915 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 +01005916 }
Harald Welte0472ab42018-03-12 15:02:26 +01005917}
5918
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005919private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005920 uint3_t sapi,
5921 RslLinkId link_id,
5922 octetstring l3,
5923 boolean exp
5924}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005925private type record of RllTestCase RllTestCases;
5926private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5927 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005928 sapi := sapi,
5929 link_id := id,
5930 l3 := l3,
5931 exp := exp
5932}
5933
5934/* execute the same callback function with a set of different parameters (tcs) on a
5935 * variety of logical channels */
5936private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5937 var ConnHdlrPars pars;
5938 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005939 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005940
5941 /* test on each of the channels we have */
5942 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5943 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5944
5945 /* test each of the test cases on the current channel */
5946 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5947 pars.spec.rll := tcs[j];
5948 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5949 vc_conn := f_start_handler(fn, pars);
5950 vc_conn.done;
5951 }
5952 }
5953
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005955}
5956
5957/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5958private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5959 var RllTestCase tc := g_pars.spec.rll;
5960 timer T := 3.0;
5961
5962 f_l1_tune(L1CTL);
5963 RSL.clear;
5964
5965 /* activate the logical channel */
5966 f_est_dchan();
5967 L1CTL.clear;
5968
5969 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5970 T.start;
5971 alt {
5972 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5973 if (tc.exp) {
5974 setverdict(pass);
5975 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005977 }
5978 }
5979 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5980 if (tc.exp) {
5981 setverdict(pass);
5982 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005984 }
5985 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005986 /* We also expect to receive the measurements */
5987 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005988 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005990 }
5991 [not tc.exp] T.timeout {
5992 setverdict(pass);
5993 }
5994 }
5995
5996 f_rsl_chan_deact();
5997 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5998 f_rslem_unregister(0, g_chan_nr);
5999}
6000testcase TC_rll_est_ind() runs on test_CT {
6001 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006002 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006003 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006004 /* normal SAPI0 establishment */
6005 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006006 /* SAPI 3 doesn't support contention resolution */
6007 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6008 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6009 /* normal SAPI3 establishment on main DCCH */
6010 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6011 /* normal SAPI3 establishment on SACCH */
6012 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6013 };
6014 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6015}
6016
6017/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6018private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6019 var RllTestCase tc := g_pars.spec.rll;
6020 var L1ctlDlMessage dl;
6021 timer T := 3.0;
6022
6023 f_l1_tune(L1CTL);
6024 RSL.clear;
6025
6026 /* activate the logical channel */
6027 f_est_dchan();
6028 L1CTL.clear;
6029
6030 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6031 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6032 T.start;
6033 alt {
6034 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6035 var LapdmFrame lapdm;
6036 var octetstring l2 := dl.payload.data_ind.payload;
6037 if (dl.dl_info.link_id.c == SACCH) {
6038 /* remove L1 header */
6039 l2 := substr(l2, 2, lengthof(l2)-2);
6040 }
6041 lapdm.ab := dec_LapdmFrameAB(l2);
6042 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6043 setverdict(pass);
6044 } else {
6045 repeat;
6046 }
6047 }
6048 [] L1CTL.receive { repeat; }
6049 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006051 }
6052 }
6053
6054 f_rsl_chan_deact();
6055 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6056 f_rslem_unregister(0, g_chan_nr);
6057}
6058testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6059 var RllTestCases tcs := {
6060 /* normal SAPI3 establishment on main DCCH */
6061 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6062 };
6063 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6064}
6065testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6066 var RllTestCases tcs := {
6067 /* normal SAPI3 establishment on SACCH */
6068 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6069 }
6070 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6071}
6072
6073/* altstep to receive a LAPDm frame matching the given template */
6074private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6075 var L1ctlDlMessage dl;
6076 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6077 var LapdmFrame lapdm;
6078 var octetstring l2 := dl.payload.data_ind.payload;
6079 if (dl.dl_info.link_id.c == SACCH) {
6080 /* remove L1 header */
6081 l2 := substr(l2, 2, lengthof(l2)-2);
6082 }
6083 if (ischosen(exp.ab)) {
6084 lapdm.ab := dec_LapdmFrameAB(l2);
6085 } else if (ischosen(exp.b4)) {
6086 lapdm.b4 := dec_LapdmFrameB4(l2);
6087 } else if (ischosen(exp.bbis)) {
6088 lapdm.bbis := dec_LapdmFrameBbis(l2);
6089 }
6090 log("Rx LAPDm ", lapdm);
6091 if (match(lapdm, exp)) {
6092 setverdict(pass);
6093 } else {
6094 repeat;
6095 }
6096 }
6097 [] L1CTL.receive { repeat; }
6098}
6099private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6100 timer T := t;
6101 T.start;
6102 alt {
6103 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006105 }
6106 [] as_l1_exp_lapdm(exp);
6107 }
6108}
6109
6110/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6111private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6112 /* send SABM from MS -> BTS */
6113 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6114 /* expect RLL EST IND on Abis */
6115 alt {
6116 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6117 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6118 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006120 }
6121 [] RSL.receive { repeat; }
6122 }
6123 /* expect UA from BTS -> MS */
6124 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6125}
6126
6127/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6128private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6129 var RllTestCase tc := g_pars.spec.rll;
6130
6131 f_l1_tune(L1CTL);
6132 RSL.clear;
6133
6134 /* activate the logical channel */
6135 f_est_dchan();
6136 L1CTL.clear;
6137
6138 /* first establish the link-layer */
6139 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6140
6141 /* then send the DISC */
6142 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6143 /* ... and expect the REL IND on the RSL side */
6144 alt {
6145 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6146 setverdict(pass);
6147 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006148 /* We also expect to receive the measurements */
6149 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006150 }
6151
6152 /* release the channel */
6153 f_rsl_chan_deact();
6154 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6155 f_rslem_unregister(0, g_chan_nr);
6156}
6157testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6158 var RllTestCases tcs := {
6159 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6160 };
6161 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6162}
6163
6164testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6165 var RllTestCases tcs := {
6166 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6167 };
6168 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6169}
6170testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6171 var RllTestCases tcs := {
6172 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6173 };
6174 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6175}
6176testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6177 var RllTestCases tcs := {
6178 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6179 };
6180 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6181}
6182
6183/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6184private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6185 var RllTestCase tc := g_pars.spec.rll;
6186 f_l1_tune(L1CTL);
6187 RSL.clear;
6188
6189 /* activate the logical channel */
6190 f_est_dchan();
6191 L1CTL.clear;
6192
6193 /* first establish the link-layer */
6194 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6195
6196 /* then send the REL REQ via RSL */
6197 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6198 /* ... and expect the DISC on the Um side */
6199 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006200 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006201 /* FIXME: send a UA in resposne to the DISC */
6202 }
6203 }
6204
6205 /* release the channel */
6206 f_rsl_chan_deact();
6207 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6208 f_rslem_unregister(0, g_chan_nr);
6209}
6210testcase TC_rll_rel_req() runs on test_CT {
6211 var RllTestCases tcs := {
6212 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6213 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6214 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6215 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6216 };
6217 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6218}
6219
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006220/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006221testcase TC_rll_data_req() runs on test_CT {
6222}
6223
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006224/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006225testcase TC_rll_data_ind() runs on test_CT {
6226}
6227
6228/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6229private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6230 var RllTestCase tc := g_pars.spec.rll;
6231
6232 f_l1_tune(L1CTL);
6233 RSL.clear;
6234
6235 f_est_dchan();
6236 L1CTL.clear;
6237
6238 /* Send UNITDATA REQ on RSL side */
6239 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6240 /* Expect it to arrive on the other side */
6241 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006242 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006243 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006244 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006245 }
6246
6247 /* release the channel */
6248 f_rsl_chan_deact();
6249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6250 f_rslem_unregister(0, g_chan_nr);
6251}
6252testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6253 var octetstring l3 := f_rnd_octstring(15);
6254 var RllTestCases tcs := {
6255 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6256 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6257 };
6258 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6259}
6260testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6261 var octetstring l3 := f_rnd_octstring(19);
6262 var RllTestCases tcs := {
6263 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6264 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6265 };
6266 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6267}
6268
6269/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6270private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6271 var RllTestCase tc := g_pars.spec.rll;
6272
6273 f_l1_tune(L1CTL);
6274 RSL.clear;
6275
6276 f_est_dchan();
6277 L1CTL.clear;
6278
6279 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006280 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006281 /* Expdct RLL UNITDATA IND on RSL side */
6282 alt {
6283 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6284 setverdict(pass);
6285 }
6286 [] RSL.receive { repeat; }
6287 }
6288
6289 /* release the channel */
6290 f_rsl_chan_deact();
6291 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6292 f_rslem_unregister(0, g_chan_nr);
6293}
6294testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006295 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006296 var RllTestCases tcs := {
6297 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6298 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6299 };
6300 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6301}
6302testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6303 var octetstring l3 := f_rnd_octstring(18);
6304 var RllTestCases tcs := {
6305 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6306 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6307 };
6308 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6309}
6310
Harald Weltee613f962018-04-18 22:38:16 +02006311/***********************************************************************
6312 * Encryption Related
6313 ***********************************************************************/
6314
6315/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006316private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006317 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6318 if (link_id.c == SACCH) {
6319 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6320 } else {
6321 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6322 }
6323}
6324
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006325/* Expect (or not expect) other kinds of messages */
6326private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6327 [exp_any] RSL.receive { repeat; }
6328 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006330 }
6331}
6332
Harald Weltee613f962018-04-18 22:38:16 +02006333/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006334private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006335 RslLinkId link_id,
6336 octetstring l3,
6337 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006338 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006339) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006340 timer T := 3.0;
6341 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6342 T.start;
6343 /* Expect RLL UNITDATA IND on RSL side */
6344 alt {
6345 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6346 setverdict(pass);
6347 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006348 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006349 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006350 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006352 }
Harald Weltee613f962018-04-18 22:38:16 +02006353 }
6354}
6355
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006356/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6357private function f_data_mo(
6358 RslLinkId link_id,
6359 boolean p, uint3_t nr, uint3_t ns,
6360 octetstring l3,
6361 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006362 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006363) runs on ConnHdlr {
6364 timer T := 3.0;
6365 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6366 T.start;
6367 /* Expect RLL DATA IND on RSL side */
6368 alt {
6369 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6370 setverdict(pass);
6371 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006372 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006373 [] as_rsl_any_ind(exp_any);
6374 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006376 }
6377 }
6378}
6379
Harald Weltee613f962018-04-18 22:38:16 +02006380/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006381private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006382 f_l1_tune(L1CTL);
6383 f_est_dchan(true);
6384
6385 /* now we actually need to transmit some data both ways to check if the encryption works */
6386 var L1ctlDlMessage dl;
6387
Stefan Sperling603d98e2018-07-25 16:47:28 +02006388 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006389 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6390
6391 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6392 f_unitdata_mt(link_id, l3);
6393
6394 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6395 f_unitdata_mo(link_id, l3);
6396
6397 /* release the channel */
6398 f_rsl_chan_deact();
6399 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6400 f_rslem_unregister(0, g_chan_nr);
6401}
6402testcase TC_chan_act_a51() runs on test_CT {
6403 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6404 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6405 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6406}
6407testcase TC_chan_act_a52() runs on test_CT {
6408 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6409 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6410 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6411}
6412testcase TC_chan_act_a53() runs on test_CT {
6413 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6414 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6415 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6416}
6417
Eric Wildf1827a72019-05-28 17:37:35 +02006418/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6419 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 +07006420private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006421 f_l1_tune(L1CTL);
6422 f_est_dchan(true);
6423
6424 /* now we actually need to transmit some data both ways to check if the encryption works */
6425 var L1ctlDlMessage dl;
6426
6427 var octetstring l3 := f_rnd_octstring(20);
6428 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6429
6430 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6431 f_unitdata_mt(link_id, l3);
6432
6433 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6434 f_unitdata_mo(link_id, l3);
6435
6436 var RSL_Message rsl;
6437 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6438
6439 /* modify key to break proper encryption */
6440 g_pars.encr.key := f_rnd_octstring(8);
6441 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6442 rsl.ies := rsl.ies & { ei };
6443 RSL.send(rsl);
6444
6445 timer T0 := 1.0;
6446 T0.start;
6447 /* Expect RSL MODIFY ACK */
6448 alt {
6449 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6450 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6452 }
6453 [] T0.timeout {
6454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6455 }
6456 }
6457
6458 var octetstring l3msg := f_rnd_octstring(15);
6459 timer T1 := 3.0;
6460 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6461 due to broken encryption */
6462 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6463 T1.start;
6464 alt {
6465 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6467 }
6468 [] T1.timeout {
6469 setverdict(pass);
6470 }
6471 }
6472
6473 /* release the channel */
6474 f_rsl_chan_deact();
6475 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6476 f_rslem_unregister(0, g_chan_nr);
6477}
6478testcase TC_rsl_modify_encr() runs on test_CT {
6479 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6480 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6481 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6482}
Harald Weltee613f962018-04-18 22:38:16 +02006483
6484/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006485private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006486 /* L3 payload doesn't matter, as it is passed transparently */
6487 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6488 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6489 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6490
6491 f_l1_tune(L1CTL);
6492
6493 /* first establish a dedicated channel in the clear */
6494 f_est_dchan(false);
6495
6496 /* Establish ABM */
6497 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6498
6499 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6500 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6501 /* expect the L3 to arrive still unencrypted on the MS side */
6502 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6503
6504 /* configure L1 to apply ciphering */
6505 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6506 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6507
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006508 /* send first ciphered I-frame in response and expect it on RSL */
6509 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006510
6511 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6512 * and hence enable encryption also on the downlink */
6513
6514 /* expect bi-directional communication work in encrypted mode */
6515 f_unitdata_mo(link_id, f_rnd_octstring(15));
6516 f_unitdata_mt(link_id, f_rnd_octstring(15));
6517
6518 /* release the channel */
6519 f_rsl_chan_deact();
6520 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6521 f_rslem_unregister(0, g_chan_nr);
6522}
6523testcase TC_encr_cmd_a51() runs on test_CT {
6524 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6525 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6526 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6527}
6528testcase TC_encr_cmd_a52() runs on test_CT {
6529 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6530 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6531 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6532}
6533testcase TC_encr_cmd_a53() runs on test_CT {
6534 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6535 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6536 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6537}
6538
6539private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6540 var LapdmFrame lf;
6541 var octetstring reenc;
6542
6543 /* decode the LAPDm frame */
6544 if (ischosen(exp_match.ab)) {
6545 lf.ab := dec_LapdmFrameAB(enc);
6546 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006548 }
6549
6550 /* check if decoder result matches expectation */
6551 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006553 } else {
6554 log(name, ": matched");
6555 setverdict(pass);
6556 }
6557
6558 /* test if re-encoded frame equals original input */
6559 reenc := enc_LapdmFrame(lf);
6560 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006562 } else {
6563 setverdict(pass);
6564 }
6565}
6566
6567testcase TC_lapdm_selftest() runs on test_CT {
6568 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6569 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6570 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6571 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6572 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6573 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6574 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6575}
6576
Stefan Sperling4880be42018-08-07 18:12:59 +02006577/***********************************************************************
6578 * DTX Related (see GSM 05.08, section 8.3)
6579 ***********************************************************************/
6580
6581/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006582private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006583 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6584 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6585 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6586 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6587}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006588private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006589 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6590 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6591}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006592private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006593 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6594 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6595 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6596 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6597}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006598private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6600 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6601 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6602 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6603 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6604 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6605 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6606 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6607}
6608
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006609private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006610 var L1ctlDlMessage dl;
6611 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6612 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6613 var GsmFrameNumber first_fn;
6614 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006615 var integer nfill_frames_sacch := 0;
6616 var integer nfill_frames_nonsacch := 0;
6617 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006618 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6619 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006620 const integer frame_dtx_tchf_mod := 104;
6621 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6622 * which operates in terms of blocks rather than frames. */
6623 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6624 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006625 timer T := 5.0;
6626
6627 f_l1_tune(L1CTL);
6628 RSL.clear;
6629 L1CTL.clear;
6630
6631 /* activate TCHF signalling channel */
6632 f_est_dchan(false);
6633
6634 T.start;
6635 alt {
6636 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6637 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6638 var octetstring l2 := dl.payload.data_ind.payload;
6639
6640 if (is_first_frame) {
6641 is_first_frame := false;
6642 first_fn := dl.dl_info.frame_nr;
6643 }
6644
6645 if (dl.dl_info.link_id.c == SACCH) {
6646 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6647 if (not match(l2_fill_frame_sacch, l2)) {
6648 repeat;
6649 }
6650 } else if (not match(l2_fill_frame, l2)) {
6651 repeat;
6652 }
6653
6654 if (dtxd) {
6655 if (not f_g_chan_is_tchf()) {
6656 T.stop;
6657 f_rsl_chan_deact();
6658 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006659 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 +02006660 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006661 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006662 T.stop;
6663 f_rsl_chan_deact();
6664 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006665
6666 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6667 * 2 SACCH, 1 TCH/F */
6668 expected_fill_frames := 3;
6669
6670 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6671 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6672 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006674 } else {
6675 setverdict(pass);
6676 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006677 } else {
6678 if (dl.dl_info.link_id.c == SACCH) {
6679 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006680 repeat;
6681 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006682 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6683 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6684 * we should only see the subset of frames numbers which correspond to a block boundary.
6685 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6686 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6687 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6688 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6689 repeat;
6690 }
6691 }
6692 log("Received DTX TCH fill frame with bad frame number: ", fn,
6693 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6694 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6695 f_rsl_chan_deact();
6696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006698 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006699 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006700 if (dl.dl_info.link_id.c == SACCH) {
6701 nfill_frames_sacch := nfill_frames_sacch + 1;
6702 } else {
6703 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6704 }
6705 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006706 T.stop;
6707 if (f_g_chan_is_tchf()) {
6708 /* Without DTX we can expect 25 fill frames for every 104 frames.
6709 * (24 FACCH + 1 SACCH filling) */
6710 expected_fill_frames := 25;
6711 } else if (f_g_chan_is_tchh()) {
6712 /* We can expect 2 fill frames for every 104 frames. */
6713 expected_fill_frames := 2;
6714 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6715 /* We can expect 5 fill frames for every 104 frames. */
6716 expected_fill_frames := 5;
6717 } else {
6718 f_rsl_chan_deact();
6719 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006721 }
6722
6723 f_rsl_chan_deact();
6724 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006725
6726 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006727 setverdict(pass);
6728 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006729 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6730 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006732 }
6733 } else {
6734 repeat;
6735 }
6736 }
6737 }
6738 [] L1CTL.receive { repeat; }
6739 [] T.timeout {
6740 f_rsl_chan_deact();
6741 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006743 }
6744 }
6745}
6746
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006747private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006748 f_test_l2_fill_frames(false);
6749}
6750
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006751private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006752 f_test_l2_fill_frames(true);
6753}
6754
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006755private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006756 var ConnHdlr vc_conn;
6757 var ConnHdlrPars pars;
6758 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006759 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006760 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6761 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6762 if (dtxd) {
6763 if (i >= 4) { /* DTX is only allowed on TCH/F */
6764 break;
6765 }
6766 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6767 } else {
6768 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6769 }
6770 vc_conn.done;
6771 }
6772}
6773
6774/* Verify that L2 fill frames are sent on TCH in signaling mode if
6775 * there is nothing to transmit while DTX is disabled on downlink. */
6776testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6777 f_tch_sign_l2_fill_frame(false);
6778}
6779
6780/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6781 * there is nothing to transmit while DTX is enabled on downlink. */
6782testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6783 f_tch_sign_l2_fill_frame(true);
6784}
Harald Welte0472ab42018-03-12 15:02:26 +01006785
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006786testcase TC_chopped_ipa_ping() runs on test_CT {
6787 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6788}
6789
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006790testcase TC_chopped_ipa_payload() runs on test_CT {
6791 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6792}
6793
Harald Welte0472ab42018-03-12 15:02:26 +01006794/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6795/* protocol error as per 44.006 */
6796/* link layer failure (repetition of I-frame N200 times without ACK */
6797/* repetition of SABM or DISC N200 times without ACK */
6798/* receptiom of SABM in multi-frame established state */
6799
6800
Harald Welte68e495b2018-02-25 00:05:57 +01006801/* TODO Areas:
6802
6803* channel activation
6804** with BS_Power / MS_Power, bypassing power control loop
6805** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006806** with timing advance from initial activation on
6807* mode modify
6808** encryption
6809** multirate
6810* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006811** unsupported algorithm
6812* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006813* BS Power Control
6814* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006815* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006816* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006817** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006818* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006819** DATA_IND from BTS->PCU
6820** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006821
6822*/
Harald Welte70767382018-02-21 12:16:40 +01006823
6824control {
6825 execute( TC_chan_act_stress() );
6826 execute( TC_chan_act_react() );
6827 execute( TC_chan_deact_not_active() );
6828 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006829 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006830 execute( TC_sacch_filling() );
6831 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006832 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006833 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006834 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006835 execute( TC_sacch_chan_act_ho_async() );
6836 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006837 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006838 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006839 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006840 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006841 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006842 execute( TC_rach_load_idle_thresh0() );
6843 execute( TC_rach_load_idle_below_thresh() );
6844 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006845 execute( TC_meas_res_sign_tchf() );
6846 execute( TC_meas_res_sign_tchh() );
6847 execute( TC_meas_res_sign_sdcch4() );
6848 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006849 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006850 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006851 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006852 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006853 execute( TC_rsl_bs_pwr_static_ass() );
6854 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006855 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006856 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006857 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006858 execute( TC_rsl_ms_pwr_dyn_up() );
6859 execute( TC_rsl_ms_pwr_dyn_down() );
6860 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6861 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006862 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006863 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006864 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006865 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006866 execute( TC_paging_imsi_80percent() );
6867 execute( TC_paging_tmsi_80percent() );
6868 execute( TC_paging_imsi_200percent() );
6869 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006870 execute( TC_rsl_protocol_error() );
6871 execute( TC_rsl_mand_ie_error() );
6872 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006873 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006874 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006875 execute( TC_si_sched_2bis() );
6876 execute( TC_si_sched_2ter() );
6877 execute( TC_si_sched_2ter_2bis() );
6878 execute( TC_si_sched_2quater() );
6879 execute( TC_si_sched_13() );
6880 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006881 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006882 execute( TC_ipa_crcx_twice_not_active() );
6883 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006884 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006885 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006886
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006887 if (mp_pcu_socket != "") {
6888 execute( TC_pcu_act_req() );
6889 execute( TC_pcu_act_req_wrong_ts() );
6890 execute( TC_pcu_act_req_wrong_bts() );
6891 execute( TC_pcu_act_req_wrong_trx() );
6892 execute( TC_pcu_deact_req() );
6893 execute( TC_pcu_deact_req_wrong_ts() );
6894 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006895 if (mp_l1_supports_gprs) {
6896 execute( TC_pcu_data_req_pdtch() );
6897 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006898 execute( TC_pcu_data_req_wrong_bts() );
6899 execute( TC_pcu_data_req_wrong_trx() );
6900 execute( TC_pcu_data_req_wrong_ts() );
6901 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006902 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006903 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006904 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006905 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006906 execute( TC_pcu_data_req_imm_ass_pch() );
6907 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006908 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006909 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006910 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006911 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006912 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006913 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006914 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006915 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006916 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006917 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006918 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006919 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006920 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006921 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006922 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006923 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006924 execute( TC_dyn_osmo_pdch_act_deact() );
6925 execute( TC_dyn_osmo_pdch_double_act() );
6926 execute( TC_dyn_ipa_pdch_act_deact() );
6927 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6928
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006929 if (PCUIF_Types.mp_pcuif_version >= 10) {
6930 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006931 execute( TC_pcu_socket_nsvc_ipv4() );
6932 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006933 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006934 } else {
6935 log("PCU socket path not available, skipping PCU tests");
6936 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006937
Harald Welte3d04ae62018-04-04 20:29:05 +02006938 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006939 execute( TC_dyn_osmo_pdch_tchf_act() );
6940 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006941 execute( TC_dyn_ipa_pdch_tchf_act() );
6942 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006943
6944 execute( TC_rll_est_ind() );
6945 execute( TC_rll_est_req_DCCH_3() );
6946 execute( TC_rll_est_req_ACCH_3() );
6947 execute( TC_rll_rel_ind_DCCH_0() );
6948 execute( TC_rll_rel_ind_DCCH_3() );
6949 execute( TC_rll_rel_ind_ACCH_0() );
6950 execute( TC_rll_rel_ind_ACCH_3() );
6951 execute( TC_rll_rel_req() );
6952 execute( TC_rll_unit_data_req_DCCH() );
6953 execute( TC_rll_unit_data_req_ACCH() );
6954 execute( TC_rll_unit_data_ind_DCCH() );
6955 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006956
6957 execute( TC_chan_act_a51() );
6958 execute( TC_chan_act_a52() );
6959 execute( TC_chan_act_a53() );
6960 execute( TC_encr_cmd_a51() );
6961 execute( TC_encr_cmd_a52() );
6962 execute( TC_encr_cmd_a53() );
6963
Harald Welteee25aae2019-05-19 14:32:37 +02006964 execute( TC_err_rep_wrong_mdisc() );
6965 execute( TC_err_rep_wrong_msg_type() );
6966 execute( TC_err_rep_wrong_sequence() );
6967
Harald Weltee613f962018-04-18 22:38:16 +02006968 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006969
6970 execute( TC_tch_sign_l2_fill_frame() );
6971 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006972
6973 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006974 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006975}
6976
6977
6978}