blob: 462e2d547d0d9b3a9e82ad4e0b20db30e08956b1 [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;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700108 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700109 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100110 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200111 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200112 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200113 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
114 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700115 /* how many transceivers do we expect to connect */
116 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700117 /* frequency hopping status */
118 boolean mp_freq_hop_enabled := false;
119 /* frequency hopping parameters */
120 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
Harald Welte629cc6b2018-03-11 17:19:05 +0100123type record of RslChannelNr ChannelNrs;
124
Harald Welte70767382018-02-21 12:16:40 +0100125type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100127 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100129 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100130 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100131 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100132
133 /* L1CTL port (for classic tests) */
134 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100135
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700136 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100139
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100141 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200142 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100143
Harald Welte883340c2018-02-28 18:59:29 +0100144 /* PCU Interface of BTS */
145 port PCUIF_CODEC_PT PCU;
146 var integer g_pcu_conn_id;
147 /* Last PCU INFO IND we received */
148 var PCUIF_Message g_pcu_last_info;
149
Harald Welte48494ca2018-02-25 16:59:50 +0100150 /* SI configuration */
151 var SystemInformationConfig si_cfg := {
152 bcch_extended := false,
153 si1_present := false,
154 si2bis_present := false,
155 si2ter_present := false,
156 si2quater_present := false,
157 si7_present := false,
158 si8_present := false,
159 si9_present := false,
160 si13_present := false,
161 si13alt_present := false,
162 si15_present := false,
163 si16_present := false,
164 si17_present := false,
165 si2n_present := false,
166 si21_present := false,
167 si22_present := false
168 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100169
170 /* all logical channels available on the BTS */
171 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100172 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200176type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100177 port L1CTL_PT L1CTL;
178
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700179 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700180 port TRXC_CODEC_PT BTS_TRXC;
181 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100182
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200183 /* port to be initialized optionally to access BSC VTY */
184 port TELNETasp_PT BSCVTY;
185
Harald Welte70767382018-02-21 12:16:40 +0100186 timer g_Tguard;
187 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
188
189 var ConnHdlrPars g_pars;
190 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100191 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200192
193 /* PCU Interface of BTS */
194 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100195}
196
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700197private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200203 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700204 timer T;
205
Harald Welte70767382018-02-21 12:16:40 +0100206 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
207 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
208
209 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
210 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
211 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
212
213 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
214 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700215
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 T.start(mp_ipa_up_timeout);
219 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
222 /* Make sure that all transceivers use unique stream ID */
223 if (trx_mask[enum2int(ev.sid)] == '1'B) {
224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
225 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
226 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 trx_mask[enum2int(ev.sid)] := '1'B;
229 trx_count := trx_count + 1;
230
231 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200234 /* This message (RF RESource INDication) is sent by the IUT itself */
235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
236 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
239 }
240 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
242 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
243 }
244
245 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
246 rfind_count := rfind_count + 1;
247 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
248 if (rfind_count < mp_transceiver_num) { repeat; }
249 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700250 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
251 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
252 [] T.timeout {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 "Timeout waiting for RSL bring up");
255 }
256 }
Harald Welte70767382018-02-21 12:16:40 +0100257}
258
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700259friend type record FreqHopPars {
260 /* Whether frequency hopping is in use */
261 boolean enabled,
262 /* Mobile Allocation Index Offset / Hopping Sequence Number */
263 MaioHsn maio_hsn,
264 /* MA bitmap to be indicated in RR Immediate Assignment */
265 MobileAllocationLV ma_map,
266 /* The actual Mobile Allocation (ARFCN list) to be used */
267 L1ctlMA ma
268};
269
Harald Welte70767382018-02-21 12:16:40 +0100270type record ConnHdlrPars {
271 RslChannelNr chan_nr,
272 RSL_IE_ChannelMode chan_mode,
273 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100274 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200275 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200276 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700277 BtsBand bts0_band optional,
278
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700279 /* Frequency hopping parameters */
280 FreqHopPars fhp
281};
Harald Welte0472ab42018-03-12 15:02:26 +0100282
283/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700284private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100285 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100286}
287
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700288private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100289 max_retrans := RACH_MAX_RETRANS_7,
290 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100291 cell_barr_access := false,
292 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100293 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100294};
295
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700296private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100297 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200298 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100299 acs := '0'B,
300 neci := true,
301 rxlev_access_min := 0
302}
303
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100305 mcc_mnc := '262F42'H,
306 lac := 42
307}
308
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700309private template (value) GPRSIndicator ts_GPRSIndicator_def := {
310 ra_colour := 0,
311 si13_pos := '0'B
312}
313
314private template (value) SI3RestOctets ts_SI3RestOctets_def
315modifies ts_SI3RestOctets := {
316 gprs_ind := {
317 presence := CSN1_H,
318 ind := ts_GPRSIndicator_def
319 }
320}
321
322private template (value) SI4RestOctets ts_SI4RestOctets_def
323modifies ts_SI4RestOctets := {
324 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700325 presence := CSN1_H,
326 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700327 }
328}
329
Harald Welte7484fc42018-02-24 14:09:45 +0100330/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100332 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100333 payload := {
334 si3 := {
335 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100336 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100337 ctrl_chan_desc := {
338 msc_r99 := true,
339 att := true,
340 bs_ag_blks_res := 1,
341 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100342 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100343 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
344 spare := '00'B,
345 bs_pa_mfrms := 0, /* 2 multiframes */
346 t3212 := 1 /* 6 minutes */
347 },
Harald Welte82ccef72018-02-25 16:17:33 +0100348 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100349 dn_ind := false,
350 pwrc := false,
351 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100352 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100353 },
Harald Weltef10153f2018-02-25 16:34:05 +0100354 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100355 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200356 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100357 }
358 }
359}
Harald Welte70767382018-02-21 12:16:40 +0100360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100362 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100363 payload := {
364 si2 := {
365 bcch_freq_list := '00000000000000000000000000000000'O,
366 ncc_permitted := '11111111'B,
367 rach_control := ts_RachCtrl_default
368 }
369 }
370}
371
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700372private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100373 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100374 payload := {
375 si4 := {
376 lai := ts_LAI_default,
377 cell_sel_par := ts_CellSelPar_default,
378 rach_control := ts_RachCtrl_default,
379 cbch_chan_desc := omit,
380 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200381 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100382 }
383 }
384}
385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100387runs on test_CT {
388 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700389 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100390}
391
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700392private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100393runs on test_CT {
394 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
395 log("Setting ", rsl_si_type, ": ", si_dec);
396 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
397}
398
Harald Welte505cf9b2018-09-15 17:47:23 +0300399friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100400 map(self:BTSVTY, system:BTSVTY);
401 f_vty_set_prompts(BTSVTY);
402 f_vty_transceive(BTSVTY, "enable");
403}
404
Harald Welte505cf9b2018-09-15 17:47:23 +0300405friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200406 map(self:BSCVTY, system:BSCVTY);
407 f_vty_set_prompts(BSCVTY, "OsmoBSC");
408 f_vty_transceive(BSCVTY, "enable");
409}
410
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200411friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
412 map(self:BSCVTY, system:BSCVTY);
413 f_vty_set_prompts(BSCVTY, "OsmoBSC");
414 f_vty_transceive(BSCVTY, "enable");
415}
416
Harald Welte883340c2018-02-28 18:59:29 +0100417/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200418private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
419 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100420 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200421 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
422 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100423 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200424 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100426 }
427}
428
Harald Weltef26de0b2018-04-04 20:28:05 +0200429private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
430 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100431 timer T := 2.0;
432 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200434 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100435 return;
436 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200437 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100438
439 T.start;
440 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200441 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100442 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100444 }
445 }
446}
447
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700448private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
449 out integer trxc_conn_id) {
450 var Result res;
451
452 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
453 "", -1, -1, { udp := {} }, {});
454 if (not ispresent(res.connId)) {
455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
456 "Could not connect to the control (TRXC) interface " &
457 "of FakeTRX, check your configuration");
458 }
459 trxc_conn_id := res.connId;
460}
461
Harald Welte70767382018-02-21 12:16:40 +0100462/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700463friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200464 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100465 g_AllChannels := {
466 /* TS 1..4: TCH/F */
467 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
468 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
469 /* TS 5: TCH/H */
470 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
471 /* TS 0: SDCCH/4 */
472 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
473 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
474 /* TS 6: SDCCH/8 */
475 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
476 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
477 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
478 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
479 };
480
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200481 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700482 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200483 g_AllChanTypes := {
484 /* TS 1..4: TCH/F */
485 valueof(ts_RslChanNr_Bm(1)),
486 /* TS 5: TCH/H */
487 valueof(ts_RslChanNr_Lm(5,1)),
488 /* TS 0: SDCCH/4 */
489 valueof(ts_RslChanNr_SDCCH4(0,2)),
490 /* TS 6: SDCCH/8 */
491 valueof(ts_RslChanNr_SDCCH8(6,4))
492 };
493 } else {
494 g_AllChanTypes := {
495 /* TS 1..4: TCH/F */
496 valueof(ts_RslChanNr_Bm(1)),
497 /* TS 0: SDCCH/4 */
498 valueof(ts_RslChanNr_SDCCH4(0,2)),
499 /* TS 6: SDCCH/8 */
500 valueof(ts_RslChanNr_SDCCH8(6,4))
501 };
502 }
Harald Welte70767382018-02-21 12:16:40 +0100503 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100504 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100505 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200506 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100507
508 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100509 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
510 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
512 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100513
Harald Weltef26de0b2018-04-04 20:28:05 +0200514 map(self:PCU, system:PCU);
515 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100516
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700517 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100518 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700519
520 /* Init TRXC interface to FakeTRX */
521 map(self:BTS_TRXC, system:BTS_TRXC);
522 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
523
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700524 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700525 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 +0700526 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700527 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
528 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100529 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200530
531 /* Wait some extra time to make sure the BTS emits a stable carrier.
532 * (this is only relevant when running the tests with a physical BTS.) */
533 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100534}
535
Harald Welte68e495b2018-02-25 00:05:57 +0100536/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700537friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100538 map(self:L1CTL, system:L1CTL);
539 f_connect_reset(L1CTL);
540}
541
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700542private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100543
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700544private type record length(8) of FreqHopGroups FreqHopConfig;
545
546private type record of FreqHopGroup FreqHopGroups;
547private type record FreqHopGroup {
548 uint6_t hsn,
549 FreqHopGroupItems trx_maio
550};
551
552private type record of FreqHopGroupItem FreqHopGroupItems;
553private type record FreqHopGroupItem {
554 uint8_t trx_nr,
555 uint6_t maio
556};
557
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700558friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
559 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700562 var integer i, j;
563
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700564 fhp.enabled := false;
565
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (i := 0; i < lengthof(groups); i := i + 1) {
567 var FreqHopGroup g := groups[i];
568 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
569 var FreqHopGroupItem gi := g.trx_maio[j];
570 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700571 fhp.maio_hsn.maio := gi.maio;
572 fhp.maio_hsn.hsn := g.hsn;
573 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700574 break;
575 }
576 }
577
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700578 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700579 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700580 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
581 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
582 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700583
584 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
586 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700587 var GsmArfcn arfcn := c_arfcn_list[gi.trx_nr];
588 fhp.ma := fhp.ma & { { false, arfcn } };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700589 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700590 }
591
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700592 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700593 break; /* We're done */
594 }
595 }
596}
597
Harald Welte70767382018-02-21 12:16:40 +0100598/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700599friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
600 boolean pcu_comp := false,
601 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100602runs on test_CT return ConnHdlr {
603 var charstring id := testcasename();
604 var ConnHdlr vc_conn;
605
606 vc_conn := ConnHdlr.create(id);
607 /* connect to RSL Emulation main component */
608 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
609 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700610
611 /* The ConnHdlr component may want to talk to some ports directly,
612 * so we disconnect it from the test_CT and connect it to the component.
613 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200614 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200615 unmap(self:PCU, system:PCU);
616 map(vc_conn:PCU, system:PCU);
617 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700618 if (trxc_comp) {
619 unmap(self:BTS_TRXC, system:BTS_TRXC);
620 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
621 }
Harald Welte70767382018-02-21 12:16:40 +0100622
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700623 /* Obtain frequency hopping parameters for a given timeslot */
624 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700625 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700626 }
627
Harald Welte70767382018-02-21 12:16:40 +0100628 vc_conn.start(f_handler_init(fn, id, pars));
629 return vc_conn;
630}
631
Harald Welte70767382018-02-21 12:16:40 +0100632private altstep as_Tguard() runs on ConnHdlr {
633 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100635 }
636}
637
Harald Welte990a3612019-05-27 14:02:13 +0200638friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
639 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100640}
641
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700642private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100643 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700644 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100645}
646
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700647private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100648 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700649 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100650}
651
652/* first function started in ConnHdlr component */
653private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
654runs on ConnHdlr {
655 g_pars := pars;
656 g_chan_nr := pars.chan_nr;
657
658 map(self:L1CTL, system:L1CTL);
659 f_connect_reset(L1CTL);
660
Harald Welted48c0c72019-06-05 10:01:15 +0200661 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700662 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100663 }
Harald Welte70767382018-02-21 12:16:40 +0100664
665 g_Tguard.start(pars.t_guard);
666 activate(as_Tguard());
667
668 f_rslem_register(0, pars.chan_nr);
669
670 /* call the user-supplied test case function */
671 fn.apply(id);
672}
673
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700674private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
675 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200676runs on ConnHdlr return RSL_Message {
677 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100678 timer T := 3.0;
679 RSL.send(tx);
680 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100681 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200682 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100683 T.stop;
684 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100685 }
Harald Welte1eba3742018-02-25 12:48:14 +0100686 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100688 }
Harald Welte21240e62018-03-11 21:43:35 +0100689 [not ignore_other] as_l1_sacch();
690 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700691 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700692 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100693 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100695 }
Harald Welte21240e62018-03-11 21:43:35 +0100696 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100697 }
Harald Welteb1726c92018-03-30 11:56:38 +0200698 return rx;
699}
700
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700701friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
702 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200703runs on ConnHdlr {
704 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100705}
706
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700707friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
708 boolean encr_enable := false,
709 RSL_IE_List more_ies := {},
710 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
711runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200712 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200713 if (encr_enable) {
714 /* append encryption related IEs, if requested */
715 var RSL_IE_EncryptionInfo encr_info;
716 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
717 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
718encr_info})) };
719 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200720 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200721 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100722}
723
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700724friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100725 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 +0100726 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100727}
728
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700729/* TODO: move this to module parameters */
730private const GsmArfcn c_arfcn_list[4] := {
731 mp_trx0_arfcn, mp_trx1_arfcn,
732 mp_trx2_arfcn, mp_trx3_arfcn
733};
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700734
Harald Welte2f2b2b72019-05-31 22:24:57 +0200735friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100736 template RSL_IE_ChannelMode chan_mode,
737 float t_guard := 20.0) := {
738 chan_nr := valueof(chan_nr),
739 chan_mode := valueof(chan_mode),
740 t_guard := t_guard,
741 l1_pars := {
742 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100743 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100744 meas_ul := {
745 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200746 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100747 rxqual := 0
748 },
749 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200750 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100751 rxqual := 0
752 }
753 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200754 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100755 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200756 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200757 ms_actual_ta := mp_ms_actual_ta_exp,
758 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100759 },
Harald Weltee613f962018-04-18 22:38:16 +0200760 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200761 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700762 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700763 fhp := {
764 enabled := false,
765 maio_hsn := ts_HsnMaio(0, 0),
766 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700767 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700768 }
Harald Welte70767382018-02-21 12:16:40 +0100769}
770
Harald Welte93640c62018-02-25 16:59:33 +0100771/***********************************************************************
772 * Channel Activation / Deactivation
773 ***********************************************************************/
774
Harald Welte70767382018-02-21 12:16:40 +0100775/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700776private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100777 for (var integer i := 0; i < 500; i := i+1) {
778 f_rsl_chan_act(g_pars.chan_mode);
779 f_rsl_chan_deact();
780 }
781 setverdict(pass);
782}
783testcase TC_chan_act_stress() 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 Welte10474062019-05-30 16:48:17 +0200786 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100787 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), 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/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700793private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100794 f_rsl_chan_act(g_pars.chan_mode);
795 /* attempt to activate the same lchan again -> expect reject */
796 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
797 alt {
798 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100800 }
801 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
802 setverdict(pass);
803 }
804 }
805 f_rsl_chan_deact();
806}
807testcase TC_chan_act_react() runs on test_CT {
808 var ConnHdlr vc_conn;
809 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100810 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100811 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
812 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100814}
815
816/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700817private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100818 timer T := 3.0;
819 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
820 T.start;
821 alt {
822 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
823 setverdict(pass);
824 }
825 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100827 }
828 }
829}
830testcase TC_chan_deact_not_active() runs on test_CT {
831 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100832 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100833 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
834 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100836}
837
838/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700839private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100840 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
841 alt {
842 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100844 }
845 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
846 setverdict(pass);
847 }
848 }
849}
850private type record WrongChanNrCase {
851 RslChannelNr chan_nr,
852 charstring description
853}
854private type record of WrongChanNrCase WrongChanNrCases;
855private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
856 chan_nr := chan_nr,
857 description := desc
858}
859
860testcase TC_chan_act_wrong_nr() runs on test_CT {
861 var ConnHdlr vc_conn;
862 var ConnHdlrPars pars;
863
Harald Welte294b0a22018-03-10 23:26:48 +0100864 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100865
866 var WrongChanNrCases wrong := {
867 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
868 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
869 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
870 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
871 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
872 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
873 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
874 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
875 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
876 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
877 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
878 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
879 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
880 };
881
882 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
883 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
884 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
885 vc_conn.done;
886 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100888}
889
Harald Weltee613f962018-04-18 22:38:16 +0200890/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200891friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200892 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200893 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200894
895 /* test on each of the channels we have */
896 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
897 pars.chan_nr := valueof(g_AllChanTypes[i]);
898
899 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
900 vc_conn := f_start_handler(fn, pars);
901 vc_conn.done;
902 }
903
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200905}
906
Harald Welte93640c62018-02-25 16:59:33 +0100907/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100908 * SACCH handling
909 ***********************************************************************/
910
911private function f_exp_sacch(boolean exp) runs on ConnHdlr {
912 timer T_sacch := 3.0;
913 T_sacch.start;
914 alt {
915 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100917 }
918 [not exp] T_sacch.timeout {
919 setverdict(pass);
920 }
921 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
922 setverdict(pass);
923 }
924 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100926 }
927 [] L1CTL.receive { repeat; }
928 [] RSL.receive { repeat; }
929 }
930}
931
932/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
933private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
934 f_l1_tune(L1CTL);
935 RSL.clear;
936
937 /* activate the logical channel */
938 f_est_dchan();
939 L1CTL.clear;
940
941 /* check that SACCH actually are received as expected */
942 f_exp_sacch(true);
943
944 /* deactivate SACCH on the logical channel */
945 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
946 f_sleep(1.0);
947 L1CTL.clear;
948
949 /* check that no SACCH are received anymore */
950 f_exp_sacch(false);
951
952 /* release the channel */
953 f_rsl_chan_deact();
954 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
955}
956testcase TC_deact_sacch() runs on test_CT {
957 var ConnHdlr vc_conn;
958 var ConnHdlrPars pars;
959 f_init();
960 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
961 //for (var integer i := 0; i < 1; i := i+1) {
962 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
963 log(testcasename(), ": Starting for ", g_AllChannels[i]);
964 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
965 vc_conn.done;
966 }
967 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200968 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100969}
970
Harald Welte55700662018-03-12 13:15:43 +0100971/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100972private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
973 var L1ctlDlMessage dl;
974 /* check that the specified SI5 value is actually sent */
975 timer T_sacch := 3.0;
976 L1CTL.clear;
977 T_sacch.start;
978 alt {
979 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
980 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
981 if (match(l3, l3_exp)) {
982 setverdict(pass);
983 } else {
984 repeat;
985 }
986 }
987 [] L1CTL.receive { repeat; }
988 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100990 }
991 }
992}
993
Harald Welte55700662018-03-12 13:15:43 +0100994/* verify that given SACCH payload is not present */
995private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
996 var L1ctlDlMessage dl;
997 /* check that the specified SI5 value is actually sent */
998 timer T_sacch := 3.0;
999 L1CTL.clear;
1000 T_sacch.start;
1001 alt {
1002 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1003 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1004 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001006 } else {
1007 repeat;
1008 }
1009 }
1010 [] L1CTL.receive { repeat; }
1011 [] T_sacch.timeout {
1012 setverdict(pass);
1013 }
1014 }
1015}
1016
Harald Welte629cc6b2018-03-11 17:19:05 +01001017/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001018private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1019 /* Set a known default SACCH filling for SI5 */
1020 var octetstring si5 := f_rnd_octstring(19);
1021 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1022
1023 f_l1_tune(L1CTL);
1024 RSL.clear;
1025
1026 /* activate the logical channel */
1027 f_est_dchan();
1028
1029 /* check that the specified SI5 value is actually sent */
1030 f_sacch_present(si5);
1031
1032 /* release the channel */
1033 RSL.clear;
1034 f_rsl_chan_deact();
1035 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1036}
1037testcase TC_sacch_filling() runs on test_CT {
1038 var ConnHdlr vc_conn;
1039 var ConnHdlrPars pars;
1040 f_init();
1041 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1042 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1043 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1044 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1045 vc_conn.done;
1046 }
1047 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001049}
1050
Harald Welte629cc6b2018-03-11 17:19:05 +01001051/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001052private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1053 /* Set a known default SACCH filling for SI5 */
1054 var octetstring si5 := f_rnd_octstring(19);
1055 var octetstring si5_diff := f_rnd_octstring(19);
1056 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1057
1058 f_l1_tune(L1CTL);
1059 RSL.clear;
1060
1061 log("Activating channel, expecting standard SI5");
1062 /* activate the logical channel */
1063 f_est_dchan();
1064 /* check that the specified SI5 value is actually sent */
1065 f_sacch_present(si5);
1066
1067 /* set channel-specific different SI5 */
1068 log("Setting channel specific SACCH INFO, expecting it");
1069 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1070 /* check that the specified lchan-specific value is now used */
1071 f_sacch_present(si5_diff);
1072
1073 /* deactivate the channel and re-activate it, this should result in default SI5 */
1074 log("De-activating and re-activating channel, expecting standard SI5");
1075 f_rsl_chan_deact();
1076 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1077 /* Verify that the TRX-wide default SACCH filling is present again */
1078 f_sacch_present(si5);
1079
1080 /* release the channel */
1081 RSL.clear;
1082 f_rsl_chan_deact();
1083 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1084}
1085testcase TC_sacch_info_mod() runs on test_CT {
1086 var ConnHdlr vc_conn;
1087 var ConnHdlrPars pars;
1088 f_init();
1089 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1090 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1091 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1092 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1093 vc_conn.done;
1094 }
1095 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001097}
1098
Harald Welte075d84c2018-03-12 13:07:24 +01001099/* Test SACCH scheduling of multiple different SI message types */
1100private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1101 var octetstring si5 := f_rnd_octstring(19);
1102 var octetstring si5bis := f_rnd_octstring(19);
1103 var octetstring si5ter := f_rnd_octstring(19);
1104 var octetstring si6 := f_rnd_octstring(19);
1105
1106 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1107 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1108 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1109 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1110
1111 f_l1_tune(L1CTL);
1112 RSL.clear;
1113
1114 /* activate the logical channel */
1115 f_est_dchan();
1116 L1CTL.clear;
1117
1118 /* check that SACCH actually are received as expected */
1119 f_sacch_present(si5);
1120 f_sacch_present(si5bis);
1121 f_sacch_present(si5ter);
1122 f_sacch_present(si6);
1123
1124 /* release the channel */
1125 f_rsl_chan_deact();
1126 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1127}
1128testcase TC_sacch_multi() runs on test_CT {
1129 var ConnHdlr vc_conn;
1130 var ConnHdlrPars pars;
1131 f_init();
1132 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1133 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1134 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1135 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1136 vc_conn.done;
1137 }
1138 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001140}
1141
Harald Welte55700662018-03-12 13:15:43 +01001142/* Test if SACH information is modified as expected */
1143private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1144 var octetstring si5 := f_rnd_octstring(19);
1145 var octetstring si6 := f_rnd_octstring(19);
1146
1147 /* First, configure both SI5 and SI6 to be transmitted */
1148 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1149 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1150
1151 f_l1_tune(L1CTL);
1152 RSL.clear;
1153
1154 /* activate the logical channel */
1155 f_est_dchan();
1156 L1CTL.clear;
1157
1158 /* check that SACCH actually are received as expected */
1159 f_sacch_present(si5);
1160 f_sacch_present(si6);
1161
1162 /* disable SI6 */
1163 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1164
1165 /* check that SI5 is still transmitted */
1166 f_sacch_present(si5);
1167 /* check if SI6 is now gone */
1168 f_sacch_missing(si6);
1169
1170 /* release the channel */
1171 f_rsl_chan_deact();
1172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1173}
1174testcase TC_sacch_multi_chg() runs on test_CT {
1175 var ConnHdlr vc_conn;
1176 var ConnHdlrPars pars;
1177 f_init();
1178 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1179 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1180 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1181 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1182 vc_conn.done;
1183 }
1184 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001186}
1187
Harald Weltec8d363c2019-05-19 20:36:48 +02001188/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1189private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1190 var octetstring si5 := f_rnd_octstring(19);
1191 var octetstring si6 := f_rnd_octstring(19);
1192 var octetstring si5_specific := f_rnd_octstring(19);
1193 var octetstring si6_specific := f_rnd_octstring(19);
1194
1195 /* First, configure both SI5 and SI6 to be transmitted */
1196 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1197 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1198
1199 f_l1_tune(L1CTL);
1200 RSL.clear;
1201
1202 /* activate channel with different SACCH filling */
1203 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1204 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1205 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1206 }));
1207 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1208 RSL_IE_Body:{sacch_info := sacch_info})) };
1209 f_est_dchan(more_ies := addl_ies);
1210
1211 /* check that SACCH actually are received as expected */
1212 f_sacch_present(si5_specific);
1213 f_sacch_present(si6_specific);
1214
1215 /* release the channel */
1216 f_rsl_chan_deact();
1217 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1218}
1219testcase TC_sacch_chan_act() runs on test_CT {
1220 var ConnHdlr vc_conn;
1221 var ConnHdlrPars pars;
1222 f_init();
1223
1224 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1225 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1226 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1227 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1228 vc_conn.done;
1229 }
1230 /* TODO: do the above in parallel, rather than sequentially? */
1231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1232}
1233
Harald Welte8b01c792019-05-19 22:51:25 +02001234/* verify that SACCH DL transmission is started only if MS power IE present
1235 * see section 4.1.3 of 3GPP TS 48.058 */
1236private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1237 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001238 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001239
1240 f_l1_tune(L1CTL);
1241 RSL.clear;
1242
1243 /* Step 1: Activate ASYNC HO channel without MS power IE */
1244
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001245 var integer ho_ref := oct2int(f_rnd_octstring(1));
1246 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1247 RSL_IE_Body:{ handover_ref := ho_ref }));
1248 var RSL_IE_List addl_ies := {
1249 ho_ref_ie
1250 };
1251
Harald Welte8b01c792019-05-19 22:51:25 +02001252 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001253 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001254 /* don't perform immediate assignment here, as we're testing non-IA case */
1255 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001256 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001257
1258 /* Verify that no DL SACCH is being received */
1259 f_sacch_missing(?);
1260
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001261 /* Send handover Access Burst and expect SACCH to start */
1262 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1263
1264 f_sacch_present(si5);
1265
Harald Welte8b01c792019-05-19 22:51:25 +02001266 f_rsl_chan_deact();
1267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1268
1269
1270 /* Step 2: Activate ASYNC HO channel with MS power IE */
1271
1272 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001273 addl_ies := {
1274 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001275 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1276 };
1277 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
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 DL SACCH is being received */
1283 f_sacch_present(si5);
1284
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001285 /* Send handover Access Burst and expect SACCH to remain present */
1286 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1287
1288 f_sacch_present(si5);
1289
Harald Welte8b01c792019-05-19 22:51:25 +02001290 f_rsl_chan_deact();
1291 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1292}
1293testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1294 var ConnHdlr vc_conn;
1295 var ConnHdlrPars pars;
1296 f_init();
1297
1298 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1299 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1300 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1301 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1302 vc_conn.done;
1303 }
1304 /* TODO: do the above in parallel, rather than sequentially? */
1305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1306}
1307
1308/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1309 * see section 4.1.4 of 3GPP TS 48.058 */
1310private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1311 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001312 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1313
Harald Welte8b01c792019-05-19 22:51:25 +02001314 var RSL_IE_List addl_ies;
1315
1316 f_l1_tune(L1CTL);
1317 RSL.clear;
1318
1319 /* Step 1: Activate SYNC HO channel without MS power IE */
1320
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001321 var integer ho_ref := oct2int(f_rnd_octstring(1));
1322 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1323 RSL_IE_Body:{ handover_ref := ho_ref }));
1324 addl_ies := {
1325 ho_ref_ie
1326 };
1327
Harald Welte8b01c792019-05-19 22:51:25 +02001328 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001329 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001330 /* don't perform immediate assignment here, as we're testing non-IA case */
1331 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001332 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001333
1334 /* Verify that no DL SACCH is being received */
1335 f_sacch_missing(?);
1336
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001337 /* Send handover Access Burst and expect SACCH to start */
1338 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1339
1340 f_sacch_present(si5);
1341
Harald Welte8b01c792019-05-19 22:51:25 +02001342 f_rsl_chan_deact();
1343 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1344
1345
1346 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1347
1348 /* Activate channel on BTS side */
1349 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001350 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001351 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1352 };
1353 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1354 /* don't perform immediate assignment here, as we're testing non-IA case */
1355 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001356 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001357
1358 /* Verify that no DL SACCH is being received */
1359 f_sacch_missing(?);
1360
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001361 /* Send handover Access Burst and expect SACCH to start */
1362 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1363
1364 f_sacch_present(si5);
1365
Harald Welte8b01c792019-05-19 22:51:25 +02001366 f_rsl_chan_deact();
1367 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1368
1369
1370 /* Step 2b: Activate SYNC HO channel with TA IE */
1371
1372 /* Activate channel on BTS side */
1373 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001374 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001375 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1376 };
1377 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1378 /* don't perform immediate assignment here, as we're testing non-IA case */
1379 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001380 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001381
1382 /* Verify that no DL SACCH is being received */
1383 f_sacch_missing(?);
1384
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001385 /* Send handover Access Burst and expect SACCH to start */
1386 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1387
1388 f_sacch_present(si5);
1389
Harald Welte8b01c792019-05-19 22:51:25 +02001390 f_rsl_chan_deact();
1391 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1392
1393
1394 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1395
1396 /* Activate channel on BTS side */
1397 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001398 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001399 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1400 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1401 };
1402 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1403 /* don't perform immediate assignment here, as we're testing non-IA case */
1404 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001405 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001406
1407 /* Verify that DL SACCH is being received */
1408 f_sacch_present(si5);
1409
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001410 /* Send handover Access Burst and expect SACCH to remain present */
1411 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1412
1413 f_sacch_present(si5);
1414
Harald Welte8b01c792019-05-19 22:51:25 +02001415 f_rsl_chan_deact();
1416 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1417}
1418testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1419 var ConnHdlr vc_conn;
1420 var ConnHdlrPars pars;
1421 f_init();
1422
1423 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1424 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1425 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1426 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1427 vc_conn.done;
1428 }
1429 /* TODO: do the above in parallel, rather than sequentially? */
1430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1431}
Harald Welte629cc6b2018-03-11 17:19:05 +01001432
1433
1434/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001435 * RACH Handling
1436 ***********************************************************************/
1437
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001439private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001440 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001442 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001443
Harald Welte8c24c2b2018-02-26 08:31:31 +01001444 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001445 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001446 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001447 var OCT1 ra := f_rnd_ra_emerg();
1448 if (emerg == true) {
1449 ra := f_rnd_ra_emerg();
1450 } else {
1451 ra := f_rnd_ra_cs();
1452 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001453 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1454 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456 }
1457 fn_last := fn;
1458
1459 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001460 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001461 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001462 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001463 T.stop;
1464 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001465 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001467 }
1468 [] RSL_CCHAN.receive { repeat; }
1469 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001470 test_failed := true;
1471 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001472 }
1473 }
1474 }
Maxba06feb2019-03-05 10:52:46 +01001475 if (test_failed) {
1476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001477 }
Maxba06feb2019-03-05 10:52:46 +01001478 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001480}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001481
Philipp Maier16ade782020-07-08 21:36:00 +02001482/* Normal variant */
1483testcase TC_rach_content() runs on test_CT {
1484 f_TC_rach_content(emerg := false);
1485}
1486
1487/* Emergency call variant */
1488testcase TC_rach_content_emerg() runs on test_CT {
1489 f_TC_rach_content(emerg := true);
1490}
1491
Harald Welte8c24c2b2018-02-26 08:31:31 +01001492/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1493testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001494 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001495 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001496 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001497 f_l1_tune(L1CTL);
1498
1499 var GsmFrameNumber fn_last := 0;
1500 for (var integer i := 0; i < 1000; i := i+1) {
1501 var OCT1 ra := f_rnd_ra_cs();
1502 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1503 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001505 }
1506 fn_last := fn;
1507 }
1508 var integer rsl_chrqd := 0;
1509 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001510 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001511 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001512 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001513 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001514 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001515 repeat;
1516 }
1517 [] RSL_CCHAN.receive { repeat; }
1518 [] T.timeout { }
1519 }
1520 if (rsl_chrqd == 1000) {
1521 setverdict(pass);
1522 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001524 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001526}
1527
Harald Welte3453ab42019-05-24 21:19:58 +02001528private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1529 var charstring bts_str := "bts " & int2str(bts_nr);
1530 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1531}
1532
1533/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1534private template integer tr_rach_slots_per_interval := (90 .. 130);
1535
1536/* Expect 0 RACH load on an idle BTS that has just started up */
1537testcase TC_rach_load_idle_thresh0() runs on test_CT {
1538 var ASP_RSL_Unitdata rx_ud;
1539
1540 f_init_vty_bsc();
1541 /* send load indications even at 0% load */
1542 f_vty_load_ind_thresh(0);
1543 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1544 f_sleep(2.0);
1545
1546 f_init();
1547
Harald Weltee37f9a52020-10-11 20:45:23 +02001548 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1549 alt {
1550 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1551 [] RSL_CCHAN.receive { repeat }
1552 }
1553
Harald Welte3453ab42019-05-24 21:19:58 +02001554 timer T := 5.0;
1555 T.start;
1556 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001557 [] 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 +02001558 setverdict(pass);
1559 repeat;
1560 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001561 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001562 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1563 repeat;
1564 }
1565 [] RSL_CCHAN.receive {
1566 repeat;
1567 }
1568 [] T.timeout { }
1569 }
1570
1571 f_vty_load_ind_thresh(10);
1572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1573}
1574
1575/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1576testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1577 var ASP_RSL_Unitdata rx_ud;
1578
1579 f_init_vty_bsc();
1580 f_init();
1581
1582 timer T := 5.0;
1583 T.start;
1584 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001585 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001586 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1587 repeat;
1588 }
1589 [] RSL_CCHAN.receive {
1590 repeat;
1591 }
1592 [] T.timeout {
1593 setverdict(pass);
1594 }
1595 }
1596
1597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1598}
1599
1600/* Expect 0 RACH load on an idle BTS that has just started up */
1601testcase TC_rach_load_count() runs on test_CT {
1602 var ASP_RSL_Unitdata rx_ud;
1603 var integer load_access_count := 0;
1604
1605 f_init_vty_bsc();
1606 /* send load indications even at 0% load */
1607 f_vty_load_ind_thresh(0);
1608 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1609 f_sleep(2.0);
1610 f_init();
1611
1612 f_init_l1ctl();
1613 f_sleep(1.0);
1614 f_l1_tune(L1CTL);
1615
Harald Welte52ae1682020-10-11 20:45:55 +02001616 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1617 alt {
1618 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1619 [] RSL_CCHAN.receive { repeat }
1620 }
1621
Harald Welte3453ab42019-05-24 21:19:58 +02001622 var GsmFrameNumber fn_last := 0;
1623 for (var integer i := 0; i < 1000; i := i+1) {
1624 var OCT1 ra := f_rnd_ra_cs();
1625 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1626 if (fn == fn_last) {
1627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1628 }
1629 fn_last := fn;
1630 }
1631
1632 timer T := 5.0;
1633 T.start;
1634 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001635 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001636 -> value rx_ud {
1637 var RSL_IE_Body ie;
1638 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1639 load_access_count := load_access_count + ie.rach_load.access_count;
1640 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1641 setverdict(fail, "Access count cannot be < Busy count");
1642 }
1643 repeat;
1644 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001645 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001646 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1647 repeat;
1648 }
1649 [] RSL_CCHAN.receive {
1650 repeat;
1651 }
1652 [] T.timeout { }
1653 }
1654 if (load_access_count == 1000) {
1655 setverdict(pass);
1656 } else {
1657 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1658 }
1659
1660 f_vty_load_ind_thresh(10);
1661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1662}
1663
Harald Welte54a2a2d2018-02-26 09:14:05 +01001664private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001665 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001666 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001667 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001668 f_sleep(0.5);
1669
1670 /* Transmit RACH request + wait for confirmation */
1671 var OCT1 ra := f_rnd_ra_cs();
1672 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1673
1674 /* Check for expected result */
1675 timer T := 1.5;
1676 T.start;
1677 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001678 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001679 setverdict(pass);
1680 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001681 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001683 }
1684 [] RSL_CCHAN.receive { repeat; }
1685 [not expect_pass] T.timeout {
1686 setverdict(pass);
1687 }
1688 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001690 }
1691 }
1692}
1693
1694/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1695testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001696 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001697 f_init_l1ctl();
1698 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001699 f_sleep(1.0);
1700
1701 /* default max-ta is 63 (full range of GSM timing advance */
1702
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001703 /* We allow early arrival up to 2 symbols */
1704 f_rach_toffs(-1*256, true);
1705 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001706 f_rach_toffs(-10*256, false);
1707
1708 /* 0 / 32 / 63 bits is legal / permitted */
1709 f_rach_toffs(0, true);
1710 f_rach_toffs(32*256, true);
1711 f_rach_toffs(63*256, true);
1712
1713 /* more than 63 bits is not legal / permitted */
1714 f_rach_toffs(64*256, false);
1715 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001717}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001718
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001719private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001720 var GsmFrameNumber fn;
1721 var RSL_Message rm;
1722
1723 f_l1_tune(L1CTL);
1724 RSL.clear;
1725
1726 /* Generate a random Handover Reference */
1727 var integer ho_ref := oct2int(f_rnd_octstring(1));
1728
1729 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1730 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1731 RSL_IE_Body:{ handover_ref := ho_ref }));
1732
1733 /* Activate a channel on the BTS side (no encryption) */
1734 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1735 act_type := t_RSL_IE_ActType_HO_SYNC);
1736
1737 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1738 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001739 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001740
1741 /* Send handover Access Burst */
1742 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1743
1744 /* TODO: test mismatching Handover Reference, and missing IE */
1745
1746 /* Wait for handover detection */
1747 timer T := 3.0;
1748 T.start;
1749 alt {
1750 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1751 log("Handover RACH has been detected: ", rm);
1752 setverdict(pass);
1753 }
1754 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1756 log2str("RSL_CHAN_RQD was not expected: ", rm));
1757 }
1758 [] RSL.receive { repeat; }
1759 [] T.timeout {
1760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1761 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1762 }
1763 }
1764
1765 /* Release the channel */
1766 f_rsl_chan_deact();
1767 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1768}
1769
1770/* Test handover RACH detection */
1771testcase TC_ho_rach() runs on test_CT {
1772 var ConnHdlrPars pars;
1773 var ConnHdlr vc_conn;
1774
1775 f_init();
1776
1777 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1778 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1779 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1780 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1781 vc_conn.done;
1782 }
1783
1784 /* TODO: do the above in parallel, rather than sequentially? */
1785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1786}
1787
Harald Welte93640c62018-02-25 16:59:33 +01001788/***********************************************************************
1789 * Measurement Processing / Reporting
1790 ***********************************************************************/
1791
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001792private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001793 spare := '0'B,
1794 lpd := 0,
1795 sapi := sapi,
1796 c_r := c_r,
1797 ea := true
1798}
1799
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001800private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001801 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001802 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001803 len := 0, /* overwritten */
1804 m := false,
1805 el := 1,
1806 payload := pl
1807}
1808
1809/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001810private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001811 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001812 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001813 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001814 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 +01001815 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001816 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001817
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001818 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1819 g_pars.l1_pars.ms_power_level, false,
1820 g_pars.l1_pars.ms_actual_ta);
1821
1822 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1823 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1824
1825 log("Sending Measurement Report: ", l1h, l2);
1826 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001827 repeat;
1828 }
1829}
1830
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001831/* handle incoming downlink SACCH, decode the L1 header into the given record */
1832private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1833 boolean do_apply := true)
1834runs on ConnHdlr
1835{
1836 var L1ctlDlMessage l1_dl;
1837
1838 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1839 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1840 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1841 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1842
1843 if (do_apply) {
1844 /* Update TA and MS power to follow what BTS requests */
1845 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1846 }
1847 }
1848}
1849
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001850private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001851 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001852 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001853 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1854 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001855 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1856 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001857 repeat;
1858 }
1859}
1860
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001861private altstep as_l1_tch_loop() runs on ConnHdlr {
1862 var L1ctlDlMessage l1_dl;
1863 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1864 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001865
1866 /* occasionaly inject FACCH frames into the uplink */
1867 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1868 var octetstring pl := '010301'O;
1869 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1870 f_pad_oct(pl, 23, '2B'O)));
1871 } else {
1872 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1873 l1_dl.payload.traffic_ind.data));
1874 }
1875
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001876 repeat;
1877 }
1878}
1879
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001880private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001881 uint6_t rxlev,
1882 uint3_t rxqual
1883}
1884
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001885private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001886 MeasElem full,
1887 MeasElem sub
1888}
1889
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001890private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001891 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001892 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001893 MeasElemFS meas_ul,
1894 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001895 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001896 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001897 uint8_t ms_actual_ta,
1898 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001899}
1900
1901/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1902private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1903 return 63 + (toffs256s/256);
1904}
1905
Harald Welted5684392018-03-10 18:22:04 +01001906private function f_max(integer a, integer b) return integer {
1907 if (a > b) {
1908 return a;
1909 } else {
1910 return b;
1911 }
1912}
1913
1914private function f_min(integer a, integer b) return integer {
1915 if (a < b) {
1916 return a;
1917 } else {
1918 return b;
1919 }
1920}
1921
1922/* compute negative tolerance val-tolerance, ensure >= min */
1923private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1924 val := val - tolerance;
1925 return f_max(val, min);
1926}
1927
1928/* compute positive tolerance val+tolerance, ensure <= max */
1929private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1930 val := val + tolerance;
1931 return f_min(val, max);
1932}
1933
1934/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1935private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1936return template integer {
1937 var template integer ret;
1938 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1939 return ret;
1940}
1941
1942
Harald Welte70767382018-02-21 12:16:40 +01001943/* build a template for matching measurement results against */
1944private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1945 var ConnL1Pars l1p := g_pars.l1_pars;
1946 var template RSL_IE_UplinkMeas ul_meas := {
1947 len := 3,
1948 rfu := '0'B,
1949 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001950 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001951 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001952 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001953 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001954 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1955 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001956 supp_meas_info := omit
1957 };
Harald Welte685d5982018-02-27 20:42:05 +01001958 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001959 ul_meas.len := (3+8);
1960 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001961 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001962 toa256_min := ?,
1963 toa256_max := ?,
1964 toa256_std_dev := ?
1965 }
Harald Welte685d5982018-02-27 20:42:05 +01001966 }
Harald Welte70767382018-02-21 12:16:40 +01001967 var template RSL_IE_BS_Power bs_power := {
1968 reserved := 0,
1969 epc := false,
1970 fpc := false,
1971 power_level := l1p.bs_power_level
1972 };
1973 var template RSL_IE_L1Info l1_info := {
1974 ms_power_lvl := l1p.ms_power_level,
1975 fpc := false,
1976 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001977 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001978 };
1979 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001980 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001981 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1982 ?, t_toffs);
1983}
1984
Philipp Maierdd841d32019-12-17 14:44:54 +01001985/* build a template for matching measurement results that do not contain any
1986 * MS related measurement (l1_info, l3_info and ms timing offset). */
1987private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1988 var ConnL1Pars l1p := g_pars.l1_pars;
1989 var template RSL_IE_UplinkMeas ul_meas := {
1990 len := 3,
1991 rfu := '0'B,
1992 dtx_d := l1p.dtx_enabled,
1993 rxlev_f_u := ?,
1994 reserved1 := '00'B,
1995 rxlev_s_u := ?,
1996 reserved2 := '00'B,
1997 rxq_f_u := ?,
1998 rxq_s_u := ?,
1999 supp_meas_info := omit
2000 };
2001 if (l1p.toa256_enabled) {
2002 ul_meas.len := (3+8);
2003 ul_meas.supp_meas_info := {
2004 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2005 toa256_min := ?,
2006 toa256_max := ?,
2007 toa256_std_dev := ?
2008 }
2009 }
2010 var template RSL_IE_BS_Power bs_power := {
2011 reserved := 0,
2012 epc := false,
2013 fpc := false,
2014 power_level := l1p.bs_power_level
2015 };
2016
2017 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2018}
2019
Harald Welte70767382018-02-21 12:16:40 +01002020/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002021private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002022 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002023 var boolean chan_est := false;
2024
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002025 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002026
2027 /* Receive osmocom specific measurement reports. This is the normal
2028 * case. Here we verify that the measurement reports we sent are
2029 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002030 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2031 /* increment counter of next to-be-expected meas rep */
2032 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2033 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002034 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002035
2036 /* The following two cases may only happen in the beginning
2037 * of the channel establishment phase. Once we have received
2038 * the "our" measurement report the first time, the channel
2039 * is established and empty or hardcoded TRXCON reports must
2040 * not occur anymore. */
2041 chan_est := true;
2042
2043 repeat;
2044 }
2045
2046 /* When the BTS has established the channel, the MS might need slightly
2047 * more time to establish the channel and actually start sending. The
2048 * result is then a measurement report that just lacks the measurement
2049 * information of the MS. This is normal and we tolerate this behavior. */
2050 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2051 /* increment counter of next to-be-expected meas rep */
2052 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2053 /* Re-start the timer expecting the next MEAS RES */
2054 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002055 repeat;
2056 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002057
2058 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2059 * measurements if the TTCN3 side does not supply measurement input in
2060 * time. In those cases TRXCON will either use a cached measurement
2061 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2062 * report the templates above will not match. We tolerate this
2063 * behavior, but only once. */
2064 [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 +01002065 /* increment counter of next to-be-expected meas rep */
2066 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2067 if (g_first_meas_res) {
2068 g_first_meas_res := false;
2069 repeat;
2070 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002072 }
Harald Welte70767382018-02-21 12:16:40 +01002073 }
2074 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002075 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002076 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002077 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002079 }
2080}
2081
Harald Weltee613f962018-04-18 22:38:16 +02002082private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2083 select (rsl_alg_id) {
2084 case (RSL_ALG_ID_A5_0) { return 0; }
2085 case (RSL_ALG_ID_A5_1) { return 1; }
2086 case (RSL_ALG_ID_A5_2) { return 2; }
2087 case (RSL_ALG_ID_A5_3) { return 3; }
2088 case (RSL_ALG_ID_A5_4) { return 4; }
2089 case (RSL_ALG_ID_A5_5) { return 5; }
2090 case (RSL_ALG_ID_A5_6) { return 6; }
2091 case (RSL_ALG_ID_A5_7) { return 7; }
2092 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2094 /* Make compiler happy by calling mtc.stop here. It is already
2095 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002096 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002097 }
2098 }
2099}
2100
2101private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2102 select (rsl_alg_id) {
2103 case (RSL_ALG_ID_A5_1) { return '000'B; }
2104 case (RSL_ALG_ID_A5_2) { return '001'B; }
2105 case (RSL_ALG_ID_A5_3) { return '010'B; }
2106 case (RSL_ALG_ID_A5_4) { return '011'B; }
2107 case (RSL_ALG_ID_A5_5) { return '100'B; }
2108 case (RSL_ALG_ID_A5_6) { return '101'B; }
2109 case (RSL_ALG_ID_A5_7) { return '110'B; }
2110 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2112 /* Make compiler happy by calling mtc.stop here. It is already
2113 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002114 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002115 }
2116 }
2117}
2118
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002119/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2120private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2121 var GsmFrameNumber fn;
2122 timer T := 8.0;
2123
2124 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2125 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2126
2127 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2128 /* Send the actual RACH */
2129 fn := f_L1CTL_RACH(L1CTL, ra);
2130
2131 T.start;
2132 alt {
2133 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2134 [] T.timeout {
2135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2136 }
2137 }
2138 T.stop
2139 return fn;
2140}
Harald Weltee613f962018-04-18 22:38:16 +02002141
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002142/* Tune to a dedicated channel: L1CTL only */
2143private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002144 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002145 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2146 7 /* TODO: mp_tsc */,
2147 mp_trx0_arfcn));
2148 } else {
2149 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2150 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002151 pars.fhp.maio_hsn.hsn,
2152 pars.fhp.maio_hsn.maio,
2153 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002154 }
2155}
2156
Harald Welte70767382018-02-21 12:16:40 +01002157/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002158private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002159 var GsmFrameNumber fn;
2160 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002161 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002162 var integer ra := 23;
2163
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002164 /* Send RACH request and wait for ChanReq */
2165 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002166
2167 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002168 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002169
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002170 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002171 if (g_pars.fhp.enabled) {
2172 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002173 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002174 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002175 }
2176
Harald Welte70767382018-02-21 12:16:40 +01002177 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002178 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 +01002179 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2180
2181 /* receive IMM.ASS on MS side */
2182 var ImmediateAssignment ia_um;
2183 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002184
2185 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2186 if (ch_desc.h != ia_um.chan_desc.h) {
2187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2188 }
2189
Harald Welte70767382018-02-21 12:16:40 +01002190 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002191 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002192 /* enable encryption, if requested */
2193 if (encr_enable) {
2194 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2195 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2196 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002197
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002198 /* Send TCH Mode Request to the L1 if needed */
2199 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2200 var L1ctlTchMode tch_mode;
2201
2202 select (g_pars.chan_mode.coding_alg_rate) {
2203 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2204 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2205 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2206 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2207 case else {
2208 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2209 " is not supported by the L1, falling back to signalling");
2210 tch_mode := L1CTL_CHAN_MODE_SIGN;
2211 }
2212 }
2213
2214 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2215 }
2216
Harald Weltefa45e9e2018-03-10 18:59:03 +01002217 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002218}
2219
2220/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002221private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002222 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002223 RSL.clear;
2224
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002225 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002226 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002227 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002228 }
Harald Welte70767382018-02-21 12:16:40 +01002229
2230 f_est_dchan();
2231
2232 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2233 * RSL measurement reports on Abis side */
2234 timer T := 8.0;
2235 T.start;
2236 alt {
2237 [] as_l1_sacch();
2238 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002239 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002240 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002241 [] L1CTL.receive { repeat; }
2242 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002243 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002244 * of any earlier errors, so if we reach this timeout, we're good */
2245 setverdict(pass);
2246 }
2247 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002249 }
2250 }
2251 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002252 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002253}
Harald Welte0472ab42018-03-12 15:02:26 +01002254
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002255/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2256private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002257 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002258 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2259 timer Tup := 10.0;
2260 Tup.start;
2261 alt {
2262 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2263 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2264 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002265
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002266 if (rx_lvl != max_rx_lvl) {
2267 repeat;
2268 }
2269 Tup.stop;
2270 }
2271 [] L1CTL.receive { repeat; }
2272 [] Tup.timeout {
2273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2274 log2str("Didn't reach full power ", max_rx_lvl));
2275 }
2276 }
2277 return max_rx_lvl;
2278}
2279
2280/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2281private function f_verify_ramp_up() runs on ConnHdlr {
2282 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002283 var integer initial_rx_lvl := -1;
2284 var integer last_rx_lvl := -1;
2285 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2286
2287 timer T := 2.0;
2288 alt {
2289 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2290 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2291 log("Received rx_level=", rx_lvl);
2292 if (initial_rx_lvl == -1) {
2293 initial_rx_lvl := rx_lvl;
2294 last_rx_lvl := rx_lvl;
2295
2296 /* Expect a somehow low value during first received messages */
2297 if (initial_rx_lvl >= max_rx_lvl / 2) {
2298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2299 log2str("Detected high initial tx power during ramp up: ",
2300 initial_rx_lvl , ", full power is", max_rx_lvl));
2301 }
2302 }
2303
2304 /* received Rx level bigger than maximum allowed power by CN */
2305 if (rx_lvl > max_rx_lvl) {
2306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2307 log2str("Detected Tx power higher than full power: ",
2308 rx_lvl , " > ", max_rx_lvl));
2309 }
2310
2311 /* Make sure it never decreases, since we are rumping up */
2312 if (last_rx_lvl > rx_lvl) {
2313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2314 log2str("Detected Tx power decrease during ramp up: ",
2315 last_rx_lvl , " -> ", rx_lvl));
2316 }
2317
2318 if (rx_lvl == max_rx_lvl and not T.running) {
2319 /* We reached the maximum power, start timer and receive
2320 /* a few more to make sure we don't surpass it */
2321 log("Reached full power, wating a bit more until success");
2322 T.start;
2323 }
2324
2325 last_rx_lvl := rx_lvl;
2326 repeat;
2327 }
2328 [] L1CTL.receive { repeat; }
2329 [] T.timeout { }
2330 }
2331
2332 /* We didn't increase tx power during ramp up */
2333 if (initial_rx_lvl < last_rx_lvl) {
2334 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2335 } else {
2336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2337 log2str("No Tx power increase during whole ramp up: ",
2338 initial_rx_lvl , " -> ", last_rx_lvl));
2339 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002340}
2341
2342/* verify BTS ramps power down to rx_level 0 */
2343private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2344 var L1ctlDlMessage l1_dl;
2345 var integer last_rx_lvl := max_rx_lvl;
2346
2347 timer Tdown := 5.0;
2348 Tdown.start;
2349 alt {
2350 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2351 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2352 log("Received rx_level=", rx_lvl);
2353
2354 /* received Rx level bigger than maximum allowed power by CN */
2355 if (rx_lvl > max_rx_lvl) {
2356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2357 log2str("Detected Tx power higher than full power: ",
2358 rx_lvl , " > ", max_rx_lvl));
2359 }
2360
2361 /* Make sure it never increases, since we are rumping down */
2362 if (last_rx_lvl < rx_lvl) {
2363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2364 log2str("Detected Tx power increase during ramp up: ",
2365 last_rx_lvl , " -> ", rx_lvl));
2366 }
2367
2368 last_rx_lvl := rx_lvl;
2369 if (last_rx_lvl != 0) {
2370 repeat;
2371 }
2372 /* we reached power level 0, we are done */
2373 Tdown.stop;
2374 }
2375 [] L1CTL.receive { repeat; }
2376 [] Tdown.timeout { }
2377 }
2378
2379 /* We didn't increase tx power during ramp down */
2380 if (max_rx_lvl > last_rx_lvl) {
2381 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2382 } else {
2383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2384 log2str("No Tx power decrease during whole ramp down: ",
2385 max_rx_lvl , " -> ", last_rx_lvl));
2386 }
2387}
2388
2389/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002390private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002391 f_l1_tune(L1CTL);
2392 RSL.clear;
2393
2394 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002395
2396 setverdict(pass);
2397}
2398testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2399 var ConnHdlr vc_conn;
2400 var ConnHdlrPars pars;
2401 f_init();
2402 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2403 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2404 pcu_comp := false, trxc_comp := true);
2405 vc_conn.done;
2406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2407}
2408
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002409/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002410private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002411 f_connhdlr_init_vty_bsc();
2412
2413 f_l1_tune(L1CTL);
2414 RSL.clear;
2415
2416 /* Wait until BTS is started and at full power */
2417 var integer max_rx_lvl := f_wait_ramp_up();
2418 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2419
2420 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2421 f_verify_ramp_down(max_rx_lvl);
2422
2423 setverdict(pass);
2424}
2425testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2426 var ConnHdlr vc_conn;
2427 var ConnHdlrPars pars;
2428 f_init();
2429 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2430 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2431 pcu_comp := false, trxc_comp := true);
2432 vc_conn.done;
2433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2434}
2435
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002436/* Verify Tx power:
2437 * + ramping down during ADM state UNLOCKED->LOCKED
2438 * + ramping up during ADM state LOCKED->UNLOCKED
2439 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002440private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002441 var L1ctlDlMessage l1_dl;
2442 var integer last_rx_lvl;
2443
2444 f_connhdlr_init_vty_bsc();
2445
2446 f_l1_tune(L1CTL);
2447 RSL.clear;
2448
2449 /* Wait until BTS is started and at full power */
2450 var integer max_rx_lvl := f_wait_ramp_up();
2451 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2452
2453 log("ADM STATE UNLOCKED->LOCKED");
2454 f_vty_enter_cfg_trx(BSCVTY);
2455 f_vty_transceive(BSCVTY, "rf_locked 1");
2456 last_rx_lvl := max_rx_lvl;
2457 f_verify_ramp_down(max_rx_lvl);
2458
2459 /* Let some time after we received 0dBm, then check we don't receive BCCH
2460 * anymore because scheduler has stopped after ramping down */
2461 f_sleep(2.0);
2462 L1CTL.clear;
2463 timer Tlocked := 2.0;
2464 Tlocked.start;
2465 alt {
2466 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2468 log2str("Received data_ind during rf_locked: ", l1_dl));
2469 }
2470 [] L1CTL.receive { repeat; }
2471 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2472 }
2473
2474 log("ADM STATE LOCKED->UNLOCKED");
2475 f_vty_transceive(BSCVTY, "rf_locked 0");
2476 f_verify_ramp_up();
2477 setverdict(pass);
2478}
2479testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2480 var ConnHdlr vc_conn;
2481 var ConnHdlrPars pars;
2482 f_init();
2483 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2484 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2485 pcu_comp := false, trxc_comp := true);
2486 vc_conn.done;
2487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2488}
2489
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002490private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002491 timer T := 8.0;
2492 T.start;
2493 var RSL_Message rsl;
2494 alt {
2495 [] as_l1_sacch();
2496 [] L1CTL.receive { repeat; }
2497 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2498 if (rsl.ies[3].body.bs_power.power_level == level) {
2499 setverdict(pass)
2500 } else {
2501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2502 }
2503 }
2504 [] T.timeout {
2505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2506 }
2507 }
2508}
2509
2510/* see if the rsl meas res contains our expeced bs power level
2511bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002512private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002513 f_l1_tune(L1CTL);
2514 RSL.clear;
2515
2516 if (mp_bts_trxc_port != -1) {
2517 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2518 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2519 }
2520
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002521 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002522 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2523 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2524
2525 f_est_dchan(more_ies :={valueof(pwr)});
2526
2527 f_check_meas_bs_power_level(pwr_var);
2528
2529 f_rsl_chan_deact();
2530 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2531}
2532
2533/* see if the rsl meas res contains our expeced bs power level
2534bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002535private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002536 f_l1_tune(L1CTL);
2537 RSL.clear;
2538
2539 if (mp_bts_trxc_port != -1) {
2540 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2541 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2542 }
2543
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002544 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002545 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2546
2547 f_est_dchan();
2548
2549 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2550
2551 f_check_meas_bs_power_level(pwr_var);
2552
2553 f_rsl_chan_deact();
2554 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2555}
2556
2557testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2558 var ConnHdlr vc_conn;
2559 var ConnHdlrPars pars;
2560 f_init();
2561 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2562 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2563 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2564 pcu_comp := false, trxc_comp := true);
2565 vc_conn.done;
2566 }
2567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2568}
2569
2570testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2571 var ConnHdlr vc_conn;
2572 var ConnHdlrPars pars;
2573 f_init();
2574 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2575 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2576 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2577 pcu_comp := false, trxc_comp := true);
2578 vc_conn.done;
2579 }
2580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2581}
2582
Eric Wild61edb7e2019-06-03 12:38:31 +02002583/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2584second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2585These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002586private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002587 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002588 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002589
2590 f_trxc_fake_rssi(rxlev2dbm(10));
2591 f_l1_tune(L1CTL);
2592 RSL.clear;
2593
2594 var RSL_IE_List addl_ies;
2595 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2596
2597 addl_ies := {
2598 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2599 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2600 };
2601
2602 /* establish with power parameters */
2603 f_est_dchan(more_ies := addl_ies);
2604
2605 /* set a high value to ensure L1 power control level increases */
2606 f_trxc_fake_rssi(rxlev2dbm(20));
2607
2608 timer T2 := 6.0;
2609 T2.start;
2610 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002611 [] as_l1_sacch_l1h(l1h) {
2612 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002613 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002614 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002615 T2.stop;
2616 }
2617 [] L1CTL.receive { repeat; }
2618 [] T2.timeout {
2619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2620 "Power Level in L1 header has not increased sufficiently");
2621 }
2622 }
2623
2624 /* set a low value to ensure L1 power control level decreases */
2625 f_trxc_fake_rssi(rxlev2dbm(0));
2626
2627 timer T4 := 6.0;
2628 T4.start;
2629 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002630 [] as_l1_sacch_l1h(l1h) {
2631 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002632 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002633 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002634 T4.stop;
2635 setverdict(pass, "Power level in L1 decreased/increased as expected");
2636 }
2637 [] L1CTL.receive { repeat; }
2638 [] T4.timeout {
2639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2640 "Power Level in L1 header has not decreased sufficiently");
2641 }
2642 }
2643
2644 f_rsl_chan_deact();
2645 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2646
2647}
2648
2649/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002650private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002651 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002652 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002653
2654 /* set a low value to ensure power increases */
2655 f_trxc_fake_rssi(rxlev2dbm(10));
2656 f_l1_tune(L1CTL);
2657 RSL.clear;
2658
2659 var RSL_IE_List addl_ies;
2660 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2661
2662 addl_ies := {
2663 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2664 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2665 };
2666
2667 /* establish with power parameters */
2668 f_est_dchan(more_ies := addl_ies);
2669
2670 timer T1 := 10.0;
2671 T1.start;
2672 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002673 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002674 [] L1CTL.receive { repeat; }
2675 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002676 if (not isbound(l1h)) {
2677 setverdict(fail, "No SACCH blocks were received");
2678 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002679 setverdict(fail, "Power level in L1 header should not have changed");
2680 }
2681 }
2682 }
2683
2684 f_rsl_chan_deact();
2685 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2686
2687}
2688
2689/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002690private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002691 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002692 var uint5_t pwr_var := 15;
2693 var uint5_t pwr_max_var := f_get_max_power_from_band();
2694
2695 /* set a low value to ensure power increases */
2696 f_trxc_fake_rssi(rxlev2dbm(10));
2697 f_l1_tune(L1CTL);
2698 RSL.clear;
2699
2700 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2701 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2702
2703 /* establish with fixed power level */
2704 f_est_dchan(more_ies :={valueof(pwr)});
2705
2706 /* check our initial power level */
2707 f_wait_for_l1_power_level(pwr_var);
2708
2709 /* update power param to enable power loop
2710 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2711 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2712
2713 /* wait, then check that our power level was reduced */
2714 timer T1 := 10.0;
2715 T1.start;
2716 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002717 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002718 [] L1CTL.receive { repeat; }
2719 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002720 if (not isbound(l1h)) {
2721 setverdict(fail, "No SACCH blocks were received");
2722 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002723 setverdict(pass, "Power level in L1 header reduced as expected");
2724 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002725 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2726 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002727 }
2728 }
2729 }
2730
2731 f_rsl_chan_deact();
2732 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2733
2734}
2735
2736/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002737private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002738 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002739
2740 /* set a high value to ensure power decreases */
2741 f_trxc_fake_rssi(rxlev2dbm(50));
2742 f_l1_tune(L1CTL);
2743 RSL.clear;
2744
2745 var uint5_t pwr_var := 5;
2746 var uint5_t pwr_target_val := 15;
2747
2748 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2749 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2750
2751 /* establish with fixed power level */
2752 f_est_dchan(more_ies :={valueof(pwr)});
2753
2754 /* check our initial power level */
2755 f_wait_for_l1_power_level(pwr_var);
2756
2757 /* update power param to enable power loop
2758 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002759 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002760
2761 /* wait, then check that our power level was increased */
2762 timer T1 := 10.0;
2763 T1.start;
2764 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002765 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002766 [] L1CTL.receive { repeat; }
2767 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002768 if (not isbound(l1h)) {
2769 setverdict(fail, "No SACCH blocks were received");
2770 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2771 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002772 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002773 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002774 }
2775 }
2776 }
2777
2778 f_rsl_chan_deact();
2779 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2780
2781}
2782
Eric Wild095024b2019-06-17 15:08:57 +02002783/* see if we change the power level without receiving power parameters, which should not happen
2784rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002785private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002786 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002787
2788 /* set a high value to ensure power decreases */
2789 f_trxc_fake_rssi(rxlev2dbm(50));
2790 f_l1_tune(L1CTL);
2791 RSL.clear;
2792
2793 var uint5_t pwr_var := 5;
2794
2795 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2796 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2797
2798 /* establish with fixed power level */
2799 f_est_dchan(more_ies :={valueof(pwr)});
2800
2801 /* check our initial power level */
2802 f_wait_for_l1_power_level(pwr_var);
2803
2804 /* wait, then check that our power level did not change */
2805 timer T1 := 10.0;
2806 T1.start;
2807 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002808 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2809 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2811 "BS power control should not be active unless we receive a power parameters IE!");
2812 }
2813 repeat;
2814 }
2815 [] L1CTL.receive { repeat; }
2816 [] T1.timeout { setverdict(pass); }
2817 }
2818
2819 f_rsl_chan_deact();
2820 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2821
2822}
2823
Eric Wild095024b2019-06-17 15:08:57 +02002824/* see if we change the power level without receiving power parameters, which should not happen
2825ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002826private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002827 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002828
2829 /* set a high value to ensure power decreases */
2830 f_trxc_fake_rssi(rxlev2dbm(50));
2831 f_l1_tune(L1CTL);
2832 RSL.clear;
2833
2834 var uint5_t pwr_var := 5;
2835
2836 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2837 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2838
2839 /* establish with fixed power level */
2840 f_est_dchan(more_ies :={valueof(pwr)});
2841
2842 /* check our initial power level */
2843 f_wait_for_l1_power_level(pwr_var);
2844
2845 /* pwr control without power params IE, should NOT activate MS power control*/
2846 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2847
2848 /* wait, then check that our power level did not change */
2849 timer T1 := 10.0;
2850 T1.start;
2851 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002852 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2853 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2855 "BS power control should not be active unless we receive a power parameters IE!");
2856 }
2857 repeat;
2858 }
2859 [] L1CTL.receive { repeat; }
2860 [] T1.timeout { setverdict(pass); }
2861 }
2862
2863 f_rsl_chan_deact();
2864 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2865
2866}
2867
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002868private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002869 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002870 timer T0 := 10.0;
2871 T0.start;
2872 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002873 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2874 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2876 "Power level in L1 header != signaled (RSL) power level.");
2877 }
2878 }
2879 [] L1CTL.receive { repeat; }
2880 [] T0.timeout {
2881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2882 "Timeout waiting for initial power level");
2883 }
2884 }
2885 T0.stop;
2886}
2887
2888private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2889 var IntegerRecord min_dbm_level;
2890 var IntegerRecord max_dbm_level;
2891 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2892
2893 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2894 if (min_dbm_level[i] == level) {
2895 return true;
2896 }
2897 }
2898 return false;
2899}
2900
2901private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2902 var IntegerRecord min_dbm_level;
2903 var IntegerRecord max_dbm_level;
2904 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2905
2906 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2907 if (max_dbm_level[i] == level) {
2908 return true;
2909 }
2910 }
2911 return false;
2912}
2913
2914private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2915 var IntegerRecord min_dbm_level;
2916 var IntegerRecord max_dbm_level;
2917 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2918 return max_dbm_level[0];
2919}
2920
2921type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002922private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002923private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2924 // 45.005 4.1.1
2925 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2926 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2927 2, 1, 0};
2928 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2929 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2930 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2931 var IntegerRecord rv;
2932
2933 select(band){
2934 case (BtsBand_allGSM){
2935 rv := gsm_power;
2936 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2937 max_dbm_level := {2, 1, 0};
2938 }
2939 case("DCS1800"){
2940 rv := dcs_power;
2941 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2942 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2943 }
2944 case("PCS1900"){
2945 rv := pcs_power;
2946 min_dbm_level := {15};
2947 max_dbm_level := {30};
2948 }
Harald Welte194b6912020-10-11 21:01:55 +02002949 case else {
2950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2951 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002952 }
2953
2954 return rv;
2955}
2956
2957private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002958 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 +02002959}
2960
2961testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2962 var ConnHdlr vc_conn;
2963 var ConnHdlrPars pars;
2964 f_init();
2965 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2966 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2967 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2968 pars.bts0_band := f_vty_get_bts0_band();
2969 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2970 vc_conn.done;
2971 }
2972 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2974}
2975
2976testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2977 var ConnHdlr vc_conn;
2978 var ConnHdlrPars pars;
2979 f_init();
2980 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2981 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2982 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2983 pars.bts0_band := f_vty_get_bts0_band();
2984 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2985 vc_conn.done;
2986 }
2987 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2989}
2990
2991testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2992 var ConnHdlr vc_conn;
2993 var ConnHdlrPars pars;
2994 f_init();
2995 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2996 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2997 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2998 pars.bts0_band := f_vty_get_bts0_band();
2999 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3000 vc_conn.done;
3001 }
3002 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3004}
3005
3006testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3007 var ConnHdlr vc_conn;
3008 var ConnHdlrPars pars;
3009 f_init();
3010 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3011 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3012 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3013 pars.bts0_band := f_vty_get_bts0_band();
3014 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3015 vc_conn.done;
3016 }
3017 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3019}
3020
Eric Wild280ccb82019-06-17 11:11:52 +02003021testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3022 var ConnHdlr vc_conn;
3023 var ConnHdlrPars pars;
3024 f_init();
3025 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3026 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3027 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3028 pars.bts0_band := f_vty_get_bts0_band();
3029 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3030 vc_conn.done;
3031 }
3032 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3034}
3035
Eric Wild095024b2019-06-17 15:08:57 +02003036testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3037 var ConnHdlr vc_conn;
3038 var ConnHdlrPars pars;
3039 f_init();
3040 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3041 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3042 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3043 pars.bts0_band := f_vty_get_bts0_band();
3044 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3045 vc_conn.done;
3046 }
3047 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3049}
3050
Philipp Maier149c3922020-10-22 17:29:36 +02003051function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003052 var template RSL_IE_ChannelMode ch_mode;
3053 var ConnHdlr vc_conn;
3054 var ConnHdlrPars pars;
3055 f_init();
3056 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3057 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3058 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003059 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003060 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3061 pcu_comp := false, trxc_comp := true);
3062 vc_conn.done;
3063 }
3064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3065}
Philipp Maier149c3922020-10-22 17:29:36 +02003066
3067testcase TC_meas_res_speech_tchf() runs on test_CT {
3068 f_TC_meas_res_speech_tchf(false);
3069}
3070
3071testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3072 f_TC_meas_res_speech_tchf(true);
3073}
3074
3075function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003076 var template RSL_IE_ChannelMode ch_mode;
3077 var ConnHdlr vc_conn;
3078 var ConnHdlrPars pars;
3079 f_init();
3080 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3081 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3082 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003083 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003084 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3085 pcu_comp := false, trxc_comp := true);
3086 vc_conn.done;
3087 }
3088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3089}
Philipp Maier149c3922020-10-22 17:29:36 +02003090
3091testcase TC_meas_res_speech_tchh() runs on test_CT {
3092 f_TC_meas_res_speech_tchh(false)
3093}
3094
3095testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3096 f_TC_meas_res_speech_tchh(true)
3097}
3098
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003099testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3100 var template RSL_IE_ChannelMode ch_mode;
3101 var ConnHdlr vc_conn;
3102 var ConnHdlrPars pars;
3103 f_init();
3104 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3105 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3106 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3107 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3108 pars.l1_pars.toa256_enabled := true;
3109 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3110 pcu_comp := false, trxc_comp := true);
3111 vc_conn.done;
3112 }
3113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3114}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003115
Harald Welte70767382018-02-21 12:16:40 +01003116testcase TC_meas_res_sign_tchf() runs on test_CT {
3117 var ConnHdlr vc_conn;
3118 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003119 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003120 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003121 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003122 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3123 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003124 vc_conn.done;
3125 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003127}
3128testcase TC_meas_res_sign_tchh() runs on test_CT {
3129 var ConnHdlr vc_conn;
3130 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003131 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003132 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003133 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003134 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3135 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003136 vc_conn.done;
3137 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003139}
3140testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3141 var ConnHdlr vc_conn;
3142 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003143 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003144 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3145 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003146 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3147 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003148 vc_conn.done;
3149 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003151}
3152testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3153 var ConnHdlr vc_conn;
3154 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003155 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003156 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3157 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003158 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3159 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003160 vc_conn.done;
3161 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003163}
Harald Welte685d5982018-02-27 20:42:05 +01003164testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3165 var ConnHdlr vc_conn;
3166 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003167 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003168 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3169 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003170 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003171 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003172 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3173 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003174 vc_conn.done;
3175 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003176 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003177}
3178
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003179/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3180 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003181private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003182 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003183 var RSL_IE_MS_Power ms_power;
3184 var RSL_Message rsl;
3185 var uint5_t power_level := 0;
3186
3187 f_l1_tune(L1CTL);
3188 RSL.clear;
3189
3190 f_est_dchan();
3191
3192 ms_power.reserved := 0;
3193 ms_power.fpc_epc := false;
3194
3195 /* Send the first power control command. This will disable any BTS/TRX
3196 * internal power control and switch the MS (which is not in scope of
3197 * this test) to a constant power level. We start with a power level
3198 * of 0 */
3199 ms_power.power_level := power_level;
3200 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3201 RSL.send(rsl);
3202
3203 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003204 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3205 if (l1h.ms_power_lvl != power_level) {
3206 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3207 "match the signaled (RSL) power level := ", power_level);
3208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003209 }
3210
3211 /* Signal a new power level via RSL for the next turn. */
3212 if (power_level < 31) {
3213 power_level := power_level + 1;
3214 ms_power.power_level := power_level;
3215 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3216 RSL.send(rsl);
3217 repeat;
3218 }
3219
3220 }
3221
3222 /* Ignore all other blocks */
3223 [] L1CTL.receive { repeat; }
3224
3225 }
3226
3227 f_rsl_chan_deact();
3228 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3229
3230 setverdict(pass);
3231}
3232
3233testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3234 var ConnHdlr vc_conn;
3235 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003236 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003237
3238 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3239 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3240 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3241 vc_conn.done;
3242 }
3243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3244}
Harald Welte70767382018-02-21 12:16:40 +01003245
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003246/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003247TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003248private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003249 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003250 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003251
3252 f_l1_tune(L1CTL);
3253 RSL.clear;
3254
3255 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003256 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003257
3258 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3259
3260
3261 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003262 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3263 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003264 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3265 }
3266
3267 }
3268
3269 /* Ignore all other blocks */
3270 [] L1CTL.receive { repeat; }
3271
3272 }
3273
3274 f_rsl_chan_deact();
3275 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3276
3277 setverdict(pass);
3278}
3279
3280testcase TC_rsl_chan_initial_ta() runs on test_CT {
3281 var ConnHdlr vc_conn;
3282 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003283 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003284 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003285 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3286 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003287 vc_conn.done;
3288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3289}
3290
Eric Wilde57e1a62019-05-28 13:30:55 +02003291/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003292private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003293 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003294 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003295
3296 var RSL_IE_MS_Power ms_power;
3297 ms_power.reserved := 0;
3298 ms_power.fpc_epc := false;
3299 ms_power.power_level := ms_power_level;
3300
3301 f_l1_tune(L1CTL);
3302 RSL.clear;
3303
3304 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3305
3306 timer T := 1.0;
3307 T.start;
3308 alt {
3309 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003310 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3311 if (l1h.ms_power_lvl != ms_power_level) {
3312 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3313 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003314 }
3315 }
3316 /* Ignore all other blocks */
3317 [] L1CTL.receive { repeat; }
3318 [] T.timeout {
3319 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3320 }
3321 }
3322
3323 f_rsl_chan_deact();
3324 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3325 setverdict(pass);
3326}
3327
3328testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3329 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3330 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3331}
3332
Harald Welte0472ab42018-03-12 15:02:26 +01003333/* 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 +01003334private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003335 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003336 RSL.clear;
3337
3338 f_est_dchan();
3339 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003340 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003341
3342 timer T := 40.0;
3343 T.start;
3344 alt {
3345 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3346 setverdict(pass)
3347 }
3348 [] RSL.receive { repeat };
3349 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003351 }
3352 }
3353 f_rsl_chan_deact();
3354}
3355testcase TC_conn_fail_crit() runs on test_CT {
3356 var ConnHdlr vc_conn;
3357 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003358 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003359 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3360 pars.t_guard := 60.0;
3361 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3362 vc_conn.done;
3363}
3364
Harald Welte93640c62018-02-25 16:59:33 +01003365/***********************************************************************
3366 * Paging
3367 ***********************************************************************/
3368
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003369private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003370 if (tmsi == 'FFFFFFFF'O) {
3371 return true;
3372 } else {
3373 return false;
3374 }
3375}
Harald Welte70767382018-02-21 12:16:40 +01003376
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003377private type record allowedFn { integer frame_nr }
3378private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3379private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3380private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3381private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3382private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3383private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3384private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3385private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3386private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003387{
3388 var integer frame_nr_51;
3389 frame_nr_51 := frame_nr mod 51
3390
3391 var allowedFn fn_check;
3392 fn_check.frame_nr := frame_nr_51;
3393
3394 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003396 return;
3397 }
3398
3399 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3400 return;
3401 }
3402 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3403 return;
3404 }
3405 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3406 return;
3407 }
3408 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3409 return;
3410 }
3411 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3412 return;
3413 }
3414 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3415 return;
3416 }
3417 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3418 return;
3419 }
3420 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3421 return;
3422 }
3423
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003425 return;
3426}
3427
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003428private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3429 inout integer num_paging_rcv_ids,
3430 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003431runs on test_CT {
3432 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003433 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003434 repeat;
3435 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003436 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003437 var octetstring without_plen :=
3438 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3439 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003440
3441 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3442
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003443 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3444 /* Ignore empty RR Paging Request (PCH filling) messages.
3445 * TODO: does it make sense to count them? */
3446 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003447 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3448 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003449 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003450 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3451 }
3452 } else if (match(rr, tr_PAGING_REQ2)) {
3453 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3454 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3455 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3456 }
3457 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3458 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3459 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003460 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003461 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3462 }
3463 } else if (match(rr, tr_PAGING_REQ3)) {
3464 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3465 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3466 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3467 }
3468 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3469 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3470 }
3471 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3472 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3473 }
3474 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3475 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3476 }
3477 }
3478 repeat;
3479 }
3480}
3481
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003482private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003483 boolean combined_ccch,
3484 integer bs_ag_blks_res,
3485 float load_factor,
3486 boolean exp_load_ind,
3487 boolean exp_overload,
3488 boolean use_tmsi
3489}
3490
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003491private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003492 integer num_paging_sent,
3493 integer num_paging_rcv_msgs,
3494 integer num_paging_rcv_ids,
3495 integer num_overload
3496}
3497
Harald Welte68e495b2018-02-25 00:05:57 +01003498/* Helper function for paging related testing */
3499private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003500 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003501 f_init_l1ctl();
3502 f_l1_tune(L1CTL);
3503
3504 var PagingTestState st := {
3505 num_paging_sent := 0,
3506 num_paging_rcv_msgs := 0,
3507 num_paging_rcv_ids := 0,
3508 num_overload := 0
3509 };
3510
3511 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3512 var float max_pch_imsi_per_sec;
3513 if (cfg.use_tmsi) {
3514 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3515 } else {
3516 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3517 }
3518 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3519 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003520 var float time_total := 20.0;
3521 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3522 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003523
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003524 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3525 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003526
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003527 timer T_itv := 0.0;
3528 T_itv.start;
3529 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003530 alt {
3531 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003532 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003533 st.num_overload := st.num_overload + 1;
3534 repeat;
3535 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003536 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003538 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003539 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003540 log("Rx LOAD_IND");
3541 /* FIXME: analyze/verify interval + contents */
3542 repeat;
3543 }
3544 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003545 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003546 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003547 [] T_itv.timeout {
3548 /* Send paging cmds based on elapsed time */
3549 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3550 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003551 var MobileIdentityV mi;
3552
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003553 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003554 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003555 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003556 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003557 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003558 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003559
3560 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003561 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 +02003562
3563 st.num_paging_sent := st.num_paging_sent + 1;
3564 }
3565 if (st.num_paging_sent < pkt_total) {
3566 /* Wait for interval to next PAGING COMMAND */
3567 var float time_now := T_total.read;
3568 var float next_sched := int2float(st.num_paging_sent)*interval;
3569 if (next_sched > time_now) {
3570 T_itv.start(next_sched - time_now);
3571 } else {
3572 T_itv.start(0.0);
3573 }
3574 } else {
3575 /* We are done, no need to keep counting */
3576 T_total.stop;
3577 }
3578 }
3579 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003580 }
3581 }
3582
3583 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3584 timer T_wait := 18.0;
3585 T_wait.start;
3586 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003587 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003588 [] L1CTL.receive { repeat; }
3589 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003590 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3591 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003592 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003594 }
Harald Welte68e495b2018-02-25 00:05:57 +01003595 }
3596
3597 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3598 " rcvd_ids=", st.num_paging_rcv_ids);
3599 return st;
3600}
3601
3602/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3603 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3604 * - that CCCH LOAD IND (PCH) are being generated
3605 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3606testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003607 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003608 var PagingTestCfg cfg := {
3609 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003610 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003611 load_factor := 0.8,
3612 exp_load_ind := true,
3613 exp_overload := false,
3614 use_tmsi := false
3615 };
3616 var PagingTestState st := f_TC_paging(cfg);
3617 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3619 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003620 } else {
3621 setverdict(pass);
3622 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003624}
3625
3626/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3627 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3628 * - that CCCH LOAD IND (PCH) are being generated
3629 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3630testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003631 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003632 var PagingTestCfg cfg := {
3633 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003634 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003635 load_factor := 0.8,
3636 exp_load_ind := true,
3637 exp_overload := false,
3638 use_tmsi := true
3639 };
3640 var PagingTestState st := f_TC_paging(cfg);
3641 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3643 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003644 } else {
3645 setverdict(pass);
3646 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003648}
3649
3650/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3651 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3652 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3653 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3654testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003655 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003656 var PagingTestCfg cfg := {
3657 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003658 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003659 load_factor := 2.0,
3660 exp_load_ind := true,
3661 exp_overload := true,
3662 use_tmsi := false
3663 };
3664 var PagingTestState st := f_TC_paging(cfg);
3665 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3666 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003667 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003668 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 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 +01003670 } else {
3671 setverdict(pass);
3672 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003674}
3675
3676/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3677 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3678 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3679 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3680testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003681 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003682 var PagingTestCfg cfg := {
3683 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003684 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003685 load_factor := 2.0,
3686 exp_load_ind := true,
3687 exp_overload := true,
3688 use_tmsi := true
3689 };
3690 var PagingTestState st := f_TC_paging(cfg);
3691 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3692 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003693 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003694 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003695 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 +01003696 } else {
3697 setverdict(pass);
3698 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003700}
3701
3702
Harald Welte93640c62018-02-25 16:59:33 +01003703/***********************************************************************
3704 * Immediate Assignment / AGCH
3705 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003706private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003707 len := 0,
3708 ma := ''B
3709}
Harald Welte93640c62018-02-25 16:59:33 +01003710
Harald Weltee8d750e2018-06-10 21:41:35 +02003711private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3712 return int2str(num_tx) & " sent, "
3713 & int2str(num_rx) & " received, "
3714 & int2str(num_del) & " deleted";
3715}
3716
3717private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3718 var L1ctlDlMessage l1_dl;
3719 timer T := 10.0;
3720 var integer num_tx := 0;
3721 var integer num_rx := 0;
3722 var integer num_del := 0;
3723 var charstring res_str;
3724 var float rx_ratio;
3725
Harald Welte10474062019-05-30 16:48:17 +02003726 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003727 f_init_l1ctl();
3728 f_l1_tune(L1CTL);
3729
3730 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003731 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003732 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3733 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003734 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003735 num_tx := num_tx+1;
3736 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003737 }
3738 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003739 T.start;
3740 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003741 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003742 num_del := num_del+1;
3743 repeat;
3744 }
3745 [] RSL_CCHAN.receive {
3746 repeat;
3747 }
3748 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003749 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3750 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3751 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003752 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003753 } else {
3754 num_rx := num_rx+1;
3755 }
3756 repeat;
3757 }
3758 [] L1CTL.receive { repeat; }
3759 [] T.timeout { }
3760 }
3761 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3762 log("AGCH test: " & res_str);
3763 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003765 }
3766 rx_ratio := int2float(num_rx) / int2float(num_tx);
3767 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003768 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 +02003769 } else {
3770 setverdict(pass);
3771 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003773}
3774
Harald Weltee8d750e2018-06-10 21:41:35 +02003775/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3776testcase TC_imm_ass_1000_20ms() runs on test_CT {
3777 f_TC_imm_ass(1000, 0.02, 0.25);
3778}
3779
3780/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3781testcase TC_imm_ass_200_0ms() runs on test_CT {
3782 f_TC_imm_ass(200, 0.0, 0.05);
3783}
3784
3785/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3786testcase TC_imm_ass_200_76ms() runs on test_CT {
3787 f_TC_imm_ass(150, 0.076, 1.00);
3788}
3789
3790
3791
Harald Welte48494ca2018-02-25 16:59:50 +01003792/***********************************************************************
3793 * BCCH
3794 ***********************************************************************/
3795
3796/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003797private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003798 GsmFrameNumber frame_number,
3799 SystemInformation si
3800}
3801
3802/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003803private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003804
3805/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003806private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003807
3808/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003809private function f_si_vecslot_contains(SystemInformationVector arr,
3810 RrMessageType key,
3811 boolean bcch_ext := false)
3812return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003813 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3814 var integer fn_mod51 := arr[i].frame_number mod 51;
3815 if (not bcch_ext and fn_mod51 == 2 or
3816 bcch_ext and fn_mod51 == 6) {
3817 if (arr[i].si.header.message_type == key) {
3818 return true;
3819 }
3820 }
3821 }
3822 return false;
3823}
3824
3825/* 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 +07003826private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3827 integer tc, RrMessageType key,
3828 boolean ext_bcch := false)
3829{
Harald Welte48494ca2018-02-25 16:59:50 +01003830 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003832 }
3833}
3834
3835/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003836private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3837 RrMessageType key)
3838return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003839 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3840 if (f_si_vecslot_contains(arr[tc], key) or
3841 f_si_vecslot_contains(arr[tc], key, true)) {
3842 return true;
3843 }
3844 }
3845 return false;
3846}
3847
3848/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003849private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3850 RrMessageType key,
3851 boolean bcch_ext := false,
3852 integer n := 1, integer m := 4)
3853return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003854 var integer count := 0;
3855 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3857 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003858 }
3859 for (var integer i:= 0; i < m; i := i + 1) {
3860 var integer fn_mod51 := arr[i].frame_number mod 51;
3861 if (not bcch_ext and fn_mod51 == 2 or
3862 bcch_ext and fn_mod51 == 6) {
3863 if (arr[i].si.header.message_type == key) {
3864 count := count + 1;
3865 }
3866 }
3867 }
3868 if (count >= n) {
3869 return true;
3870 } else {
3871 return false;
3872 }
3873}
3874
3875/* 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 +07003876private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3877 integer tc, RrMessageType key,
3878 boolean ext_bcch := false,
3879 integer n, integer m)
3880{
Harald Welte48494ca2018-02-25 16:59:50 +01003881 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003883 }
3884}
3885
3886/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003887private function f_si_vecslot_contains_only(SystemInformationVector arr,
3888 RrMessageType key,
3889 boolean bcch_ext := false)
3890return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003891 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3892 var integer fn_mod51 := arr[i].frame_number mod 51;
3893 if (not bcch_ext and fn_mod51 == 2 or
3894 bcch_ext and fn_mod51 == 6) {
3895 if (arr[i].si.header.message_type != key) {
3896 return false;
3897 }
3898 }
3899 }
3900 return true;
3901}
3902
3903/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003904private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3905 integer tc, RrMessageType key,
3906 boolean ext_bcch := false)
3907{
Harald Welte48494ca2018-02-25 16:59:50 +01003908 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003910 }
3911}
3912
3913/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003914private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003915 boolean bcch_extended,
3916 boolean si1_present,
3917 boolean si2bis_present,
3918 boolean si2ter_present,
3919 boolean si2quater_present,
3920 boolean si7_present,
3921 boolean si8_present,
3922 boolean si9_present,
3923 boolean si13_present,
3924 boolean si13alt_present,
3925 boolean si15_present,
3926 boolean si16_present,
3927 boolean si17_present,
3928 boolean si2n_present,
3929 boolean si21_present,
3930 boolean si22_present
3931}
3932
3933/* 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 +07003934private function f_validate_si_scheduling(SystemInformationConfig cfg,
3935 SystemInformationVectorPerTc si_per_tc)
3936{
Harald Welte48494ca2018-02-25 16:59:50 +01003937 var integer i;
3938 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3939 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003941 }
3942 }
3943 if (cfg.si1_present) {
3944 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3945 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3946 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3947 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3948 /* make sure *ALL* contain SI1 */
3949 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3950 }
3951 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3952 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3953 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3954 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3955 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3956 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3957
3958 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3959 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3960 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3961 * consecutive occurrences of TC = 4. */
3962 if (cfg.si2bis_present and not cfg.si2ter_present) {
3963 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3964 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3965 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3966 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3967 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3968 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3969 }
3970
3971 if (cfg.si7_present or cfg.si8_present) {
3972 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3973 * if System Information type 4 does not contain all information needed for cell
3974 * selection and reselection. */
3975 if (not cfg.bcch_extended) {
3976 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3977 }
3978 if (cfg.si7_present) {
3979 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3980 }
3981 if (cfg.si8_present) {
3982 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3983 }
3984 }
3985
3986 if (cfg.si2quater_present) {
3987 /* iii) System information type 2 quater is sent if needed, as determined by the system
3988 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3989 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3990 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3991 * within any of 4 consecutive occurrences of TC = 5. */
3992 if (not (cfg.bcch_extended)) {
3993 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3994 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3995 } else {
3996 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3997 }
3998 } else {
3999 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4000 }
4001 }
4002 if (cfg.si9_present) {
4003 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4004 * in system information type 3 as defined in 3GPP TS 44.018. */
4005 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4006 }
4007 if (cfg.si13_present) {
4008 /* vii) System Information type 13 is only related to the GPRS service. System Information
4009 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4010 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4011 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4012 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4013 * within any of 4 consecutive occurrences of TC=4. */
4014 if (not cfg.bcch_extended) {
4015 log("not-bccch-extended");
4016 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4017 } else {
4018 log("bccch-extended");
4019 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4020 }
4021 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004023 }
4024 }
4025 if (cfg.si16_present or cfg.si17_present) {
4026 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4027 * should not be sent in a cell where network sharing is used (see rule xv). */
4028 if (cfg.si22_present) {
4029 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4030 }
4031 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004033 }
4034 if (not cfg.bcch_extended) {
4035 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4036 }
4037 if (cfg.si16_present) {
4038 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4039 }
4040 if (cfg.si17_present) {
4041 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4042 }
4043 }
4044
4045 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4046 * broadcast information. The frequency with which they are sent is determined by the
4047 * system operator. System Information type 9 identifies the scheduling of System
4048 * Information type 18 and 20 messages. */
4049
4050 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4051 * Information Type 19 is present, then its scheduling shall be indicated in System
4052 * Information Type 9. */
4053
4054 if (cfg.si15_present) {
4055 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4056 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4057 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4058 * 4 consecutive occurrences of TC = 1. */
4059 if (not cfg.bcch_extended) {
4060 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4061 } else {
4062 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4063 }
4064 }
4065 if (cfg.si13alt_present) {
4066 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4067 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4068 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4069 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4070 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4071 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4072 * of TC = 4. */
4073 if (cfg.si13_present) {
4074 testcase.stop("Error: Cannot have SI13alt and SI13");
4075 }
4076 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004078 }
4079 if (not cfg.bcch_extended) {
4080 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4081 } else {
4082 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4083 }
4084 }
4085 if (cfg.si2n_present) {
4086 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4087 * as determined by the system operator. In the case that the message is sent on the
4088 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4089 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4090 * consecutive occurrences of TC = 4. */
4091 if (not cfg.bcch_extended) {
4092 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4093 } else {
4094 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4095 }
4096 }
4097 if (cfg.si21_present) {
4098 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4099 * determined by the system operator. If Extended Access Barring is in use in the cell
4100 * then this message is sent at least once within any of 4 consecutive occurrences of
4101 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4102 * cell then this message shall only be sent on BCCH Ext. */
4103 if (not cfg.bcch_extended) {
4104 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4105 } else {
4106 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4107 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004109 }
4110 }
4111 }
4112 if (cfg.si22_present) {
4113 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4114 * should not be sent in a cell where SoLSA is used (see rule viii). System
4115 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4116 * =2 and TC=6. */
4117 if (cfg.si16_present or cfg.si17_present) {
4118 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4119 }
4120 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4121 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004123 }
4124 if (not cfg.bcch_extended) {
4125 testcase.stop("Error: SI22 requires BCCH Extd!");
4126 } else {
4127 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4128 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4129 }
4130 }
4131}
4132
4133/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004134private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4135return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004136 timer T := duration;
4137 var SystemInformationVectorPerTc si_per_tc;
4138 var L1ctlDlMessage l1_dl;
4139
4140 /* initialize all per-TC vectors empty */
4141 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4142 si_per_tc[i] := {};
4143 }
4144
4145 /* flush all previous L1 queued msgs */
4146 pt.clear;
4147
4148 T.start;
4149 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004150 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004151 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4152 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4153 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004154 repeat;
4155 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004156
Harald Welte48494ca2018-02-25 16:59:50 +01004157 var integer tc := f_gsm_compute_tc(sig.frame_number);
4158 log("SI received at TC=", tc, ": ", sig.si);
4159 /* append to the per-TC bucket */
4160 si_per_tc[tc] := si_per_tc[tc] & { sig };
4161 repeat;
4162 }
4163 [] pt.receive { repeat; }
4164 [] T.timeout { }
4165 }
4166
4167 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4168 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4169 }
4170 log("si_per_tc=", si_per_tc);
4171 return si_per_tc;
4172}
4173
4174/* helper function: Set given SI via RSL + validate scheduling.
4175 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004176private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004177 var SystemInformationVectorPerTc si_per_tc;
4178 f_init_l1ctl();
4179 f_l1_tune(L1CTL);
4180
4181 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004182 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004183 f_validate_si_scheduling(si_cfg, si_per_tc);
4184
4185 setverdict(pass);
4186}
4187
4188testcase TC_si_sched_default() runs on test_CT {
4189 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004190 /* 2+3+4 are mandatory and set in f_init() */
4191 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004193}
4194
4195testcase TC_si_sched_1() runs on test_CT {
4196 f_init();
4197 si_cfg.si1_present := true;
4198 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004199 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004201}
4202
4203testcase TC_si_sched_2bis() runs on test_CT {
4204 f_init();
4205 si_cfg.si2bis_present := true;
4206 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4207 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004209}
4210
4211testcase TC_si_sched_2ter() runs on test_CT {
4212 f_init();
4213 si_cfg.si2ter_present := true;
4214 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4215 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004217}
4218
4219testcase TC_si_sched_2ter_2bis() runs on test_CT {
4220 f_init();
4221 si_cfg.si2bis_present := true;
4222 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4223 si_cfg.si2ter_present := true;
4224 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4225 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004227}
4228
4229testcase TC_si_sched_2quater() runs on test_CT {
4230 f_init();
4231 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004232 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004233 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004235}
4236
4237testcase TC_si_sched_13() runs on test_CT {
4238 f_init();
4239 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004240 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004241 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004243}
4244
4245testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4246 f_init();
4247 si_cfg.si2bis_present := true;
4248 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4249 si_cfg.si2ter_present := true;
4250 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4251 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004252 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004253 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004254 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004255 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004257}
4258
4259
Harald Welte68e495b2018-02-25 00:05:57 +01004260testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004261 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004262 /* FIXME: enable / disable individual BCCH info */
4263 //ts_RSL_BCCH_INFO(si_type, info);
4264 /* expect no ERROR REPORT after either of them *
4265 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004267}
4268
Harald Welte93640c62018-02-25 16:59:33 +01004269/***********************************************************************
4270 * Low-Level Protocol Errors / ERROR REPORT
4271 ***********************************************************************/
4272
Harald Welte01d982c2018-02-25 01:31:40 +01004273private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4274 timer T := 5.0;
4275 T.start;
4276 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004277 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004278 setverdict(pass);
4279 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004280 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004282 }
4283 [] RSL_CCHAN.receive {
4284 repeat;
4285 }
4286 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004288 }
4289 }
4290}
4291
4292/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4293testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004294 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004295 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4296 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004297 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004298
4299 f_exp_err_rep(RSL_ERR_PROTO);
4300}
4301
4302/* Provoke a mandatory IE error and match on ERROR REPORT */
4303testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004304 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004305
4306 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4307 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004308 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004309
4310 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4311}
4312
4313/* Provoke an IE content error and match on ERROR REPORT */
4314testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004315 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004316 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4317 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004318 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004319
4320 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4321}
4322
Harald Welteee25aae2019-05-19 14:32:37 +02004323/* attempt to activate channel with wrong RSL Message Discriminator IE */
4324function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4325 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4326 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4327 RSL.send(rsl);
4328 f_rslem_unregister(0, g_chan_nr);
4329}
4330testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4331 var ConnHdlr vc_conn;
4332 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4333
Harald Welte10474062019-05-30 16:48:17 +02004334 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004335
4336 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4337 vc_conn.done;
4338 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4339
4340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4341}
4342
4343/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004344private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004345 var template (value) RSL_Message rsl_tx;
4346 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4347 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4348 RSL.send(rsl_tx);
4349 f_rslem_unregister(0, g_chan_nr);
4350}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004351private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004352 var template (value) RSL_Message rsl_tx;
4353 /* we first have to activate the dedicated channel */
4354 f_rsl_chan_act(g_pars.chan_mode);
4355 /* ... to then send an invalid RLL message */
4356 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4357 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4358 RSL.send(rsl_tx);
4359 f_rslem_unregister(0, g_chan_nr);
4360}
4361testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4362 var ConnHdlr vc_conn;
4363 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4364 var template (value) RSL_Message rsl_tx;
4365
Harald Welte10474062019-05-30 16:48:17 +02004366 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004367
4368 /* Common Channel with wrong message type */
4369 RSL_CCHAN.clear;
4370 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4371 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004372 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004373 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4374
4375 /* TRX Management */
4376 RSL_CCHAN.clear;
4377 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4378 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004379 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004380 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4381
4382 /* Dedicated Channel */
4383 RSL_CCHAN.clear;
4384 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4385 vc_conn.done;
4386 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4387
4388 /* RLL */
4389 RSL_CCHAN.clear;
4390 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4391 vc_conn.done;
4392 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4393}
4394
4395/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004396private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004397 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4398 f_rslem_unregister(0, g_chan_nr);
4399}
4400testcase TC_err_rep_wrong_sequence() runs on test_CT {
4401 var ConnHdlr vc_conn;
4402 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4403
Harald Welte10474062019-05-30 16:48:17 +02004404 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004405
4406 RSL_CCHAN.clear;
4407 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4408 vc_conn.done;
4409 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4410}
4411
Harald Welte93640c62018-02-25 16:59:33 +01004412/***********************************************************************
4413 * IPA CRCX/MDCX/DLCS media stream handling
4414 ***********************************************************************/
4415
Harald Weltea871a382018-02-25 02:03:14 +01004416/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004417private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004418 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4419 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004420}
4421testcase TC_ipa_dlcx_not_active() runs on test_CT {
4422 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004423 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004424 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4425 vc_conn.done;
4426}
Harald Welte68e495b2018-02-25 00:05:57 +01004427
Harald Weltea3f1df92018-02-25 12:49:55 +01004428/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004429private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004430 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4431 "IPA CRCX ACK");
4432 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4433 "IPA CRCX NACK");
4434}
4435testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4436 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004437 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004438 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4439 vc_conn.done;
4440}
4441
4442/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004443private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004444 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4445 "IPA CRCX ACK");
4446 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4447 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4448 var uint7_t rtp_pt2 := f_rnd_int(127);
4449 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4450 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4451 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4452 "IPA MDCX ACK");
4453 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4454 "IPA DLCX ACK");
4455}
4456testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4457 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004458 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004459 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4460 vc_conn.done;
4461}
4462
Harald Welte3ae11da2018-02-25 13:36:06 +01004463/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004464private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004465 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4466 "IPA CRCX ACK");
4467 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4468 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4469 var uint7_t rtp_pt2 := f_rnd_int(127);
4470 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4471 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4472 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4473 "IPA MDCX ACK");
4474 /* Second MDCX */
4475 remote_ip := f_rnd_int(c_UINT32_MAX);
4476 remote_port := f_rnd_int(c_UINT16_MAX);
4477 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4478 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4479 "IPA MDCX ACK");
4480 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4481 "IPA DLCX ACK");
4482}
4483testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4484 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004485 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004486 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4487 vc_conn.done;
4488}
4489
Harald Welte9912eb52018-02-25 13:30:15 +01004490/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004491private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004492 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4493 "IPA CRCX NACK");
4494}
4495testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4496 var ConnHdlrPars pars;
4497 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004498 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004499
4500 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4501 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4502 vc_conn.done;
4503
4504 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4505 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4506 vc_conn.done;
4507}
4508
Harald Weltea3f1df92018-02-25 12:49:55 +01004509
Harald Welte883340c2018-02-28 18:59:29 +01004510/***********************************************************************
4511 * PCU Socket related tests
4512 ***********************************************************************/
4513
Harald Welte07bd2d22019-05-25 11:03:30 +02004514/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004515friend 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 +01004516runs on test_CT {
4517 timer T := 3.0;
4518
4519 /* we don't expect any RTS.req before PDCH are active */
4520 T.start;
4521 alt {
4522 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004524 }
4525 [] PCU.receive { repeat; }
4526 [] T.timeout { }
4527 }
4528
4529 /* Send PDCH activate request for known PDCH timeslot */
4530 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4531
4532 /* we now expect RTS.req for this timeslot (only) */
4533 T.start;
4534 alt {
4535 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4536 setverdict(pass);
4537 }
4538 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4539 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004541 }
4542 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004544 }
4545 [] PCU.receive { repeat; }
4546 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004548 }
4549 [not exp_success] T.timeout {
4550 setverdict(pass);
4551 }
4552 }
4553}
4554
Harald Welte07bd2d22019-05-25 11:03:30 +02004555/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004556friend 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 +01004557runs on test_CT {
4558 timer T := 3.0;
4559
4560 /* Send PDCH activate request for known PDCH timeslot */
4561 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 +02004562 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4563 * when it will actually have been executed in the BTS */
4564 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004565 PCU.clear;
4566 /* we now expect no RTS.req for this timeslot */
4567 T.start;
4568 alt {
4569 [] 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 +02004570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004571 }
4572 [] PCU.receive { repeat; }
4573 [] T.timeout {
4574 setverdict(pass);
4575 }
4576 }
4577}
4578
Harald Weltead033dc2019-05-25 17:28:16 +02004579friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004580 f_init();
4581 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4582}
4583
Harald Welte883340c2018-02-28 18:59:29 +01004584/* PDCH activation via PCU socket; check for presence of RTS.req */
4585testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004586 f_init_pcu_test();
4587
Harald Welte883340c2018-02-28 18:59:29 +01004588 f_TC_pcu_act_req(0, 0, 7, true);
4589}
4590
4591/* PDCH activation via PCU socket on non-PDCU timeslot */
4592testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004593 f_init_pcu_test();
4594
Harald Welte883340c2018-02-28 18:59:29 +01004595 f_TC_pcu_act_req(0, 0, 1, false);
4596}
4597
4598/* PDCH activation via PCU socket on wrong BTS */
4599testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004600 f_init_pcu_test();
4601
Harald Welte883340c2018-02-28 18:59:29 +01004602 f_TC_pcu_act_req(23, 0, 7, false);
4603}
4604
4605/* PDCH activation via PCU socket on wrong TRX */
4606testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004607 f_init_pcu_test();
4608
Harald Welte883340c2018-02-28 18:59:29 +01004609 f_TC_pcu_act_req(0, 23, 7, false);
4610}
4611
4612/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4613testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004614 f_init_pcu_test();
4615
Harald Welte883340c2018-02-28 18:59:29 +01004616 /* Activate PDCH */
4617 f_TC_pcu_act_req(0, 0, 7, true);
4618 f_sleep(1.0);
4619 /* and De-Activate again */
4620 f_TC_pcu_deact_req(0, 0, 7);
4621}
4622
4623/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4624testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004625 f_init_pcu_test();
4626
Harald Welte883340c2018-02-28 18:59:29 +01004627 f_TC_pcu_deact_req(0, 0, 1);
4628}
4629
4630/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4631testcase TC_pcu_ver_si13() runs on test_CT {
4632 const octetstring si13 := '00010203040506070909'O;
4633 var PCUIF_send_data sd;
4634 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004635 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004636
4637 /* Set SI13 via RSL */
4638 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004639
Harald Welte883340c2018-02-28 18:59:29 +01004640 T.start;
4641 alt {
4642 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4643 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4644 setverdict(pass);
4645 } else {
4646 repeat;
4647 }
4648 }
4649 [] PCU.receive { repeat; }
4650 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004652 }
4653 }
4654}
4655
4656private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4657
4658/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004659friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004660 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4661runs on test_CT
4662{
4663 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4664 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4665}
4666
4667/* 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 +02004668friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4669 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004670runs on test_CT
4671{
4672 var PCUIF_send_data sd;
4673
4674 timer T := 3.0;
4675 T.start;
4676 alt {
4677 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4678 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4679 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4680 sd.data.u.rts_req.fn, sapi, data);
4681 }
4682 [] PCU.receive { repeat; }
4683 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004685 }
4686 }
4687}
4688
4689/* Send DATA.req on invalid BTS */
4690testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004691 var TfiUsfArr tua := f_TfiUsfArrInit();
4692 var octetstring data := '0000'O & f_rnd_octstring(21);
4693
4694 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004695
Harald Welte883340c2018-02-28 18:59:29 +01004696 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004697 f_TfiUsfArrSet(tua, 7, 0);
4698 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4699 f_sleep(1.0);
4700
4701 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004702}
4703
4704/* Send DATA.req on invalid TRX */
4705testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004706 var TfiUsfArr tua := f_TfiUsfArrInit();
4707 var octetstring data := '0000'O & f_rnd_octstring(21);
4708
4709 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004710
Harald Welte883340c2018-02-28 18:59:29 +01004711 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004712 f_TfiUsfArrSet(tua, 7, 0);
4713 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4714 f_sleep(1.0);
4715
4716 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004717}
4718
4719/* Send DATA.req on invalid timeslot */
4720testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004721 var TfiUsfArr tua := f_TfiUsfArrInit();
4722 var octetstring data := '0000'O & f_rnd_octstring(21);
4723
4724 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004725
Harald Welte883340c2018-02-28 18:59:29 +01004726 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004727 f_TfiUsfArrSet(tua, 7, 0);
4728 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4729 f_sleep(1.0);
4730
4731 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004732}
4733
4734/* Send DATA.req on timeslot that hasn't been activated */
4735testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004736 var TfiUsfArr tua := f_TfiUsfArrInit();
4737 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004738
Harald Welte7162a612019-05-26 12:56:09 +02004739 f_virtphy_common();
4740
4741 f_TfiUsfArrSet(tua, 7, 0);
4742 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4743 f_sleep(1.0);
4744
4745 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004746}
4747
Harald Weltead033dc2019-05-25 17:28:16 +02004748private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004749 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4750 boolean wait_rts := true)
4751runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004752 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004753 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004754
4755 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004756 if (wait_rts) {
4757 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4758 } else {
4759 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4760 }
Harald Weltead033dc2019-05-25 17:28:16 +02004761
4762 T.start;
4763 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004764 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004765 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4766 setverdict(pass);
4767 }
Harald Welte7162a612019-05-26 12:56:09 +02004768 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4769 setverdict(fail, "Received unexpected ", rx_dl);
4770 }
Harald Weltead033dc2019-05-25 17:28:16 +02004771 [] L1CTL.receive {
4772 repeat;
4773 }
Harald Welte7162a612019-05-26 12:56:09 +02004774 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004775 setverdict(fail, "Timeout waiting for ", data);
4776 }
Harald Welte7162a612019-05-26 12:56:09 +02004777 [not expect_data] T.timeout {
4778 setverdict(pass);
4779 }
Harald Weltead033dc2019-05-25 17:28:16 +02004780 }
4781}
4782
4783private function f_disable_dynamic_ts() runs on test_CT
4784{
4785 f_init_vty_bsc();
4786 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4787 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4788 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4789 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004790 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004791}
4792
4793private function f_virtphy_common() runs on test_CT {
4794 f_disable_dynamic_ts();
4795 f_init_l1ctl();
4796 f_l1_tune(L1CTL);
4797}
4798
4799testcase TC_pcu_data_req_pdtch() runs on test_CT {
4800 var TfiUsfArr tua := f_TfiUsfArrInit();
4801 var octetstring data := '0000'O & f_rnd_octstring(21);
4802
4803 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004804
Harald Welte883340c2018-02-28 18:59:29 +01004805 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004806 f_TfiUsfArrSet(tua, 7, 0);
4807 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4808 f_sleep(1.0);
4809
4810 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004811}
4812
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004813/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004814testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004815 var TfiUsfArr tua := f_TfiUsfArrInit();
4816 var octetstring data := '0000'O & f_rnd_octstring(21);
4817
4818 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004819
Harald Welte883340c2018-02-28 18:59:29 +01004820 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004821 f_TfiUsfArrSet(tua, 7, 0);
4822 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4823 f_sleep(1.0);
4824
4825 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004826}
4827
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004828private function f_TC_pcu_ptcch_ul(uint16_t ra)
4829runs on test_CT {
4830 var template PCUIF_Message pcu_rach_ind;
4831 var PCUIF_send_data sd;
4832 var GsmFrameNumber fn;
4833 timer T;
4834
4835 /* Send an Access Burst on PTCCH/U over the Um-interface */
4836 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4837 chan_nr := ts_RslChanNr_PDCH(7),
4838 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4839
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004840 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4841 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004842
4843 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4844 T.start(52.0 * 4.615 / 1000.0);
4845 alt {
4846 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4847 log("Rx an Access Burst on the PCU interface: ", sd.data);
4848 setverdict(pass);
4849 T.stop;
4850 }
4851 [] PCU.receive { repeat; }
4852 [] T.timeout {
4853 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4854 /* Keep going, that's not the end of the world */
4855 }
4856 }
4857}
4858
4859testcase TC_pcu_ptcch() runs on test_CT {
4860 var L1ctlDlMessage dl;
4861 var octetstring data;
4862 timer T;
4863
4864 f_init_pcu_test();
4865 f_init_l1ctl();
4866 f_l1_tune(L1CTL);
4867
4868 /* Activate PDCH channel on TS7 */
4869 f_TC_pcu_act_req(0, 0, 7, true);
4870
4871 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004872 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004873 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004874 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004875 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004876
4877 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4878 for (var integer i := 0; i < 16; i := i + 1) {
4879 log("Sending an Access Burst towards the L1CTL interface");
4880 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4881 }
4882
4883 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4884 data := f_rnd_octstring(23);
4885
4886 /* Verify PTCCH/D: send a random data block, make sure it's received */
4887 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4888 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4889
4890 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4891 * let's give it more time in case if we miss the beginning. */
4892 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4893 alt {
4894 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4895 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4896 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4897 frame := data)) -> value dl {
4898 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4899 setverdict(pass);
4900 T.stop;
4901 }
4902 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4903 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4904 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4905 l2_data := data)) -> value dl {
4906 log("Rx PTCCH/D data block on L1CTL: ", dl);
4907 setverdict(pass);
4908 T.stop;
4909 }
4910 [] L1CTL.receive { repeat; }
4911 [] T.timeout {
4912 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4913 }
4914 }
4915}
4916
Harald Welte883340c2018-02-28 18:59:29 +01004917/* Send AGCH from PCU; check it appears on Um side */
4918testcase TC_pcu_data_req_agch() runs on test_CT {
4919 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004920 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004921 f_init_l1ctl();
4922 f_l1_tune(L1CTL);
4923
4924 f_TC_pcu_act_req(0, 0, 7, true);
4925 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4926
4927 T.start;
4928 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004929 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004930 setverdict(pass);
4931 }
4932 [] L1CTL.receive { repeat; }
4933 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004935 }
4936 }
4937}
4938
Harald Welte928622b2019-05-26 13:22:59 +02004939/* Send AGCH from PCU; check it appears on Um side */
4940testcase TC_pcu_data_req_pch() runs on test_CT {
4941 timer T := 3.0;
4942 f_init_pcu_test();
4943 f_init_l1ctl();
4944 f_l1_tune(L1CTL);
4945
4946 f_TC_pcu_act_req(0, 0, 7, true);
4947 /* three characters prefix: last 3 digits of IMSI as ASCII */
4948 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4949
4950 T.start;
4951 alt {
4952 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4953 setverdict(pass);
4954 }
4955 [] L1CTL.receive { repeat; }
4956 [] T.timeout {
4957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4958 }
4959 }
4960}
4961
Harald Welte883340c2018-02-28 18:59:29 +01004962/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4963testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4964 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004965 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004966 f_init_l1ctl();
4967 f_l1_tune(L1CTL);
4968
4969 /* append 3 last imsi digits so BTS can compute pagng group */
4970 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4971
4972 timer T := 0.5;
4973 T.start;
4974 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004975 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004976 /* TODO: verify paging group */
4977 setverdict(pass);
4978 }
4979 [] L1CTL.receive { repeat; }
4980 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004982 }
4983 }
4984}
4985
4986/* Send RACH from Um side, expect it to show up on PCU socket */
4987testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004988 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004989 f_init_l1ctl();
4990 f_l1_tune(L1CTL);
4991
4992 var GsmFrameNumber fn_last := 0;
4993 for (var integer i := 0; i < 1000; i := i+1) {
4994 var OCT1 ra := f_rnd_ra_ps();
4995 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4996 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004998 }
4999 fn_last := fn;
5000
5001 timer T := 2.0;
5002 T.start;
5003 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005004 [] 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 +01005005 T.stop;
5006 }
5007 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005009 }
5010 [] PCU.receive { repeat; }
5011 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005013 }
5014 }
5015 }
5016 setverdict(pass);
5017}
5018
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005019/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5020 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5021testcase TC_pcu_ext_rach_content() runs on test_CT {
5022 var template PCUIF_Message pcu_rach_ind;
5023 var GsmFrameNumber fn_last := 0;
5024 var L1ctlRachSynchSeq synch_seq;
5025 var PCUIF_BurstType pcu_bt;
5026 var GsmFrameNumber fn;
5027 var BIT11 ra11;
5028
5029 f_init_pcu_test();
5030 f_init_l1ctl();
5031 f_l1_tune(L1CTL);
5032
5033 for (var integer i := 0; i < 1000; i := i+1) {
5034 /* We need to test both TS1 & TS2 */
5035 if (i rem 2 == 0) {
5036 synch_seq := RACH_SYNCH_SEQ_TS1;
5037 pcu_bt := BURST_TYPE_1;
5038 } else {
5039 synch_seq := RACH_SYNCH_SEQ_TS2;
5040 pcu_bt := BURST_TYPE_2;
5041 }
5042
5043 ra11 := f_rnd_ra11_ps();
5044 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5045 if (fn == fn_last) {
5046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5047 "Two RACH in same FN?!?");
5048 }
5049 fn_last := fn;
5050
5051 /* Compose the expected message */
5052 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005053 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005054 ra := bit2int(ra11),
5055 is_11bit := 1,
5056 burst_type := pcu_bt,
5057 fn := fn);
5058
5059 timer T := 2.0;
5060 T.start;
5061 alt {
5062 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5063 T.stop;
5064 }
5065 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5067 }
5068 [] PCU.receive { repeat; }
5069 [] T.timeout {
5070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5071 }
5072 }
5073 }
5074 setverdict(pass);
5075}
5076
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005077private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5078runs on test_CT {
5079 var template PCUIF_send_data sdt;
5080 var PCUIF_send_data sd;
5081 var int16_t lqual_cb;
5082 timer T := 1.0;
5083
5084 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5085 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5086
5087 /* Send a random PDTCH frame over Um */
5088 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5089 '0000'O & f_rnd_octstring(21)));
5090
5091 T.start;
5092 alt {
5093 /* If expected link quality is above the threshold */
5094 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5095 lqual_cb := sd.data.u.data_ind.lqual_cb;
5096 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5097
5098 /* Make sure the actual link quality matches the expected value */
5099 if (not match(lqual_cb, lqual_cb_exp)) {
5100 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5101 "expected value ", lqual_cb_exp));
5102 } else {
5103 setverdict(pass);
5104 }
5105 }
5106 /* If expected link quality is below the threshold */
5107 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5109 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5110 }
5111 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5112 [] PCU.receive { repeat; }
5113 [lqual_cb_exp < thresh] T.timeout {
5114 log("Rx nothing, as expected");
5115 setverdict(pass);
5116 }
5117 [lqual_cb_exp >= thresh] T.timeout {
5118 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5119 "Timeout waiting for PCUIF_DATA.ind");
5120 }
5121 }
5122}
5123
5124/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5125testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5126 f_init_pcu_test();
5127 PCU.clear;
5128
5129 f_init_l1ctl();
5130 f_l1_tune(L1CTL);
5131
5132 /* Activate a PDCH channel on TS7 */
5133 f_TC_pcu_act_req(0, 0, 7, true);
5134
5135 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005136 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005137 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005138 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005139 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005140
5141 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5142 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5143 var TrxcMessage ret;
5144
5145 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5146 valueof(ts_TRXC_FAKE_CI(i)));
5147
5148 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5149 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5150 }
5151}
5152
Harald Welte883340c2018-02-28 18:59:29 +01005153/* Send PAGING via RSL, expect it to shw up on PCU socket */
5154testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005155 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005156
5157 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005158 var MobileIdentityLV mi_lv;
5159 var octetstring mi_lv_enc;
5160 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005161 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005162
Harald Welte883340c2018-02-28 18:59:29 +01005163 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005164 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005165 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005166 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005167 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005168
5169 /* Fancy encoding for PCUIF */
5170 mi_lv := valueof(ts_MI_LV(mi));
5171 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5172 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005173
5174 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005175 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005176 T.start;
5177 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005178 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005179 }
5180 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005182 }
5183 [] PCU.receive { repeat; }
5184 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005186 }
5187 }
5188 }
5189 setverdict(pass);
5190}
5191
Harald Welted66c9b82019-05-25 09:03:15 +02005192/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5193testcase TC_pcu_time_ind() runs on test_CT {
5194 var PCUIF_send_data pcu_sd;
5195 var integer num_time_ind := 0;
5196 var integer first_fn, last_fn;
5197 var float test_duration := 5.0;
5198 timer T;
5199
5200 f_init_pcu_test();
5201 f_TC_pcu_act_req(0, 0, 7, true);
5202
5203 PCU.clear;
5204 T.start(test_duration);
5205 alt {
5206 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5207 num_time_ind := num_time_ind + 1;
5208 if (not isbound(first_fn)) {
5209 first_fn := pcu_sd.data.u.time_ind.fn;
5210 }
5211 last_fn := pcu_sd.data.u.time_ind.fn;
5212 repeat;
5213 }
5214 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5215 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5216 repeat;
5217 }
5218 [] PCU.receive {
5219 repeat;
5220 }
5221 [] T.timeout {}
5222 }
5223 var integer fn_expired := last_fn - first_fn;
5224 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5225
5226 /* verify the number of frames expired matches our expectation */
5227 const float c_GSM_FN_DURATION_MS := 4.61538;
5228 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005229 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005230 if (not match(fn_expired, t_fn_expected)) {
5231 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5232 }
5233
5234 /* There are three TIME.ind in every fn MOD 13 */
5235 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5236 /* Add some tolerance */
5237 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5238 if (not match(num_time_ind, t_time_ind_exp)) {
5239 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5240 }
5241
5242 setverdict(pass);
5243}
5244
Harald Welte4832c862019-05-25 14:57:18 +02005245/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5246testcase TC_pcu_rts_req() runs on test_CT {
5247 var PCUIF_send_data pcu_sd;
5248 var integer first_fn, last_fn;
5249 var integer num_rts_pdtch := 0;
5250 var integer num_rts_ptcch := 0;
5251 var float test_duration := 5.0;
5252 timer T;
5253
5254 f_init_pcu_test();
5255 f_TC_pcu_act_req(0, 0, 7, true);
5256
5257 PCU.clear;
5258 T.start(test_duration);
5259 alt {
5260 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5261 -> value pcu_sd {
5262 num_rts_pdtch := num_rts_pdtch + 1;
5263 if (not isbound(first_fn)) {
5264 first_fn := pcu_sd.data.u.rts_req.fn;
5265 }
5266 last_fn := pcu_sd.data.u.rts_req.fn;
5267 repeat;
5268 }
5269 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5270 -> value pcu_sd {
5271 num_rts_ptcch := num_rts_ptcch + 1;
5272 if (not isbound(first_fn)) {
5273 first_fn := pcu_sd.data.u.rts_req.fn;
5274 }
5275 last_fn := pcu_sd.data.u.rts_req.fn;
5276 repeat;
5277 }
5278 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5279 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5280 repeat;
5281 }
5282 [] PCU.receive {
5283 repeat;
5284 }
5285 [] T.timeout {}
5286 }
5287 var integer fn_expired := last_fn - first_fn;
5288 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5289 ", num_rts_ptcch=", num_rts_ptcch);
5290
5291 /* verify the number of frames expired matches our expectation */
5292 const float c_GSM_FN_DURATION_MS := 4.61538;
5293 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005294 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005295 if (not match(fn_expired, t_fn_expected)) {
5296 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5297 }
5298
5299 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5300 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5301 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5302 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5303 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5304 t_ptcch_exp);
5305 }
5306
5307 /* We have 12 PDTCH blocks every 52-multiframe */
5308 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5309 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5310 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5311 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5312 t_pdtch_exp);
5313 }
5314
5315 setverdict(pass);
5316}
5317
Harald Welte07bd2d22019-05-25 11:03:30 +02005318/* test for generating Abis side OML ALERT from the PCU */
5319testcase TC_pcu_oml_alert() runs on test_CT {
5320 var PCUIF_send_data pcu_sd;
5321 var integer num_time_ind := 0;
5322 var integer first_fn, last_fn;
5323 var float test_duration := 5.0;
5324 timer T;
5325
5326 f_init_pcu_test();
5327 f_TC_pcu_act_req(0, 0, 7, true);
5328
5329 /* re-connect CTRL port from BTS to BSC */
5330 f_ipa_ctrl_stop();
5331 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5332
5333 /* Send that OML Alert */
5334 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5335
5336 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5337 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5338 setverdict(pass);
5339}
5340
Harald Welteeaa9a862019-05-26 23:01:08 +02005341/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5342private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5343 var PCUIF_Message first_info;
5344 var integer pcu_conn_id := -1;
5345 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5346 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5347 var OCT4 tlli := '01020304'O;
5348 var OCT1 cause := '23'O;
5349 timer T := 5.0;
5350
5351 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5352
5353 f_l1_tune(L1CTL);
5354 RSL.clear;
5355
5356 f_est_dchan();
5357 L1CTL.clear;
5358
5359 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5360
5361 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5362 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5363 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5364
5365 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5366 T.start;
5367 alt {
5368 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5369 setverdict(pass);
5370 }
5371 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5372 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5373 }
5374 [] PCU.receive {
5375 repeat;
5376 }
5377 [] T.timeout {
5378 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5379 }
5380 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005381
5382 /* release the channel */
5383 f_rsl_chan_deact();
5384 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5385 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005386}
5387testcase TC_pcu_rr_suspend() runs on test_CT {
5388 var ConnHdlrPars pars;
5389 var ConnHdlr vc_conn;
5390
5391 f_init();
5392
5393 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5394 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5395 vc_conn.done;
5396}
Harald Welte07bd2d22019-05-25 11:03:30 +02005397
Harald Weltea2e0e942019-05-27 18:12:53 +02005398/* Ensure that PCUIF socket can accept only a single connection */
5399testcase TC_pcu_socket_connect_multi() runs on test_CT {
5400 timer T := 5.0;
5401
5402 /* this (among other things) establishes the first connection to the PCUIF socket */
5403 f_init();
5404
5405 /* try to establish a second connection, expect it to fail */
5406 PCU.send(UD_connect:{mp_pcu_socket, -1});
5407 T.start;
5408 alt {
5409 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5410 setverdict(pass);
5411 }
5412 [] PCU.receive(UD_connect_result:?) {
5413 setverdict(fail, "Unexpected unix domain connect result");
5414 }
5415 [] T.timeout {
5416 setverdict(pass);
5417 }
5418 }
5419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5420}
5421
Harald Weltec8effb72019-05-27 18:23:04 +02005422/* Ensure that PCUIF socket can disconnect + reconnect */
5423testcase TC_pcu_socket_reconnect() runs on test_CT {
5424 /* this (among other things) establishes the first connection to the PCUIF socket */
5425 f_init();
5426
5427 f_sleep(1.0);
5428
5429 f_pcuif_close(PCU, g_pcu_conn_id);
5430 g_pcu_conn_id := -1;
5431
5432 f_sleep(1.0);
5433
5434 /* re-connect */
5435 PCU.clear;
5436 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5437 setverdict(pass);
5438
5439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5440}
5441
Harald Weltebe030482019-05-27 22:29:35 +02005442/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005443private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5444runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005445 var L1ctlDlMessage l1_dl;
5446 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005447 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005448 timer T := 5.0;
5449 T.start;
5450 alt {
5451 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005452 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5453 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005454 repeat;
5455 }
5456 }
5457 [] pt.receive {
5458 repeat;
5459 }
5460 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5462 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005463 }
5464 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005465 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005466}
5467
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005468/* Check if GPRS Indicator is present in RR System Information of a given type */
5469private function f_si_has_gprs_indicator(RrMessageType si_type)
5470runs on test_CT return boolean {
5471 var SystemInformation si := f_get_si(L1CTL, si_type);
5472
5473 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005474 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005475 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005476 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005477 }
5478
5479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5480 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005481}
5482
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005483/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5484private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5485runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005486 /* don't call f_init() as this would connect PCU socket */
5487 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005488
5489 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005490 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005491 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005492
5493 f_init_l1ctl();
5494 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005495 f_sleep(2.0);
5496 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005497
5498 if (f_si_has_gprs_indicator(si_type)) {
5499 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005500 } else {
5501 setverdict(pass);
5502 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005503
Harald Weltebe030482019-05-27 22:29:35 +02005504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5505}
5506
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005507testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5508 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5509}
Harald Weltebe030482019-05-27 22:29:35 +02005510
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005511testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5512 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5513}
5514
5515/* Ensure that GPRS capability is advertised after PCU socket connect */
5516private function f_TC_pcu_socket_connect(RrMessageType si_type)
5517runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005518 /* this (among other things) establishes the first connection to the PCUIF socket */
5519 f_init();
5520 f_init_l1ctl();
5521 f_l1_tune(L1CTL);
5522
5523 f_sleep(2.0);
5524 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005525
5526 if (not f_si_has_gprs_indicator(si_type)) {
5527 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005528 } else {
5529 setverdict(pass);
5530 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005531
Harald Weltebe030482019-05-27 22:29:35 +02005532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5533}
5534
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005535testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5536 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5537}
Harald Weltebe030482019-05-27 22:29:35 +02005538
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005539testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5540 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5541}
5542
5543/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5544private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5545runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005546 /* this (among other things) establishes the first connection to the PCUIF socket */
5547 f_init();
5548 f_init_l1ctl();
5549 f_l1_tune(L1CTL);
5550
5551 f_pcuif_close(PCU, g_pcu_conn_id);
5552 g_pcu_conn_id := -1;
5553
5554 f_sleep(1.0);
5555
5556 /* re-connect */
5557 PCU.clear;
5558 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5559
5560 f_sleep(2.0);
5561 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005562
5563 if (f_si_has_gprs_indicator(si_type)) {
5564 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005565 } else {
5566 setverdict(pass);
5567 }
5568
5569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5570}
5571
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005572testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5573 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5574}
5575
5576testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5577 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5578}
5579
Oliver Smithf5239c72019-08-28 10:01:25 +02005580/* 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) */
5581testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5582 var SystemInformation si3 := valueof(ts_SI3_default);
5583
5584 f_init();
5585
Harald Welte76220222020-10-11 20:32:44 +02005586 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5587 * information */
5588 timer T := 2.0;
5589 T.start;
5590 alt {
5591 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5592 [] T.timeout {}
5593 }
5594
Oliver Smithf5239c72019-08-28 10:01:25 +02005595 /* Verify cell_id */
5596 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5597 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5598 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005599 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5600 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5601 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005602 }
5603
5604 /* Verify LAC */
5605 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5606 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5607 if (lac_si3 != lac_pcu) {
5608 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5609 }
5610
5611 setverdict(pass);
5612}
Harald Welted66c9b82019-05-25 09:03:15 +02005613
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005614/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5615testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5616 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005617 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005618
5619 f_init();
5620
5621 info_ind := g_pcu_last_info.u.info_ind;
5622
5623 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5624 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5625 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5626 /* Skip inactive timeslots */
5627 continue;
5628 }
5629
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005630 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005631 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005632 else
5633 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005634
5635 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005636 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005637 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005638 hsn := fhp.maio_hsn.hsn,
5639 maio := fhp.maio_hsn.maio,
5640 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005641 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005642 } else {
5643 tr_ts := tr_PCUIF_InfoTrxTsH0;
5644 }
5645
5646 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5647 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5648 if (not match(ts, tr_ts)) {
5649 setverdict(fail, "Hopping parameters do not match: ",
5650 "received ", ts, " vs expected ", tr_ts);
5651 } else {
5652 setverdict(pass);
5653 }
5654 }
5655 }
5656}
5657
Alexander Couzens5283f552020-07-28 15:39:04 +02005658/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5659testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5660 f_init_vty_bsc();
5661 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5662 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5663
5664 f_init();
5665
5666 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5667 if (not ischosen(remote_addr.v10)) {
5668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5669 log2str("Unexpected remote_addr: ", remote_addr));
5670 }
5671
5672 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5673 setverdict(fail, "Received address family is not IPv4");
5674 }
5675
5676 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5677 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5678 }
5679
5680 setverdict(pass);
5681}
5682
5683/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5684testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5685 f_init_vty_bsc();
5686 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5687
5688 f_init();
5689
5690 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5691 if (not ischosen(remote_addr.v10)) {
5692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5693 log2str("Unexpected remote_addr: ", remote_addr));
5694 }
5695
5696 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5697 setverdict(fail, "Received address family is not IPv6");
5698 }
5699
5700 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5701 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5702 }
5703
5704 setverdict(pass);
5705}
5706
Harald Welte3d04ae62018-04-04 20:29:05 +02005707/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005708 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005709 ***********************************************************************/
5710
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005711private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5712 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005713runs on ConnHdlr {
5714 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005715
5716 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005717 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005718 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5719 repeat;
5720 }
5721 }
5722}
5723
5724private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5725runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005726 /* Expect BTS to immediately acknowledge activation as PDCH */
5727 PCU.clear;
5728 f_rsl_chan_act(g_pars.chan_mode);
5729 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005730 timer T_wait := 2.0;
5731 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005732 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005733 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005734 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005735 [] T_wait.timeout {
5736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5737 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5738 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005739 }
5740 /* try to activate this PDCH from the PCU point of view */
5741 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5742 /* FIXME: is there a response? */
5743}
5744
5745private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5746runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005747 /* Send RSL CHAN REL (deactivate) */
5748 PCU.clear;
5749 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5750 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005751 timer T_wait := 2.0;
5752 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005753 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005754 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005755 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005756 [] T_wait.timeout {
5757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5758 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5759 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005760 }
5761 /* Emulate PCU asking BTS to deactivate PDCH */
5762 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5763 alt {
5764 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5765 setverdict(pass);
5766 }
5767 [] RSL.receive { repeat; }
5768 }
5769}
5770
5771/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005772private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005773 var PCUIF_Message first_info;
5774 var integer ts_nr := g_chan_nr.tn;
5775 var integer trx_nr := 0;
5776 var integer bts_nr := 0;
5777 var integer pcu_conn_id := -1;
5778
5779 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5780
5781 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5782 f_sleep(3.0);
5783 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5784 setverdict(pass);
5785}
5786testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5787 var ConnHdlrPars pars;
5788 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005789 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005790
5791 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5792 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5793 vc_conn.done;
5794}
5795
5796/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005797private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005798 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005799 var integer pcu_conn_id := -1;
5800
5801 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5802
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005803 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5804 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5805 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005806 setverdict(pass);
5807}
5808testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5809 var ConnHdlrPars pars;
5810 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005811 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005812
5813 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5814 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5815 vc_conn.done;
5816}
5817
5818/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005819private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005820 var PCUIF_Message first_info;
5821 var integer ts_nr := g_chan_nr.tn;
5822 var integer trx_nr := 0;
5823 var integer bts_nr := 0;
5824 var integer pcu_conn_id := -1;
5825
5826 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5827
5828 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005829 /* Send a second Chan Activ and expect it to be NACKed */
5830 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5831 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005832 setverdict(pass);
5833}
5834testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5835 var ConnHdlrPars pars;
5836 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005837 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005838
5839 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5840 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5841 vc_conn.done;
5842}
5843
5844/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005845private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005846 var PCUIF_Message first_info;
5847 var integer ts_nr := g_chan_nr.tn;
5848 var integer trx_nr := 0;
5849 var integer bts_nr := 0;
5850 var integer pcu_conn_id := -1;
5851 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5852
5853 /* register for the TCH/F channel number */
5854 f_rslem_register(0, chan_nr);
5855
5856 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5857
5858 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5859 "RSL CHAN ACT");
5860 setverdict(pass);
5861}
5862testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5863 var ConnHdlrPars pars;
5864 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005865 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005866
5867 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5868 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5869 vc_conn.done;
5870}
5871
5872/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005873private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005874 var PCUIF_Message first_info;
5875 var integer ts_nr := g_chan_nr.tn;
5876 var integer trx_nr := 0;
5877 var integer bts_nr := 0;
5878 var integer pcu_conn_id := -1;
5879 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5880 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5881
5882 /* register for the TCH/H channel numbers */
5883 f_rslem_register(0, chan_nr[0]);
5884 f_rslem_register(0, chan_nr[1]);
5885
5886 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5887
5888 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5889 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5890 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5891 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5892 setverdict(pass);
5893}
5894testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5895 var ConnHdlrPars pars;
5896 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005897 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005898
5899 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5900 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5901 vc_conn.done;
5902}
5903
Harald Welte9bbbfb52018-04-05 09:33:19 +02005904/***********************************************************************
5905 * IPA Style Dynamic Timeslot Support
5906 ***********************************************************************/
5907
5908private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5909runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005910 /* Expect BTS to immediately acknowledge activation as PDCH */
5911 PCU.clear;
5912 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5913 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005914 timer T_wait := 2.0;
5915 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005916 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005917 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005918 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005919 [] T_wait.timeout {
5920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5921 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5922 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005923 }
5924 /* try to activate this PDCH from the PCU point of view */
5925 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5926 /* FIXME: is there a response? */
5927
5928 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5929}
5930
5931private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5932runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005933 /* Send RSL CHAN REL (deactivate) */
5934 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5935 PCU.clear;
5936 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005937 timer T_wait := 2.0;
5938 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005939 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005940 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005941 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005942 [] T_wait.timeout {
5943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5944 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5945 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005946 }
5947 /* Emulate PCU asking BTS to deactivate PDCH */
5948 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5949 alt {
5950 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5951 setverdict(pass);
5952 }
5953 [] RSL.receive { repeat; }
5954 }
5955}
5956
5957/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005958private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005959 var PCUIF_Message first_info;
5960 var integer ts_nr := g_chan_nr.tn;
5961 var integer trx_nr := 0;
5962 var integer bts_nr := 0;
5963 var integer pcu_conn_id := -1;
5964
5965 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5966
5967 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5968 f_sleep(3.0);
5969 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5970
5971 setverdict(pass);
5972
5973}
5974testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5975 var ConnHdlrPars pars;
5976 var ConnHdlr vc_conn;
5977 f_init();
5978
5979 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5980 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5981 vc_conn.done;
5982}
5983
5984/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005985private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005986 var PCUIF_Message first_info;
5987 var integer ts_nr := g_chan_nr.tn;
5988 var integer trx_nr := 0;
5989 var integer bts_nr := 0;
5990 var integer pcu_conn_id := -1;
5991
5992 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5993
5994 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5995 "RSL CHAN ACT");
5996 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5997 "RF CHAN REL", true);
5998 setverdict(pass);
5999}
6000testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6001 var ConnHdlrPars pars;
6002 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006003 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006004
6005 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6006 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6007 vc_conn.done;
6008}
6009
6010/* 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 +07006011private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006012 var PCUIF_Message first_info;
6013 var integer ts_nr := g_chan_nr.tn;
6014 var integer trx_nr := 0;
6015 var integer bts_nr := 0;
6016 var integer pcu_conn_id := -1;
6017
6018 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6019
6020 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6021 "RSL CHAN ACT");
6022
6023 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6024 alt {
6025 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6026 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006028 }
6029 [] RSL.receive { repeat; }
6030 }
6031
6032 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6033 "RF CHAN REL", true);
6034 setverdict(pass);
6035}
6036testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6037 var ConnHdlrPars pars;
6038 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006039 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006040
6041 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6042 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6043 vc_conn.done;
6044}
6045
6046/* 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 +07006047private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006048 var PCUIF_Message first_info;
6049 var integer ts_nr := g_chan_nr.tn;
6050 var integer trx_nr := 0;
6051 var integer bts_nr := 0;
6052 var integer pcu_conn_id := -1;
6053
6054 /* register for the TCH/F channel number */
6055 f_rslem_register(0, g_chan_nr);
6056
6057 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6058
6059 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6060
6061 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6062 "RSL CHAN ACT");
6063
6064 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6065
6066 setverdict(pass);
6067}
6068testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6069 var ConnHdlrPars pars;
6070 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006071 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006072
6073 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6074 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6075 vc_conn.done;
6076}
6077
6078
Harald Welte0472ab42018-03-12 15:02:26 +01006079/***********************************************************************
6080 * LAPDm / RLL related
6081 ***********************************************************************/
6082
6083private function f_tx_lapdm(template (value) LapdmFrame l,
6084 template (value) RslLinkId link_id) runs on ConnHdlr {
6085 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006086 var template (value) SacchL1Header l1h;
6087
6088 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006089 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006090 /* Compose dummy L1 header */
6091 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6092 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 +02006093 } else {
6094 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006095 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 +01006096 }
Harald Welte0472ab42018-03-12 15:02:26 +01006097}
6098
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006099private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006100 uint3_t sapi,
6101 RslLinkId link_id,
6102 octetstring l3,
6103 boolean exp
6104}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006105private type record of RllTestCase RllTestCases;
6106private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6107 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006108 sapi := sapi,
6109 link_id := id,
6110 l3 := l3,
6111 exp := exp
6112}
6113
6114/* execute the same callback function with a set of different parameters (tcs) on a
6115 * variety of logical channels */
6116private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6117 var ConnHdlrPars pars;
6118 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006119 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006120
6121 /* test on each of the channels we have */
6122 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6123 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6124
6125 /* test each of the test cases on the current channel */
6126 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6127 pars.spec.rll := tcs[j];
6128 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6129 vc_conn := f_start_handler(fn, pars);
6130 vc_conn.done;
6131 }
6132 }
6133
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006135}
6136
6137/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6138private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6139 var RllTestCase tc := g_pars.spec.rll;
6140 timer T := 3.0;
6141
6142 f_l1_tune(L1CTL);
6143 RSL.clear;
6144
6145 /* activate the logical channel */
6146 f_est_dchan();
6147 L1CTL.clear;
6148
6149 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6150 T.start;
6151 alt {
6152 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6153 if (tc.exp) {
6154 setverdict(pass);
6155 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006157 }
6158 }
6159 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6160 if (tc.exp) {
6161 setverdict(pass);
6162 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006164 }
6165 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006166 /* We also expect to receive the measurements */
6167 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006168 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006170 }
6171 [not tc.exp] T.timeout {
6172 setverdict(pass);
6173 }
6174 }
6175
6176 f_rsl_chan_deact();
6177 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6178 f_rslem_unregister(0, g_chan_nr);
6179}
6180testcase TC_rll_est_ind() runs on test_CT {
6181 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006182 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006183 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006184 /* normal SAPI0 establishment */
6185 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006186 /* SAPI 3 doesn't support contention resolution */
6187 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6188 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6189 /* normal SAPI3 establishment on main DCCH */
6190 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6191 /* normal SAPI3 establishment on SACCH */
6192 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6193 };
6194 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6195}
6196
6197/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6198private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6199 var RllTestCase tc := g_pars.spec.rll;
6200 var L1ctlDlMessage dl;
6201 timer T := 3.0;
6202
6203 f_l1_tune(L1CTL);
6204 RSL.clear;
6205
6206 /* activate the logical channel */
6207 f_est_dchan();
6208 L1CTL.clear;
6209
6210 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6211 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6212 T.start;
6213 alt {
6214 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6215 var LapdmFrame lapdm;
6216 var octetstring l2 := dl.payload.data_ind.payload;
6217 if (dl.dl_info.link_id.c == SACCH) {
6218 /* remove L1 header */
6219 l2 := substr(l2, 2, lengthof(l2)-2);
6220 }
6221 lapdm.ab := dec_LapdmFrameAB(l2);
6222 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6223 setverdict(pass);
6224 } else {
6225 repeat;
6226 }
6227 }
6228 [] L1CTL.receive { repeat; }
6229 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006231 }
6232 }
6233
6234 f_rsl_chan_deact();
6235 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6236 f_rslem_unregister(0, g_chan_nr);
6237}
6238testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6239 var RllTestCases tcs := {
6240 /* normal SAPI3 establishment on main DCCH */
6241 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6242 };
6243 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6244}
6245testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6246 var RllTestCases tcs := {
6247 /* normal SAPI3 establishment on SACCH */
6248 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6249 }
6250 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6251}
6252
6253/* altstep to receive a LAPDm frame matching the given template */
6254private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6255 var L1ctlDlMessage dl;
6256 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6257 var LapdmFrame lapdm;
6258 var octetstring l2 := dl.payload.data_ind.payload;
6259 if (dl.dl_info.link_id.c == SACCH) {
6260 /* remove L1 header */
6261 l2 := substr(l2, 2, lengthof(l2)-2);
6262 }
6263 if (ischosen(exp.ab)) {
6264 lapdm.ab := dec_LapdmFrameAB(l2);
6265 } else if (ischosen(exp.b4)) {
6266 lapdm.b4 := dec_LapdmFrameB4(l2);
6267 } else if (ischosen(exp.bbis)) {
6268 lapdm.bbis := dec_LapdmFrameBbis(l2);
6269 }
6270 log("Rx LAPDm ", lapdm);
6271 if (match(lapdm, exp)) {
6272 setverdict(pass);
6273 } else {
6274 repeat;
6275 }
6276 }
6277 [] L1CTL.receive { repeat; }
6278}
6279private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6280 timer T := t;
6281 T.start;
6282 alt {
6283 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006285 }
6286 [] as_l1_exp_lapdm(exp);
6287 }
6288}
6289
6290/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6291private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6292 /* send SABM from MS -> BTS */
6293 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6294 /* expect RLL EST IND on Abis */
6295 alt {
6296 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6297 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6298 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006300 }
6301 [] RSL.receive { repeat; }
6302 }
6303 /* expect UA from BTS -> MS */
6304 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6305}
6306
6307/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6308private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6309 var RllTestCase tc := g_pars.spec.rll;
6310
6311 f_l1_tune(L1CTL);
6312 RSL.clear;
6313
6314 /* activate the logical channel */
6315 f_est_dchan();
6316 L1CTL.clear;
6317
6318 /* first establish the link-layer */
6319 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6320
6321 /* then send the DISC */
6322 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6323 /* ... and expect the REL IND on the RSL side */
6324 alt {
6325 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6326 setverdict(pass);
6327 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006328 /* We also expect to receive the measurements */
6329 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006330 }
6331
6332 /* release the channel */
6333 f_rsl_chan_deact();
6334 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6335 f_rslem_unregister(0, g_chan_nr);
6336}
6337testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6338 var RllTestCases tcs := {
6339 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6340 };
6341 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6342}
6343
6344testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6345 var RllTestCases tcs := {
6346 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6347 };
6348 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6349}
6350testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6351 var RllTestCases tcs := {
6352 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6353 };
6354 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6355}
6356testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6357 var RllTestCases tcs := {
6358 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6359 };
6360 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6361}
6362
6363/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6364private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6365 var RllTestCase tc := g_pars.spec.rll;
6366 f_l1_tune(L1CTL);
6367 RSL.clear;
6368
6369 /* activate the logical channel */
6370 f_est_dchan();
6371 L1CTL.clear;
6372
6373 /* first establish the link-layer */
6374 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6375
6376 /* then send the REL REQ via RSL */
6377 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6378 /* ... and expect the DISC on the Um side */
6379 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006380 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006381 /* FIXME: send a UA in resposne to the DISC */
6382 }
6383 }
6384
6385 /* release the channel */
6386 f_rsl_chan_deact();
6387 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6388 f_rslem_unregister(0, g_chan_nr);
6389}
6390testcase TC_rll_rel_req() runs on test_CT {
6391 var RllTestCases tcs := {
6392 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6393 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6394 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6395 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6396 };
6397 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6398}
6399
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006400/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006401testcase TC_rll_data_req() runs on test_CT {
6402}
6403
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006404/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006405testcase TC_rll_data_ind() runs on test_CT {
6406}
6407
6408/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6409private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6410 var RllTestCase tc := g_pars.spec.rll;
6411
6412 f_l1_tune(L1CTL);
6413 RSL.clear;
6414
6415 f_est_dchan();
6416 L1CTL.clear;
6417
6418 /* Send UNITDATA REQ on RSL side */
6419 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6420 /* Expect it to arrive on the other side */
6421 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006422 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006423 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006424 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006425 }
6426
6427 /* release the channel */
6428 f_rsl_chan_deact();
6429 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6430 f_rslem_unregister(0, g_chan_nr);
6431}
6432testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6433 var octetstring l3 := f_rnd_octstring(15);
6434 var RllTestCases tcs := {
6435 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6436 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6437 };
6438 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6439}
6440testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6441 var octetstring l3 := f_rnd_octstring(19);
6442 var RllTestCases tcs := {
6443 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6444 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6445 };
6446 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6447}
6448
6449/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6450private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6451 var RllTestCase tc := g_pars.spec.rll;
6452
6453 f_l1_tune(L1CTL);
6454 RSL.clear;
6455
6456 f_est_dchan();
6457 L1CTL.clear;
6458
6459 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006460 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006461 /* Expdct RLL UNITDATA IND on RSL side */
6462 alt {
6463 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6464 setverdict(pass);
6465 }
6466 [] RSL.receive { repeat; }
6467 }
6468
6469 /* release the channel */
6470 f_rsl_chan_deact();
6471 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6472 f_rslem_unregister(0, g_chan_nr);
6473}
6474testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006475 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006476 var RllTestCases tcs := {
6477 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6478 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6479 };
6480 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6481}
6482testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6483 var octetstring l3 := f_rnd_octstring(18);
6484 var RllTestCases tcs := {
6485 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6486 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6487 };
6488 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6489}
6490
Harald Weltee613f962018-04-18 22:38:16 +02006491/***********************************************************************
6492 * Encryption Related
6493 ***********************************************************************/
6494
6495/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006496private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006497 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6498 if (link_id.c == SACCH) {
6499 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6500 } else {
6501 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6502 }
6503}
6504
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006505/* Expect (or not expect) other kinds of messages */
6506private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6507 [exp_any] RSL.receive { repeat; }
6508 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006510 }
6511}
6512
Harald Weltee613f962018-04-18 22:38:16 +02006513/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006514private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006515 RslLinkId link_id,
6516 octetstring l3,
6517 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006518 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006519) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006520 timer T := 3.0;
6521 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6522 T.start;
6523 /* Expect RLL UNITDATA IND on RSL side */
6524 alt {
6525 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6526 setverdict(pass);
6527 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006528 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006529 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006530 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006532 }
Harald Weltee613f962018-04-18 22:38:16 +02006533 }
6534}
6535
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006536/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6537private function f_data_mo(
6538 RslLinkId link_id,
6539 boolean p, uint3_t nr, uint3_t ns,
6540 octetstring l3,
6541 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006542 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006543) runs on ConnHdlr {
6544 timer T := 3.0;
6545 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6546 T.start;
6547 /* Expect RLL DATA IND on RSL side */
6548 alt {
6549 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6550 setverdict(pass);
6551 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006552 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006553 [] as_rsl_any_ind(exp_any);
6554 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006556 }
6557 }
6558}
6559
Harald Weltee613f962018-04-18 22:38:16 +02006560/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006561private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006562 f_l1_tune(L1CTL);
6563 f_est_dchan(true);
6564
6565 /* now we actually need to transmit some data both ways to check if the encryption works */
6566 var L1ctlDlMessage dl;
6567
Stefan Sperling603d98e2018-07-25 16:47:28 +02006568 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006569 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6570
6571 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6572 f_unitdata_mt(link_id, l3);
6573
6574 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6575 f_unitdata_mo(link_id, l3);
6576
6577 /* release the channel */
6578 f_rsl_chan_deact();
6579 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6580 f_rslem_unregister(0, g_chan_nr);
6581}
6582testcase TC_chan_act_a51() runs on test_CT {
6583 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6584 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6585 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6586}
6587testcase TC_chan_act_a52() runs on test_CT {
6588 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6589 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6590 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6591}
6592testcase TC_chan_act_a53() runs on test_CT {
6593 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6594 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6595 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6596}
6597
Eric Wildf1827a72019-05-28 17:37:35 +02006598/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6599 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 +07006600private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006601 f_l1_tune(L1CTL);
6602 f_est_dchan(true);
6603
6604 /* now we actually need to transmit some data both ways to check if the encryption works */
6605 var L1ctlDlMessage dl;
6606
6607 var octetstring l3 := f_rnd_octstring(20);
6608 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6609
6610 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6611 f_unitdata_mt(link_id, l3);
6612
6613 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6614 f_unitdata_mo(link_id, l3);
6615
6616 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006617 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006618
6619 /* modify key to break proper encryption */
6620 g_pars.encr.key := f_rnd_octstring(8);
6621 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6622 rsl.ies := rsl.ies & { ei };
6623 RSL.send(rsl);
6624
6625 timer T0 := 1.0;
6626 T0.start;
6627 /* Expect RSL MODIFY ACK */
6628 alt {
6629 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6630 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6632 }
6633 [] T0.timeout {
6634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6635 }
6636 }
6637
6638 var octetstring l3msg := f_rnd_octstring(15);
6639 timer T1 := 3.0;
6640 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6641 due to broken encryption */
6642 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6643 T1.start;
6644 alt {
6645 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6647 }
6648 [] T1.timeout {
6649 setverdict(pass);
6650 }
6651 }
6652
6653 /* release the channel */
6654 f_rsl_chan_deact();
6655 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6656 f_rslem_unregister(0, g_chan_nr);
6657}
6658testcase TC_rsl_modify_encr() runs on test_CT {
6659 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6660 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6661 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6662}
Harald Weltee613f962018-04-18 22:38:16 +02006663
6664/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006665private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006666 /* L3 payload doesn't matter, as it is passed transparently */
6667 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6668 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6669 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6670
6671 f_l1_tune(L1CTL);
6672
6673 /* first establish a dedicated channel in the clear */
6674 f_est_dchan(false);
6675
6676 /* Establish ABM */
6677 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6678
6679 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6680 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6681 /* expect the L3 to arrive still unencrypted on the MS side */
6682 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6683
6684 /* configure L1 to apply ciphering */
6685 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6686 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6687
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006688 /* send first ciphered I-frame in response and expect it on RSL */
6689 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006690
6691 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6692 * and hence enable encryption also on the downlink */
6693
6694 /* expect bi-directional communication work in encrypted mode */
6695 f_unitdata_mo(link_id, f_rnd_octstring(15));
6696 f_unitdata_mt(link_id, f_rnd_octstring(15));
6697
6698 /* release the channel */
6699 f_rsl_chan_deact();
6700 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6701 f_rslem_unregister(0, g_chan_nr);
6702}
6703testcase TC_encr_cmd_a51() runs on test_CT {
6704 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6705 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6706 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6707}
6708testcase TC_encr_cmd_a52() runs on test_CT {
6709 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6710 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6711 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6712}
6713testcase TC_encr_cmd_a53() runs on test_CT {
6714 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6715 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6716 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6717}
6718
6719private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6720 var LapdmFrame lf;
6721 var octetstring reenc;
6722
6723 /* decode the LAPDm frame */
6724 if (ischosen(exp_match.ab)) {
6725 lf.ab := dec_LapdmFrameAB(enc);
6726 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006728 }
6729
6730 /* check if decoder result matches expectation */
6731 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006733 } else {
6734 log(name, ": matched");
6735 setverdict(pass);
6736 }
6737
6738 /* test if re-encoded frame equals original input */
6739 reenc := enc_LapdmFrame(lf);
6740 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006742 } else {
6743 setverdict(pass);
6744 }
6745}
6746
6747testcase TC_lapdm_selftest() runs on test_CT {
6748 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6749 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6750 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6751 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6752 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6753 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6754 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6755}
6756
Stefan Sperling4880be42018-08-07 18:12:59 +02006757/***********************************************************************
6758 * DTX Related (see GSM 05.08, section 8.3)
6759 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006760private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006761 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006762 var GsmFrameNumber first_fn;
6763 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006764 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006765 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006766 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6767 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006768 const integer frame_dtx_tchf_mod := 104;
6769 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6770 * which operates in terms of blocks rather than frames. */
6771 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6772 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006773 timer T := 5.0;
6774
6775 f_l1_tune(L1CTL);
6776 RSL.clear;
6777 L1CTL.clear;
6778
6779 /* activate TCHF signalling channel */
6780 f_est_dchan(false);
6781
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006782 /* A template for matching dummy LAPDm func=UA frames */
6783 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6784 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6785 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6786
Stefan Sperling4880be42018-08-07 18:12:59 +02006787 T.start;
6788 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006789 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006790 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006791
6792 if (is_first_frame) {
6793 is_first_frame := false;
6794 first_fn := dl.dl_info.frame_nr;
6795 }
6796
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006797 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006798 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006799 T.stop;
6800 f_rsl_chan_deact();
6801 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006802
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006803 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6804 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006805
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006806 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006807 setverdict(fail, "Not enough fill frames received: ",
6808 nfill_frames, " out of ", expected_fill_frames);
6809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006810 } else {
6811 setverdict(pass);
6812 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006813 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006814 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6815 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6816 * we should only see the subset of frames numbers which correspond to a block boundary.
6817 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6818 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6819 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006820 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006821 repeat;
6822 }
6823 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006824 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6825 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6826 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006827 f_rsl_chan_deact();
6828 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006829 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006830 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006831 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006832 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006833 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006834
6835 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006836 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6837 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006838 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6839 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6840 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006841 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6842 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006843 case else {
6844 /* This shall not happen, just to be sure */
6845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6846 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006847 }
6848
6849 f_rsl_chan_deact();
6850 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006851
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006852 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006853 setverdict(pass);
6854 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006855 setverdict(fail, "Not enough fill frames received: ",
6856 nfill_frames, " out of ", expected_fill_frames);
6857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006858 }
6859 } else {
6860 repeat;
6861 }
6862 }
6863 }
6864 [] L1CTL.receive { repeat; }
6865 [] T.timeout {
6866 f_rsl_chan_deact();
6867 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006869 }
6870 }
6871}
6872
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006873private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006874 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006875 var ConnHdlr vc_conn;
6876 var ConnHdlrPars pars;
6877 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006878 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006879 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006880 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006881 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006882 if (dtxd) {
6883 if (i >= 4) { /* DTX is only allowed on TCH/F */
6884 break;
6885 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006886 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006887 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006888 vc_conn.done;
6889 }
6890}
6891
6892/* Verify that L2 fill frames are sent on TCH in signaling mode if
6893 * there is nothing to transmit while DTX is disabled on downlink. */
6894testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6895 f_tch_sign_l2_fill_frame(false);
6896}
6897
6898/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6899 * there is nothing to transmit while DTX is enabled on downlink. */
6900testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6901 f_tch_sign_l2_fill_frame(true);
6902}
Harald Welte0472ab42018-03-12 15:02:26 +01006903
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006904testcase TC_chopped_ipa_ping() runs on test_CT {
6905 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6906}
6907
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006908testcase TC_chopped_ipa_payload() runs on test_CT {
6909 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6910}
6911
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006912
6913/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6914 * Return value: Measurement Report to be sent (encoded octetstring). */
6915type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6916 runs on ConnHdlr return octetstring;
6917
6918private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6919runs on ConnHdlr {
6920 var L1ctlDlMessage l1_dl;
6921 var SacchL1Header l1h;
6922 var octetstring l2;
6923
6924 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6925 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6926 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6927 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6928
6929 /* Pass it to the user specified call-back function */
6930 l2 := cb.apply(l1h, num_blocks);
6931 /* Send a Measurement Report generated by the call-back */
6932 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6933 l1_dl.dl_info.link_id,
6934 l1h, l2));
6935
6936 /* Shall we keep going? */
6937 num_blocks := num_blocks - 1;
6938 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6939 if (num_blocks > 0) { repeat; }
6940 }
6941 [] L1CTL.receive { repeat; }
6942}
6943
6944private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6945runs on ConnHdlr return octetstring {
6946 /* Command the L1 to apply received parameters */
6947 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6948
6949 /* Dummy measurement report (the results are invalid) */
6950 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6951}
6952
6953private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6954runs on ConnHdlr return octetstring {
6955 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6956 setverdict(fail, "Unexpected MS Power level change: ",
6957 g_pars.l1_pars.ms_power_level, " -> ",
6958 l1h.ms_power_lvl);
6959 }
6960
6961 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6962}
6963
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006964private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6965runs on ConnHdlr return octetstring {
6966 /* UL RSSI oscillation driven by SACCH block number */
6967 if (num_blocks rem 2 == 0) {
6968 f_trxc_fake_rssi(-100);
6969 } else {
6970 f_trxc_fake_rssi(-50);
6971 }
6972
6973 /* Make sure that MS power level remains constant */
6974 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6975}
6976
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006977/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6978private function f_TC_ms_pwr_ctrl_constant(charstring id)
6979runs on ConnHdlr {
6980 var integer num_blocks := 8;
6981 timer T := int2float(num_blocks);
6982
6983 f_l1_tune(L1CTL);
6984 RSL.clear;
6985
6986 /* These IEs are needed for autonomous MS power control */
6987 var template (value) RSL_IE_List ies := {
6988 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6989 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6990 }),
6991 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6992 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6993 })
6994 };
6995
6996 /* Ensure that 'rx-current' equals 'rx-target' */
6997 f_trxc_fake_rssi(mp_uplink_power_target);
6998
6999 /* Establish a dedicated channel */
7000 f_est_dchan(more_ies := valueof(ies));
7001
7002 L1CTL.clear;
7003 T.start;
7004 alt {
7005 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7006 [] T.timeout {
7007 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7008 num_blocks, " were not handled");
7009 }
7010 }
7011}
7012testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7013 var ConnHdlr vc_conn;
7014 var ConnHdlrPars pars;
7015
7016 f_init();
7017
7018 /* Explicitly configure the Uplink power target (in dBm) */
7019 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7020
7021 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7022 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7023 log(testcasename(), ": starting on ", pars.chan_nr);
7024
7025 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7026 pars, trxc_comp := true);
7027 vc_conn.done;
7028 }
7029
7030 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7032}
7033
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007034/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7035private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7036runs on ConnHdlr {
7037 var integer num_blocks := 16;
7038 timer T := int2float(num_blocks);
7039
7040 f_l1_tune(L1CTL);
7041 RSL.clear;
7042
7043 /* These IEs are needed for autonomous MS power control */
7044 var template (value) RSL_IE_List ies := {
7045 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7046 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7047 }),
7048 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7049 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7050 })
7051 };
7052
7053 /* Ensure that 'rx-current' equals 'rx-target' */
7054 f_trxc_fake_rssi(mp_uplink_power_target);
7055
7056 /* Establish a dedicated channel */
7057 f_est_dchan(more_ies := valueof(ies));
7058
7059 L1CTL.clear;
7060 T.start;
7061 alt {
7062 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7063 [] T.timeout {
7064 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7065 num_blocks, " were not handled");
7066 }
7067 }
7068}
7069testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7070 var ConnHdlr vc_conn;
7071 var ConnHdlrPars pars;
7072
7073 f_init();
7074
7075 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7076 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7077 /* Explicitly configure the Uplink power range (target and delte) */
7078 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7079 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7080
7081 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7082 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7083 log(testcasename(), ": starting on ", pars.chan_nr);
7084
7085 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7086 pars, trxc_comp := true);
7087 vc_conn.done;
7088 }
7089
7090 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7092}
7093
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007094private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7095 var template L1ctlDlMessage tr_bad_frame;
7096 var L1ctlDlMessage l1_dl;
7097 timer T := 8.0;
7098
7099 f_l1_tune(L1CTL);
7100 RSL.clear;
7101
7102 f_est_dchan();
7103
7104 /* There may be a few errors right after the channel activation */
7105 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7106 L1CTL.clear;
7107
7108 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7109 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7110 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7111 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7112 tr_bad_frame.payload := ?;
7113
7114 T.start;
7115 alt {
7116 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7117 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7118 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7119 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7120 }
7121 [] as_l1_sacch();
7122 [] L1CTL.receive { repeat; }
7123 [] T.timeout {
7124 /* We're done, break the loop */
7125 setverdict(pass);
7126 }
7127 }
7128
7129 f_rsl_chan_deact();
7130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7131}
7132testcase TC_speech_no_rtp_tchf() runs on test_CT {
7133 var ConnHdlr vc_conn;
7134 var ConnHdlrPars pars;
7135
7136 f_init();
7137
7138 /* TS1, TCH/F, V1 (FR codec) */
7139 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7140 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7141 vc_conn.done;
7142}
7143testcase TC_speech_no_rtp_tchh() runs on test_CT {
7144 var ConnHdlr vc_conn;
7145 var ConnHdlrPars pars;
7146
7147 f_init();
7148
7149 /* TS5, TCH/H, V1 (HR codec) */
7150 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7151 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7152 vc_conn.done;
7153}
7154
Harald Welte0472ab42018-03-12 15:02:26 +01007155/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7156/* protocol error as per 44.006 */
7157/* link layer failure (repetition of I-frame N200 times without ACK */
7158/* repetition of SABM or DISC N200 times without ACK */
7159/* receptiom of SABM in multi-frame established state */
7160
7161
Harald Welte68e495b2018-02-25 00:05:57 +01007162/* TODO Areas:
7163
7164* channel activation
7165** with BS_Power / MS_Power, bypassing power control loop
7166** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007167** with timing advance from initial activation on
7168* mode modify
7169** encryption
7170** multirate
7171* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007172** unsupported algorithm
7173* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007174* BS Power Control
7175* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007176* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007177* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007178** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007179* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007180** DATA_IND from BTS->PCU
7181** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007182
7183*/
Harald Welte70767382018-02-21 12:16:40 +01007184
7185control {
7186 execute( TC_chan_act_stress() );
7187 execute( TC_chan_act_react() );
7188 execute( TC_chan_deact_not_active() );
7189 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007190 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007191 execute( TC_sacch_filling() );
7192 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007193 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007194 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007195 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007196 execute( TC_sacch_chan_act_ho_async() );
7197 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007198 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007199 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007200 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007201 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007202 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007203 execute( TC_rach_load_idle_thresh0() );
7204 execute( TC_rach_load_idle_below_thresh() );
7205 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007206 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007207 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007208 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007209 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007210 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007211 execute( TC_meas_res_sign_tchf() );
7212 execute( TC_meas_res_sign_tchh() );
7213 execute( TC_meas_res_sign_sdcch4() );
7214 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007215 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007216 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007217 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007218 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007219 execute( TC_rsl_bs_pwr_static_ass() );
7220 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007221 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007222 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007223 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007224 execute( TC_rsl_ms_pwr_dyn_up() );
7225 execute( TC_rsl_ms_pwr_dyn_down() );
7226 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7227 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007228 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007229 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007230 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007231 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007232 execute( TC_paging_imsi_80percent() );
7233 execute( TC_paging_tmsi_80percent() );
7234 execute( TC_paging_imsi_200percent() );
7235 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007236 execute( TC_rsl_protocol_error() );
7237 execute( TC_rsl_mand_ie_error() );
7238 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007239 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007240 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007241 execute( TC_si_sched_2bis() );
7242 execute( TC_si_sched_2ter() );
7243 execute( TC_si_sched_2ter_2bis() );
7244 execute( TC_si_sched_2quater() );
7245 execute( TC_si_sched_13() );
7246 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007247 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007248 execute( TC_ipa_crcx_twice_not_active() );
7249 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007250 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007251 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007252
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007253 if (mp_pcu_socket != "") {
7254 execute( TC_pcu_act_req() );
7255 execute( TC_pcu_act_req_wrong_ts() );
7256 execute( TC_pcu_act_req_wrong_bts() );
7257 execute( TC_pcu_act_req_wrong_trx() );
7258 execute( TC_pcu_deact_req() );
7259 execute( TC_pcu_deact_req_wrong_ts() );
7260 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007261 if (mp_l1_supports_gprs) {
7262 execute( TC_pcu_data_req_pdtch() );
7263 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007264 execute( TC_pcu_data_req_wrong_bts() );
7265 execute( TC_pcu_data_req_wrong_trx() );
7266 execute( TC_pcu_data_req_wrong_ts() );
7267 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007268 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007269 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007270 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007271 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007272 execute( TC_pcu_data_req_imm_ass_pch() );
7273 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007274 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007275 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007276 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007277 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007278 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007279 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007280 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007281 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007282 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007283 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007284 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007285 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007286 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007287 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007288 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007289 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007290 execute( TC_dyn_osmo_pdch_act_deact() );
7291 execute( TC_dyn_osmo_pdch_double_act() );
7292 execute( TC_dyn_ipa_pdch_act_deact() );
7293 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7294
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007295 if (PCUIF_Types.mp_pcuif_version >= 10) {
7296 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007297 execute( TC_pcu_socket_nsvc_ipv4() );
7298 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007299 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007300 } else {
7301 log("PCU socket path not available, skipping PCU tests");
7302 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007303
Harald Welte3d04ae62018-04-04 20:29:05 +02007304 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007305 execute( TC_dyn_osmo_pdch_tchf_act() );
7306 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007307 execute( TC_dyn_ipa_pdch_tchf_act() );
7308 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007309
7310 execute( TC_rll_est_ind() );
7311 execute( TC_rll_est_req_DCCH_3() );
7312 execute( TC_rll_est_req_ACCH_3() );
7313 execute( TC_rll_rel_ind_DCCH_0() );
7314 execute( TC_rll_rel_ind_DCCH_3() );
7315 execute( TC_rll_rel_ind_ACCH_0() );
7316 execute( TC_rll_rel_ind_ACCH_3() );
7317 execute( TC_rll_rel_req() );
7318 execute( TC_rll_unit_data_req_DCCH() );
7319 execute( TC_rll_unit_data_req_ACCH() );
7320 execute( TC_rll_unit_data_ind_DCCH() );
7321 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007322
7323 execute( TC_chan_act_a51() );
7324 execute( TC_chan_act_a52() );
7325 execute( TC_chan_act_a53() );
7326 execute( TC_encr_cmd_a51() );
7327 execute( TC_encr_cmd_a52() );
7328 execute( TC_encr_cmd_a53() );
7329
Harald Welteee25aae2019-05-19 14:32:37 +02007330 execute( TC_err_rep_wrong_mdisc() );
7331 execute( TC_err_rep_wrong_msg_type() );
7332 execute( TC_err_rep_wrong_sequence() );
7333
Harald Weltee613f962018-04-18 22:38:16 +02007334 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007335
7336 execute( TC_tch_sign_l2_fill_frame() );
7337 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007338
7339 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007340 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007341
7342 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007343 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007344
7345 execute( TC_speech_no_rtp_tchf() );
7346 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007347}
7348
7349
7350}