blob: 0cfd7507031ae4de1d8cd8bc29fdfc3d882646aa [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 Yanitskiyca813922020-09-12 19:08:31 +0700587 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
588 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700589 }
590
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700591 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700592 break; /* We're done */
593 }
594 }
595}
596
Harald Welte70767382018-02-21 12:16:40 +0100597/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700598friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
599 boolean pcu_comp := false,
600 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100601runs on test_CT return ConnHdlr {
602 var charstring id := testcasename();
603 var ConnHdlr vc_conn;
604
605 vc_conn := ConnHdlr.create(id);
606 /* connect to RSL Emulation main component */
607 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
608 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700609
610 /* The ConnHdlr component may want to talk to some ports directly,
611 * so we disconnect it from the test_CT and connect it to the component.
612 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200614 unmap(self:PCU, system:PCU);
615 map(vc_conn:PCU, system:PCU);
616 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700617 if (trxc_comp) {
618 unmap(self:BTS_TRXC, system:BTS_TRXC);
619 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
620 }
Harald Welte70767382018-02-21 12:16:40 +0100621
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700622 /* Obtain frequency hopping parameters for a given timeslot */
623 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 }
626
Harald Welte70767382018-02-21 12:16:40 +0100627 vc_conn.start(f_handler_init(fn, id, pars));
628 return vc_conn;
629}
630
Harald Welte70767382018-02-21 12:16:40 +0100631private altstep as_Tguard() runs on ConnHdlr {
632 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100634 }
635}
636
Harald Welte990a3612019-05-27 14:02:13 +0200637friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
638 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100639}
640
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700641private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100642 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700643 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100644}
645
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700646private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100647 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700648 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* first function started in ConnHdlr component */
652private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
653runs on ConnHdlr {
654 g_pars := pars;
655 g_chan_nr := pars.chan_nr;
656
657 map(self:L1CTL, system:L1CTL);
658 f_connect_reset(L1CTL);
659
Harald Welted48c0c72019-06-05 10:01:15 +0200660 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700661 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100662 }
Harald Welte70767382018-02-21 12:16:40 +0100663
664 g_Tguard.start(pars.t_guard);
665 activate(as_Tguard());
666
667 f_rslem_register(0, pars.chan_nr);
668
669 /* call the user-supplied test case function */
670 fn.apply(id);
671}
672
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700673private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
674 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200675runs on ConnHdlr return RSL_Message {
676 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100677 timer T := 3.0;
678 RSL.send(tx);
679 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100680 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200681 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100682 T.stop;
683 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100684 }
Harald Welte1eba3742018-02-25 12:48:14 +0100685 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100687 }
Harald Welte21240e62018-03-11 21:43:35 +0100688 [not ignore_other] as_l1_sacch();
689 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700690 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700691 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100692 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welte21240e62018-03-11 21:43:35 +0100695 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100696 }
Harald Welteb1726c92018-03-30 11:56:38 +0200697 return rx;
698}
699
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700700friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
701 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200702runs on ConnHdlr {
703 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100704}
705
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700706friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
707 boolean encr_enable := false,
708 RSL_IE_List more_ies := {},
709 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
710runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200711 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200712 if (encr_enable) {
713 /* append encryption related IEs, if requested */
714 var RSL_IE_EncryptionInfo encr_info;
715 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
716 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
717encr_info})) };
718 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200719 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200720 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100721}
722
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700723friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100724 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 +0100725 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100726}
727
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700728/* Default Mobile Allocation to be used for frequency hopping */
729private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
730 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
731
Harald Welte2f2b2b72019-05-31 22:24:57 +0200732friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100733 template RSL_IE_ChannelMode chan_mode,
734 float t_guard := 20.0) := {
735 chan_nr := valueof(chan_nr),
736 chan_mode := valueof(chan_mode),
737 t_guard := t_guard,
738 l1_pars := {
739 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100740 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100741 meas_ul := {
742 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200743 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100744 rxqual := 0
745 },
746 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200747 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100748 rxqual := 0
749 }
750 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200751 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100752 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200753 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200754 ms_actual_ta := mp_ms_actual_ta_exp,
755 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100756 },
Harald Weltee613f962018-04-18 22:38:16 +0200757 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200758 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700759 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700760 fhp := {
761 enabled := false,
762 maio_hsn := ts_HsnMaio(0, 0),
763 ma_map := c_MA_null,
764 ma := l1ctl_ma_def
765 }
Harald Welte70767382018-02-21 12:16:40 +0100766}
767
Harald Welte93640c62018-02-25 16:59:33 +0100768/***********************************************************************
769 * Channel Activation / Deactivation
770 ***********************************************************************/
771
Harald Welte70767382018-02-21 12:16:40 +0100772/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700773private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100774 for (var integer i := 0; i < 500; i := i+1) {
775 f_rsl_chan_act(g_pars.chan_mode);
776 f_rsl_chan_deact();
777 }
778 setverdict(pass);
779}
780testcase TC_chan_act_stress() runs on test_CT {
781 var ConnHdlr vc_conn;
782 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200783 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100784 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
785 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100787}
788
789/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700790private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100791 f_rsl_chan_act(g_pars.chan_mode);
792 /* attempt to activate the same lchan again -> expect reject */
793 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
794 alt {
795 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100797 }
798 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
799 setverdict(pass);
800 }
801 }
802 f_rsl_chan_deact();
803}
804testcase TC_chan_act_react() runs on test_CT {
805 var ConnHdlr vc_conn;
806 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100807 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100808 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
809 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100811}
812
813/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700814private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100815 timer T := 3.0;
816 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
817 T.start;
818 alt {
819 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
820 setverdict(pass);
821 }
822 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100824 }
825 }
826}
827testcase TC_chan_deact_not_active() runs on test_CT {
828 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100829 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100830 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
831 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100833}
834
835/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700836private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100837 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
838 alt {
839 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100841 }
842 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
843 setverdict(pass);
844 }
845 }
846}
847private type record WrongChanNrCase {
848 RslChannelNr chan_nr,
849 charstring description
850}
851private type record of WrongChanNrCase WrongChanNrCases;
852private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
853 chan_nr := chan_nr,
854 description := desc
855}
856
857testcase TC_chan_act_wrong_nr() runs on test_CT {
858 var ConnHdlr vc_conn;
859 var ConnHdlrPars pars;
860
Harald Welte294b0a22018-03-10 23:26:48 +0100861 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100862
863 var WrongChanNrCases wrong := {
864 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
866 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
867 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
868 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
869 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
870 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
871 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
872 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
873 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
874 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
875 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
876 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
877 };
878
879 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
880 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
881 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
882 vc_conn.done;
883 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100885}
886
Harald Weltee613f962018-04-18 22:38:16 +0200887/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200888friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200889 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200890 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200891
892 /* test on each of the channels we have */
893 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
894 pars.chan_nr := valueof(g_AllChanTypes[i]);
895
896 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
897 vc_conn := f_start_handler(fn, pars);
898 vc_conn.done;
899 }
900
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200902}
903
Harald Welte93640c62018-02-25 16:59:33 +0100904/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100905 * SACCH handling
906 ***********************************************************************/
907
908private function f_exp_sacch(boolean exp) runs on ConnHdlr {
909 timer T_sacch := 3.0;
910 T_sacch.start;
911 alt {
912 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100914 }
915 [not exp] T_sacch.timeout {
916 setverdict(pass);
917 }
918 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
919 setverdict(pass);
920 }
921 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100923 }
924 [] L1CTL.receive { repeat; }
925 [] RSL.receive { repeat; }
926 }
927}
928
929/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
930private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
931 f_l1_tune(L1CTL);
932 RSL.clear;
933
934 /* activate the logical channel */
935 f_est_dchan();
936 L1CTL.clear;
937
938 /* check that SACCH actually are received as expected */
939 f_exp_sacch(true);
940
941 /* deactivate SACCH on the logical channel */
942 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
943 f_sleep(1.0);
944 L1CTL.clear;
945
946 /* check that no SACCH are received anymore */
947 f_exp_sacch(false);
948
949 /* release the channel */
950 f_rsl_chan_deact();
951 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
952}
953testcase TC_deact_sacch() runs on test_CT {
954 var ConnHdlr vc_conn;
955 var ConnHdlrPars pars;
956 f_init();
957 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
958 //for (var integer i := 0; i < 1; i := i+1) {
959 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
960 log(testcasename(), ": Starting for ", g_AllChannels[i]);
961 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
962 vc_conn.done;
963 }
964 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100966}
967
Harald Welte55700662018-03-12 13:15:43 +0100968/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100969private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
970 var L1ctlDlMessage dl;
971 /* check that the specified SI5 value is actually sent */
972 timer T_sacch := 3.0;
973 L1CTL.clear;
974 T_sacch.start;
975 alt {
976 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
977 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
978 if (match(l3, l3_exp)) {
979 setverdict(pass);
980 } else {
981 repeat;
982 }
983 }
984 [] L1CTL.receive { repeat; }
985 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100987 }
988 }
989}
990
Harald Welte55700662018-03-12 13:15:43 +0100991/* verify that given SACCH payload is not present */
992private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
993 var L1ctlDlMessage dl;
994 /* check that the specified SI5 value is actually sent */
995 timer T_sacch := 3.0;
996 L1CTL.clear;
997 T_sacch.start;
998 alt {
999 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1000 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1001 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001003 } else {
1004 repeat;
1005 }
1006 }
1007 [] L1CTL.receive { repeat; }
1008 [] T_sacch.timeout {
1009 setverdict(pass);
1010 }
1011 }
1012}
1013
Harald Welte629cc6b2018-03-11 17:19:05 +01001014/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001015private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1016 /* Set a known default SACCH filling for SI5 */
1017 var octetstring si5 := f_rnd_octstring(19);
1018 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1019
1020 f_l1_tune(L1CTL);
1021 RSL.clear;
1022
1023 /* activate the logical channel */
1024 f_est_dchan();
1025
1026 /* check that the specified SI5 value is actually sent */
1027 f_sacch_present(si5);
1028
1029 /* release the channel */
1030 RSL.clear;
1031 f_rsl_chan_deact();
1032 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1033}
1034testcase TC_sacch_filling() runs on test_CT {
1035 var ConnHdlr vc_conn;
1036 var ConnHdlrPars pars;
1037 f_init();
1038 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1039 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1040 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1041 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1042 vc_conn.done;
1043 }
1044 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001046}
1047
Harald Welte629cc6b2018-03-11 17:19:05 +01001048/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001049private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1050 /* Set a known default SACCH filling for SI5 */
1051 var octetstring si5 := f_rnd_octstring(19);
1052 var octetstring si5_diff := f_rnd_octstring(19);
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 log("Activating channel, expecting standard SI5");
1059 /* activate the logical channel */
1060 f_est_dchan();
1061 /* check that the specified SI5 value is actually sent */
1062 f_sacch_present(si5);
1063
1064 /* set channel-specific different SI5 */
1065 log("Setting channel specific SACCH INFO, expecting it");
1066 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1067 /* check that the specified lchan-specific value is now used */
1068 f_sacch_present(si5_diff);
1069
1070 /* deactivate the channel and re-activate it, this should result in default SI5 */
1071 log("De-activating and re-activating channel, expecting standard SI5");
1072 f_rsl_chan_deact();
1073 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1074 /* Verify that the TRX-wide default SACCH filling is present again */
1075 f_sacch_present(si5);
1076
1077 /* release the channel */
1078 RSL.clear;
1079 f_rsl_chan_deact();
1080 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1081}
1082testcase TC_sacch_info_mod() runs on test_CT {
1083 var ConnHdlr vc_conn;
1084 var ConnHdlrPars pars;
1085 f_init();
1086 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1087 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1088 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1089 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1090 vc_conn.done;
1091 }
1092 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001094}
1095
Harald Welte075d84c2018-03-12 13:07:24 +01001096/* Test SACCH scheduling of multiple different SI message types */
1097private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1098 var octetstring si5 := f_rnd_octstring(19);
1099 var octetstring si5bis := f_rnd_octstring(19);
1100 var octetstring si5ter := f_rnd_octstring(19);
1101 var octetstring si6 := f_rnd_octstring(19);
1102
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1106 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1107
1108 f_l1_tune(L1CTL);
1109 RSL.clear;
1110
1111 /* activate the logical channel */
1112 f_est_dchan();
1113 L1CTL.clear;
1114
1115 /* check that SACCH actually are received as expected */
1116 f_sacch_present(si5);
1117 f_sacch_present(si5bis);
1118 f_sacch_present(si5ter);
1119 f_sacch_present(si6);
1120
1121 /* release the channel */
1122 f_rsl_chan_deact();
1123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1124}
1125testcase TC_sacch_multi() runs on test_CT {
1126 var ConnHdlr vc_conn;
1127 var ConnHdlrPars pars;
1128 f_init();
1129 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1130 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1131 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1132 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1133 vc_conn.done;
1134 }
1135 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001137}
1138
Harald Welte55700662018-03-12 13:15:43 +01001139/* Test if SACH information is modified as expected */
1140private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1141 var octetstring si5 := f_rnd_octstring(19);
1142 var octetstring si6 := f_rnd_octstring(19);
1143
1144 /* First, configure both SI5 and SI6 to be transmitted */
1145 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1146 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1147
1148 f_l1_tune(L1CTL);
1149 RSL.clear;
1150
1151 /* activate the logical channel */
1152 f_est_dchan();
1153 L1CTL.clear;
1154
1155 /* check that SACCH actually are received as expected */
1156 f_sacch_present(si5);
1157 f_sacch_present(si6);
1158
1159 /* disable SI6 */
1160 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1161
1162 /* check that SI5 is still transmitted */
1163 f_sacch_present(si5);
1164 /* check if SI6 is now gone */
1165 f_sacch_missing(si6);
1166
1167 /* release the channel */
1168 f_rsl_chan_deact();
1169 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1170}
1171testcase TC_sacch_multi_chg() runs on test_CT {
1172 var ConnHdlr vc_conn;
1173 var ConnHdlrPars pars;
1174 f_init();
1175 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1176 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1177 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1178 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1179 vc_conn.done;
1180 }
1181 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001183}
1184
Harald Weltec8d363c2019-05-19 20:36:48 +02001185/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1186private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1187 var octetstring si5 := f_rnd_octstring(19);
1188 var octetstring si6 := f_rnd_octstring(19);
1189 var octetstring si5_specific := f_rnd_octstring(19);
1190 var octetstring si6_specific := f_rnd_octstring(19);
1191
1192 /* First, configure both SI5 and SI6 to be transmitted */
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1194 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* activate channel with different SACCH filling */
1200 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1201 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1202 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1203 }));
1204 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1205 RSL_IE_Body:{sacch_info := sacch_info})) };
1206 f_est_dchan(more_ies := addl_ies);
1207
1208 /* check that SACCH actually are received as expected */
1209 f_sacch_present(si5_specific);
1210 f_sacch_present(si6_specific);
1211
1212 /* release the channel */
1213 f_rsl_chan_deact();
1214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1215}
1216testcase TC_sacch_chan_act() runs on test_CT {
1217 var ConnHdlr vc_conn;
1218 var ConnHdlrPars pars;
1219 f_init();
1220
1221 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1222 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1223 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1224 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1225 vc_conn.done;
1226 }
1227 /* TODO: do the above in parallel, rather than sequentially? */
1228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1229}
1230
Harald Welte8b01c792019-05-19 22:51:25 +02001231/* verify that SACCH DL transmission is started only if MS power IE present
1232 * see section 4.1.3 of 3GPP TS 48.058 */
1233private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1234 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001235 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001236
1237 f_l1_tune(L1CTL);
1238 RSL.clear;
1239
1240 /* Step 1: Activate ASYNC HO channel without MS power IE */
1241
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001242 var integer ho_ref := oct2int(f_rnd_octstring(1));
1243 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1244 RSL_IE_Body:{ handover_ref := ho_ref }));
1245 var RSL_IE_List addl_ies := {
1246 ho_ref_ie
1247 };
1248
Harald Welte8b01c792019-05-19 22:51:25 +02001249 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001250 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 +02001251 /* don't perform immediate assignment here, as we're testing non-IA case */
1252 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001253 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001254
1255 /* Verify that no DL SACCH is being received */
1256 f_sacch_missing(?);
1257
1258 f_rsl_chan_deact();
1259 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1260
1261
1262 /* Step 2: Activate ASYNC HO channel with MS power IE */
1263
1264 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001265 addl_ies := {
1266 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001267 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1268 };
1269 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1270 /* don't perform immediate assignment here, as we're testing non-IA case */
1271 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001272 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001273
1274 /* Verify that DL SACCH is being received */
1275 f_sacch_present(si5);
1276
1277 f_rsl_chan_deact();
1278 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1279}
1280testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1281 var ConnHdlr vc_conn;
1282 var ConnHdlrPars pars;
1283 f_init();
1284
1285 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1286 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1287 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1288 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1289 vc_conn.done;
1290 }
1291 /* TODO: do the above in parallel, rather than sequentially? */
1292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1293}
1294
1295/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1296 * see section 4.1.4 of 3GPP TS 48.058 */
1297private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1298 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1300
Harald Welte8b01c792019-05-19 22:51:25 +02001301 var RSL_IE_List addl_ies;
1302
1303 f_l1_tune(L1CTL);
1304 RSL.clear;
1305
1306 /* Step 1: Activate SYNC HO channel without MS power IE */
1307
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001308 var integer ho_ref := oct2int(f_rnd_octstring(1));
1309 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1310 RSL_IE_Body:{ handover_ref := ho_ref }));
1311 addl_ies := {
1312 ho_ref_ie
1313 };
1314
Harald Welte8b01c792019-05-19 22:51:25 +02001315 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001316 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 +02001317 /* don't perform immediate assignment here, as we're testing non-IA case */
1318 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001319 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001320
1321 /* Verify that no DL SACCH is being received */
1322 f_sacch_missing(?);
1323
1324 f_rsl_chan_deact();
1325 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1326
1327
1328 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1329
1330 /* Activate channel on BTS side */
1331 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001332 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001333 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1334 };
1335 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1336 /* don't perform immediate assignment here, as we're testing non-IA case */
1337 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001338 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001339
1340 /* Verify that no DL SACCH is being received */
1341 f_sacch_missing(?);
1342
1343 f_rsl_chan_deact();
1344 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1345
1346
1347 /* Step 2b: Activate SYNC HO channel with TA IE */
1348
1349 /* Activate channel on BTS side */
1350 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001351 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001352 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1353 };
1354 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1355 /* don't perform immediate assignment here, as we're testing non-IA case */
1356 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001357 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001358
1359 /* Verify that no DL SACCH is being received */
1360 f_sacch_missing(?);
1361
1362 f_rsl_chan_deact();
1363 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1364
1365
1366 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1367
1368 /* Activate channel on BTS side */
1369 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001370 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001371 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1372 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1373 };
1374 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1375 /* don't perform immediate assignment here, as we're testing non-IA case */
1376 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001377 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001378
1379 /* Verify that DL SACCH is being received */
1380 f_sacch_present(si5);
1381
1382 f_rsl_chan_deact();
1383 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1384}
1385testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1386 var ConnHdlr vc_conn;
1387 var ConnHdlrPars pars;
1388 f_init();
1389
1390 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1391 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1392 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1393 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1394 vc_conn.done;
1395 }
1396 /* TODO: do the above in parallel, rather than sequentially? */
1397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1398}
Harald Welte629cc6b2018-03-11 17:19:05 +01001399
1400
1401/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001402 * RACH Handling
1403 ***********************************************************************/
1404
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001406private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001407 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001409 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001410
Harald Welte8c24c2b2018-02-26 08:31:31 +01001411 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001412 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001413 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001414 var OCT1 ra := f_rnd_ra_emerg();
1415 if (emerg == true) {
1416 ra := f_rnd_ra_emerg();
1417 } else {
1418 ra := f_rnd_ra_cs();
1419 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001420 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1421 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001423 }
1424 fn_last := fn;
1425
1426 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001427 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001428 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001429 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001430 T.stop;
1431 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001432 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001434 }
1435 [] RSL_CCHAN.receive { repeat; }
1436 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001437 test_failed := true;
1438 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001439 }
1440 }
1441 }
Maxba06feb2019-03-05 10:52:46 +01001442 if (test_failed) {
1443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001444 }
Maxba06feb2019-03-05 10:52:46 +01001445 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001447}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001448
Philipp Maier16ade782020-07-08 21:36:00 +02001449/* Normal variant */
1450testcase TC_rach_content() runs on test_CT {
1451 f_TC_rach_content(emerg := false);
1452}
1453
1454/* Emergency call variant */
1455testcase TC_rach_content_emerg() runs on test_CT {
1456 f_TC_rach_content(emerg := true);
1457}
1458
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1460testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001461 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001462 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001463 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001464 f_l1_tune(L1CTL);
1465
1466 var GsmFrameNumber fn_last := 0;
1467 for (var integer i := 0; i < 1000; i := i+1) {
1468 var OCT1 ra := f_rnd_ra_cs();
1469 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1470 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001472 }
1473 fn_last := fn;
1474 }
1475 var integer rsl_chrqd := 0;
1476 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001477 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001478 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001479 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001480 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001481 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001482 repeat;
1483 }
1484 [] RSL_CCHAN.receive { repeat; }
1485 [] T.timeout { }
1486 }
1487 if (rsl_chrqd == 1000) {
1488 setverdict(pass);
1489 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001491 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001493}
1494
Harald Welte3453ab42019-05-24 21:19:58 +02001495private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1496 var charstring bts_str := "bts " & int2str(bts_nr);
1497 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1498}
1499
1500/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1501private template integer tr_rach_slots_per_interval := (90 .. 130);
1502
1503/* Expect 0 RACH load on an idle BTS that has just started up */
1504testcase TC_rach_load_idle_thresh0() runs on test_CT {
1505 var ASP_RSL_Unitdata rx_ud;
1506
1507 f_init_vty_bsc();
1508 /* send load indications even at 0% load */
1509 f_vty_load_ind_thresh(0);
1510 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1511 f_sleep(2.0);
1512
1513 f_init();
1514
Harald Weltee37f9a52020-10-11 20:45:23 +02001515 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1516 alt {
1517 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1518 [] RSL_CCHAN.receive { repeat }
1519 }
1520
Harald Welte3453ab42019-05-24 21:19:58 +02001521 timer T := 5.0;
1522 T.start;
1523 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001524 [] 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 +02001525 setverdict(pass);
1526 repeat;
1527 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001528 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001529 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1530 repeat;
1531 }
1532 [] RSL_CCHAN.receive {
1533 repeat;
1534 }
1535 [] T.timeout { }
1536 }
1537
1538 f_vty_load_ind_thresh(10);
1539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1540}
1541
1542/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1543testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1544 var ASP_RSL_Unitdata rx_ud;
1545
1546 f_init_vty_bsc();
1547 f_init();
1548
1549 timer T := 5.0;
1550 T.start;
1551 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001552 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001553 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1554 repeat;
1555 }
1556 [] RSL_CCHAN.receive {
1557 repeat;
1558 }
1559 [] T.timeout {
1560 setverdict(pass);
1561 }
1562 }
1563
1564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1565}
1566
1567/* Expect 0 RACH load on an idle BTS that has just started up */
1568testcase TC_rach_load_count() runs on test_CT {
1569 var ASP_RSL_Unitdata rx_ud;
1570 var integer load_access_count := 0;
1571
1572 f_init_vty_bsc();
1573 /* send load indications even at 0% load */
1574 f_vty_load_ind_thresh(0);
1575 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1576 f_sleep(2.0);
1577 f_init();
1578
1579 f_init_l1ctl();
1580 f_sleep(1.0);
1581 f_l1_tune(L1CTL);
1582
Harald Welte52ae1682020-10-11 20:45:55 +02001583 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1584 alt {
1585 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1586 [] RSL_CCHAN.receive { repeat }
1587 }
1588
Harald Welte3453ab42019-05-24 21:19:58 +02001589 var GsmFrameNumber fn_last := 0;
1590 for (var integer i := 0; i < 1000; i := i+1) {
1591 var OCT1 ra := f_rnd_ra_cs();
1592 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1593 if (fn == fn_last) {
1594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1595 }
1596 fn_last := fn;
1597 }
1598
1599 timer T := 5.0;
1600 T.start;
1601 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001602 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001603 -> value rx_ud {
1604 var RSL_IE_Body ie;
1605 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1606 load_access_count := load_access_count + ie.rach_load.access_count;
1607 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1608 setverdict(fail, "Access count cannot be < Busy count");
1609 }
1610 repeat;
1611 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001612 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001613 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1614 repeat;
1615 }
1616 [] RSL_CCHAN.receive {
1617 repeat;
1618 }
1619 [] T.timeout { }
1620 }
1621 if (load_access_count == 1000) {
1622 setverdict(pass);
1623 } else {
1624 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1625 }
1626
1627 f_vty_load_ind_thresh(10);
1628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1629}
1630
Harald Welte54a2a2d2018-02-26 09:14:05 +01001631private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001632 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001633 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001634 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001635 f_sleep(0.5);
1636
1637 /* Transmit RACH request + wait for confirmation */
1638 var OCT1 ra := f_rnd_ra_cs();
1639 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1640
1641 /* Check for expected result */
1642 timer T := 1.5;
1643 T.start;
1644 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001645 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001646 setverdict(pass);
1647 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001648 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001650 }
1651 [] RSL_CCHAN.receive { repeat; }
1652 [not expect_pass] T.timeout {
1653 setverdict(pass);
1654 }
1655 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001657 }
1658 }
1659}
1660
1661/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1662testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001663 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001664 f_init_l1ctl();
1665 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001666 f_sleep(1.0);
1667
1668 /* default max-ta is 63 (full range of GSM timing advance */
1669
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001670 /* We allow early arrival up to 2 symbols */
1671 f_rach_toffs(-1*256, true);
1672 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001673 f_rach_toffs(-10*256, false);
1674
1675 /* 0 / 32 / 63 bits is legal / permitted */
1676 f_rach_toffs(0, true);
1677 f_rach_toffs(32*256, true);
1678 f_rach_toffs(63*256, true);
1679
1680 /* more than 63 bits is not legal / permitted */
1681 f_rach_toffs(64*256, false);
1682 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001684}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001686private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001687 var GsmFrameNumber fn;
1688 var RSL_Message rm;
1689
1690 f_l1_tune(L1CTL);
1691 RSL.clear;
1692
1693 /* Generate a random Handover Reference */
1694 var integer ho_ref := oct2int(f_rnd_octstring(1));
1695
1696 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1697 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1698 RSL_IE_Body:{ handover_ref := ho_ref }));
1699
1700 /* Activate a channel on the BTS side (no encryption) */
1701 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1702 act_type := t_RSL_IE_ActType_HO_SYNC);
1703
1704 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1705 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001706 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001707
1708 /* Send handover Access Burst */
1709 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1710
1711 /* TODO: test mismatching Handover Reference, and missing IE */
1712
1713 /* Wait for handover detection */
1714 timer T := 3.0;
1715 T.start;
1716 alt {
1717 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1718 log("Handover RACH has been detected: ", rm);
1719 setverdict(pass);
1720 }
1721 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1723 log2str("RSL_CHAN_RQD was not expected: ", rm));
1724 }
1725 [] RSL.receive { repeat; }
1726 [] T.timeout {
1727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1728 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1729 }
1730 }
1731
1732 /* Release the channel */
1733 f_rsl_chan_deact();
1734 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1735}
1736
1737/* Test handover RACH detection */
1738testcase TC_ho_rach() runs on test_CT {
1739 var ConnHdlrPars pars;
1740 var ConnHdlr vc_conn;
1741
1742 f_init();
1743
1744 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1745 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1746 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1747 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1748 vc_conn.done;
1749 }
1750
1751 /* TODO: do the above in parallel, rather than sequentially? */
1752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1753}
1754
Harald Welte93640c62018-02-25 16:59:33 +01001755/***********************************************************************
1756 * Measurement Processing / Reporting
1757 ***********************************************************************/
1758
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001759private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001760 spare := '0'B,
1761 lpd := 0,
1762 sapi := sapi,
1763 c_r := c_r,
1764 ea := true
1765}
1766
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001767private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001768 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001769 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001770 len := 0, /* overwritten */
1771 m := false,
1772 el := 1,
1773 payload := pl
1774}
1775
1776/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001777private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001778 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001779 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001780 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001781 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 +01001782 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001783 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001784
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001785 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1786 g_pars.l1_pars.ms_power_level, false,
1787 g_pars.l1_pars.ms_actual_ta);
1788
1789 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1790 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1791
1792 log("Sending Measurement Report: ", l1h, l2);
1793 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001794 repeat;
1795 }
1796}
1797
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001798private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001799 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001800 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001801 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1802 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001803 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1804 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001805 repeat;
1806 }
1807}
1808
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001809private altstep as_l1_tch_loop() runs on ConnHdlr {
1810 var L1ctlDlMessage l1_dl;
1811 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1812 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001813
1814 /* occasionaly inject FACCH frames into the uplink */
1815 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1816 var octetstring pl := '010301'O;
1817 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1818 f_pad_oct(pl, 23, '2B'O)));
1819 } else {
1820 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1821 l1_dl.payload.traffic_ind.data));
1822 }
1823
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001824 repeat;
1825 }
1826}
1827
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001828private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001829 uint6_t rxlev,
1830 uint3_t rxqual
1831}
1832
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001833private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001834 MeasElem full,
1835 MeasElem sub
1836}
1837
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001838private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001839 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001840 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001841 MeasElemFS meas_ul,
1842 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001843 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001844 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001845 uint8_t ms_actual_ta,
1846 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001847}
1848
1849/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1850private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1851 return 63 + (toffs256s/256);
1852}
1853
Harald Welted5684392018-03-10 18:22:04 +01001854private function f_max(integer a, integer b) return integer {
1855 if (a > b) {
1856 return a;
1857 } else {
1858 return b;
1859 }
1860}
1861
1862private function f_min(integer a, integer b) return integer {
1863 if (a < b) {
1864 return a;
1865 } else {
1866 return b;
1867 }
1868}
1869
1870/* compute negative tolerance val-tolerance, ensure >= min */
1871private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1872 val := val - tolerance;
1873 return f_max(val, min);
1874}
1875
1876/* compute positive tolerance val+tolerance, ensure <= max */
1877private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1878 val := val + tolerance;
1879 return f_min(val, max);
1880}
1881
1882/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1883private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1884return template integer {
1885 var template integer ret;
1886 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1887 return ret;
1888}
1889
1890
Harald Welte70767382018-02-21 12:16:40 +01001891/* build a template for matching measurement results against */
1892private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1893 var ConnL1Pars l1p := g_pars.l1_pars;
1894 var template RSL_IE_UplinkMeas ul_meas := {
1895 len := 3,
1896 rfu := '0'B,
1897 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001898 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001899 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001900 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001901 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001902 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1903 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001904 supp_meas_info := omit
1905 };
Harald Welte685d5982018-02-27 20:42:05 +01001906 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001907 ul_meas.len := (3+8);
1908 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001909 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001910 toa256_min := ?,
1911 toa256_max := ?,
1912 toa256_std_dev := ?
1913 }
Harald Welte685d5982018-02-27 20:42:05 +01001914 }
Harald Welte70767382018-02-21 12:16:40 +01001915 var template RSL_IE_BS_Power bs_power := {
1916 reserved := 0,
1917 epc := false,
1918 fpc := false,
1919 power_level := l1p.bs_power_level
1920 };
1921 var template RSL_IE_L1Info l1_info := {
1922 ms_power_lvl := l1p.ms_power_level,
1923 fpc := false,
1924 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001925 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001926 };
1927 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001928 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001929 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1930 ?, t_toffs);
1931}
1932
Philipp Maierdd841d32019-12-17 14:44:54 +01001933/* build a template for matching measurement results that do not contain any
1934 * MS related measurement (l1_info, l3_info and ms timing offset). */
1935private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1936 var ConnL1Pars l1p := g_pars.l1_pars;
1937 var template RSL_IE_UplinkMeas ul_meas := {
1938 len := 3,
1939 rfu := '0'B,
1940 dtx_d := l1p.dtx_enabled,
1941 rxlev_f_u := ?,
1942 reserved1 := '00'B,
1943 rxlev_s_u := ?,
1944 reserved2 := '00'B,
1945 rxq_f_u := ?,
1946 rxq_s_u := ?,
1947 supp_meas_info := omit
1948 };
1949 if (l1p.toa256_enabled) {
1950 ul_meas.len := (3+8);
1951 ul_meas.supp_meas_info := {
1952 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1953 toa256_min := ?,
1954 toa256_max := ?,
1955 toa256_std_dev := ?
1956 }
1957 }
1958 var template RSL_IE_BS_Power bs_power := {
1959 reserved := 0,
1960 epc := false,
1961 fpc := false,
1962 power_level := l1p.bs_power_level
1963 };
1964
1965 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1966}
1967
Harald Welte70767382018-02-21 12:16:40 +01001968/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001969private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001970 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001971 var boolean chan_est := false;
1972
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001973 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001974
1975 /* Receive osmocom specific measurement reports. This is the normal
1976 * case. Here we verify that the measurement reports we sent are
1977 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001978 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1979 /* increment counter of next to-be-expected meas rep */
1980 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1981 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001982 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001983
1984 /* The following two cases may only happen in the beginning
1985 * of the channel establishment phase. Once we have received
1986 * the "our" measurement report the first time, the channel
1987 * is established and empty or hardcoded TRXCON reports must
1988 * not occur anymore. */
1989 chan_est := true;
1990
1991 repeat;
1992 }
1993
1994 /* When the BTS has established the channel, the MS might need slightly
1995 * more time to establish the channel and actually start sending. The
1996 * result is then a measurement report that just lacks the measurement
1997 * information of the MS. This is normal and we tolerate this behavior. */
1998 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1999 /* increment counter of next to-be-expected meas rep */
2000 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2001 /* Re-start the timer expecting the next MEAS RES */
2002 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002003 repeat;
2004 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002005
2006 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2007 * measurements if the TTCN3 side does not supply measurement input in
2008 * time. In those cases TRXCON will either use a cached measurement
2009 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2010 * report the templates above will not match. We tolerate this
2011 * behavior, but only once. */
2012 [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 +01002013 /* increment counter of next to-be-expected meas rep */
2014 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2015 if (g_first_meas_res) {
2016 g_first_meas_res := false;
2017 repeat;
2018 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002020 }
Harald Welte70767382018-02-21 12:16:40 +01002021 }
2022 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002024 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002025 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002027 }
2028}
2029
Harald Weltee613f962018-04-18 22:38:16 +02002030private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2031 select (rsl_alg_id) {
2032 case (RSL_ALG_ID_A5_0) { return 0; }
2033 case (RSL_ALG_ID_A5_1) { return 1; }
2034 case (RSL_ALG_ID_A5_2) { return 2; }
2035 case (RSL_ALG_ID_A5_3) { return 3; }
2036 case (RSL_ALG_ID_A5_4) { return 4; }
2037 case (RSL_ALG_ID_A5_5) { return 5; }
2038 case (RSL_ALG_ID_A5_6) { return 6; }
2039 case (RSL_ALG_ID_A5_7) { return 7; }
2040 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2042 /* Make compiler happy by calling mtc.stop here. It is already
2043 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002044 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002045 }
2046 }
2047}
2048
2049private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2050 select (rsl_alg_id) {
2051 case (RSL_ALG_ID_A5_1) { return '000'B; }
2052 case (RSL_ALG_ID_A5_2) { return '001'B; }
2053 case (RSL_ALG_ID_A5_3) { return '010'B; }
2054 case (RSL_ALG_ID_A5_4) { return '011'B; }
2055 case (RSL_ALG_ID_A5_5) { return '100'B; }
2056 case (RSL_ALG_ID_A5_6) { return '101'B; }
2057 case (RSL_ALG_ID_A5_7) { return '110'B; }
2058 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2060 /* Make compiler happy by calling mtc.stop here. It is already
2061 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002062 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002063 }
2064 }
2065}
2066
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002067/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2068private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2069 var GsmFrameNumber fn;
2070 timer T := 8.0;
2071
2072 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2073 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2074
2075 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2076 /* Send the actual RACH */
2077 fn := f_L1CTL_RACH(L1CTL, ra);
2078
2079 T.start;
2080 alt {
2081 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2082 [] T.timeout {
2083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2084 }
2085 }
2086 T.stop
2087 return fn;
2088}
Harald Weltee613f962018-04-18 22:38:16 +02002089
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002090/* Tune to a dedicated channel: L1CTL only */
2091private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002092 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002093 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2094 7 /* TODO: mp_tsc */,
2095 mp_trx0_arfcn));
2096 } else {
2097 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2098 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002099 pars.fhp.maio_hsn.hsn,
2100 pars.fhp.maio_hsn.maio,
2101 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002102 }
2103}
2104
Harald Welte70767382018-02-21 12:16:40 +01002105/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002106private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002107 var GsmFrameNumber fn;
2108 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002109 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002110 var integer ra := 23;
2111
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002112 /* Send RACH request and wait for ChanReq */
2113 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002114
2115 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002116 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002117
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002118 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002119 if (g_pars.fhp.enabled) {
2120 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002121 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002122 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002123 }
2124
Harald Welte70767382018-02-21 12:16:40 +01002125 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002126 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 +01002127 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2128
2129 /* receive IMM.ASS on MS side */
2130 var ImmediateAssignment ia_um;
2131 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002132
2133 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2134 if (ch_desc.h != ia_um.chan_desc.h) {
2135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2136 }
2137
Harald Welte70767382018-02-21 12:16:40 +01002138 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002139 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002140 /* enable encryption, if requested */
2141 if (encr_enable) {
2142 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2143 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2144 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002145
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002146 /* Send TCH Mode Request to the L1 if needed */
2147 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2148 var L1ctlTchMode tch_mode;
2149
2150 select (g_pars.chan_mode.coding_alg_rate) {
2151 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2152 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2153 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2154 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2155 case else {
2156 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2157 " is not supported by the L1, falling back to signalling");
2158 tch_mode := L1CTL_CHAN_MODE_SIGN;
2159 }
2160 }
2161
2162 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2163 }
2164
Harald Weltefa45e9e2018-03-10 18:59:03 +01002165 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002166}
2167
2168/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002169private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002170 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002171 RSL.clear;
2172
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002173 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002174 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002175 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002176 }
Harald Welte70767382018-02-21 12:16:40 +01002177
2178 f_est_dchan();
2179
2180 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2181 * RSL measurement reports on Abis side */
2182 timer T := 8.0;
2183 T.start;
2184 alt {
2185 [] as_l1_sacch();
2186 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002187 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002188 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002189 [] L1CTL.receive { repeat; }
2190 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002191 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002192 * of any earlier errors, so if we reach this timeout, we're good */
2193 setverdict(pass);
2194 }
2195 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002197 }
2198 }
2199 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002200 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002201}
Harald Welte0472ab42018-03-12 15:02:26 +01002202
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002203/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2204private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002205 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002206 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2207 timer Tup := 10.0;
2208 Tup.start;
2209 alt {
2210 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2211 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2212 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002213
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002214 if (rx_lvl != max_rx_lvl) {
2215 repeat;
2216 }
2217 Tup.stop;
2218 }
2219 [] L1CTL.receive { repeat; }
2220 [] Tup.timeout {
2221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2222 log2str("Didn't reach full power ", max_rx_lvl));
2223 }
2224 }
2225 return max_rx_lvl;
2226}
2227
2228/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2229private function f_verify_ramp_up() runs on ConnHdlr {
2230 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002231 var integer initial_rx_lvl := -1;
2232 var integer last_rx_lvl := -1;
2233 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2234
2235 timer T := 2.0;
2236 alt {
2237 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2238 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2239 log("Received rx_level=", rx_lvl);
2240 if (initial_rx_lvl == -1) {
2241 initial_rx_lvl := rx_lvl;
2242 last_rx_lvl := rx_lvl;
2243
2244 /* Expect a somehow low value during first received messages */
2245 if (initial_rx_lvl >= max_rx_lvl / 2) {
2246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2247 log2str("Detected high initial tx power during ramp up: ",
2248 initial_rx_lvl , ", full power is", max_rx_lvl));
2249 }
2250 }
2251
2252 /* received Rx level bigger than maximum allowed power by CN */
2253 if (rx_lvl > max_rx_lvl) {
2254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2255 log2str("Detected Tx power higher than full power: ",
2256 rx_lvl , " > ", max_rx_lvl));
2257 }
2258
2259 /* Make sure it never decreases, since we are rumping up */
2260 if (last_rx_lvl > rx_lvl) {
2261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2262 log2str("Detected Tx power decrease during ramp up: ",
2263 last_rx_lvl , " -> ", rx_lvl));
2264 }
2265
2266 if (rx_lvl == max_rx_lvl and not T.running) {
2267 /* We reached the maximum power, start timer and receive
2268 /* a few more to make sure we don't surpass it */
2269 log("Reached full power, wating a bit more until success");
2270 T.start;
2271 }
2272
2273 last_rx_lvl := rx_lvl;
2274 repeat;
2275 }
2276 [] L1CTL.receive { repeat; }
2277 [] T.timeout { }
2278 }
2279
2280 /* We didn't increase tx power during ramp up */
2281 if (initial_rx_lvl < last_rx_lvl) {
2282 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2283 } else {
2284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2285 log2str("No Tx power increase during whole ramp up: ",
2286 initial_rx_lvl , " -> ", last_rx_lvl));
2287 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002288}
2289
2290/* verify BTS ramps power down to rx_level 0 */
2291private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2292 var L1ctlDlMessage l1_dl;
2293 var integer last_rx_lvl := max_rx_lvl;
2294
2295 timer Tdown := 5.0;
2296 Tdown.start;
2297 alt {
2298 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2299 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2300 log("Received rx_level=", rx_lvl);
2301
2302 /* received Rx level bigger than maximum allowed power by CN */
2303 if (rx_lvl > max_rx_lvl) {
2304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2305 log2str("Detected Tx power higher than full power: ",
2306 rx_lvl , " > ", max_rx_lvl));
2307 }
2308
2309 /* Make sure it never increases, since we are rumping down */
2310 if (last_rx_lvl < rx_lvl) {
2311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2312 log2str("Detected Tx power increase during ramp up: ",
2313 last_rx_lvl , " -> ", rx_lvl));
2314 }
2315
2316 last_rx_lvl := rx_lvl;
2317 if (last_rx_lvl != 0) {
2318 repeat;
2319 }
2320 /* we reached power level 0, we are done */
2321 Tdown.stop;
2322 }
2323 [] L1CTL.receive { repeat; }
2324 [] Tdown.timeout { }
2325 }
2326
2327 /* We didn't increase tx power during ramp down */
2328 if (max_rx_lvl > last_rx_lvl) {
2329 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2330 } else {
2331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2332 log2str("No Tx power decrease during whole ramp down: ",
2333 max_rx_lvl , " -> ", last_rx_lvl));
2334 }
2335}
2336
2337/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002338private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002339 f_l1_tune(L1CTL);
2340 RSL.clear;
2341
2342 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002343
2344 setverdict(pass);
2345}
2346testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2347 var ConnHdlr vc_conn;
2348 var ConnHdlrPars pars;
2349 f_init();
2350 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2351 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2352 pcu_comp := false, trxc_comp := true);
2353 vc_conn.done;
2354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2355}
2356
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002357/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002358private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002359 f_connhdlr_init_vty_bsc();
2360
2361 f_l1_tune(L1CTL);
2362 RSL.clear;
2363
2364 /* Wait until BTS is started and at full power */
2365 var integer max_rx_lvl := f_wait_ramp_up();
2366 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2367
2368 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2369 f_verify_ramp_down(max_rx_lvl);
2370
2371 setverdict(pass);
2372}
2373testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2374 var ConnHdlr vc_conn;
2375 var ConnHdlrPars pars;
2376 f_init();
2377 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2378 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2379 pcu_comp := false, trxc_comp := true);
2380 vc_conn.done;
2381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2382}
2383
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002384/* Verify Tx power:
2385 * + ramping down during ADM state UNLOCKED->LOCKED
2386 * + ramping up during ADM state LOCKED->UNLOCKED
2387 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002388private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002389 var L1ctlDlMessage l1_dl;
2390 var integer last_rx_lvl;
2391
2392 f_connhdlr_init_vty_bsc();
2393
2394 f_l1_tune(L1CTL);
2395 RSL.clear;
2396
2397 /* Wait until BTS is started and at full power */
2398 var integer max_rx_lvl := f_wait_ramp_up();
2399 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2400
2401 log("ADM STATE UNLOCKED->LOCKED");
2402 f_vty_enter_cfg_trx(BSCVTY);
2403 f_vty_transceive(BSCVTY, "rf_locked 1");
2404 last_rx_lvl := max_rx_lvl;
2405 f_verify_ramp_down(max_rx_lvl);
2406
2407 /* Let some time after we received 0dBm, then check we don't receive BCCH
2408 * anymore because scheduler has stopped after ramping down */
2409 f_sleep(2.0);
2410 L1CTL.clear;
2411 timer Tlocked := 2.0;
2412 Tlocked.start;
2413 alt {
2414 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2416 log2str("Received data_ind during rf_locked: ", l1_dl));
2417 }
2418 [] L1CTL.receive { repeat; }
2419 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2420 }
2421
2422 log("ADM STATE LOCKED->UNLOCKED");
2423 f_vty_transceive(BSCVTY, "rf_locked 0");
2424 f_verify_ramp_up();
2425 setverdict(pass);
2426}
2427testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2428 var ConnHdlr vc_conn;
2429 var ConnHdlrPars pars;
2430 f_init();
2431 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2432 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2433 pcu_comp := false, trxc_comp := true);
2434 vc_conn.done;
2435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2436}
2437
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002438private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002439 timer T := 8.0;
2440 T.start;
2441 var RSL_Message rsl;
2442 alt {
2443 [] as_l1_sacch();
2444 [] L1CTL.receive { repeat; }
2445 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2446 if (rsl.ies[3].body.bs_power.power_level == level) {
2447 setverdict(pass)
2448 } else {
2449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2450 }
2451 }
2452 [] T.timeout {
2453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2454 }
2455 }
2456}
2457
2458/* see if the rsl meas res contains our expeced bs power level
2459bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002460private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002461 f_l1_tune(L1CTL);
2462 RSL.clear;
2463
2464 if (mp_bts_trxc_port != -1) {
2465 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2466 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2467 }
2468
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002469 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002470 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2471 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2472
2473 f_est_dchan(more_ies :={valueof(pwr)});
2474
2475 f_check_meas_bs_power_level(pwr_var);
2476
2477 f_rsl_chan_deact();
2478 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2479}
2480
2481/* see if the rsl meas res contains our expeced bs power level
2482bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002483private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002484 f_l1_tune(L1CTL);
2485 RSL.clear;
2486
2487 if (mp_bts_trxc_port != -1) {
2488 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2489 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2490 }
2491
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002492 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002493 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2494
2495 f_est_dchan();
2496
2497 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2498
2499 f_check_meas_bs_power_level(pwr_var);
2500
2501 f_rsl_chan_deact();
2502 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2503}
2504
2505testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2506 var ConnHdlr vc_conn;
2507 var ConnHdlrPars pars;
2508 f_init();
2509 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2510 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2511 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2512 pcu_comp := false, trxc_comp := true);
2513 vc_conn.done;
2514 }
2515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2516}
2517
2518testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2519 var ConnHdlr vc_conn;
2520 var ConnHdlrPars pars;
2521 f_init();
2522 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2523 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2524 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2525 pcu_comp := false, trxc_comp := true);
2526 vc_conn.done;
2527 }
2528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2529}
2530
Eric Wild61edb7e2019-06-03 12:38:31 +02002531/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2532second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2533These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002534private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002535 var uint5_t pwr_var := 7;
2536 var L1ctlDlMessage l1_dl;
2537
2538 f_trxc_fake_rssi(rxlev2dbm(10));
2539 f_l1_tune(L1CTL);
2540 RSL.clear;
2541
2542 var RSL_IE_List addl_ies;
2543 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2544
2545 addl_ies := {
2546 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2547 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2548 };
2549
2550 /* establish with power parameters */
2551 f_est_dchan(more_ies := addl_ies);
2552
2553 /* set a high value to ensure L1 power control level increases */
2554 f_trxc_fake_rssi(rxlev2dbm(20));
2555
2556 timer T2 := 6.0;
2557 T2.start;
2558 alt {
2559 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002560 /* Update sent MS power to follow what BTS requests */
2561 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2562 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002564 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002565 T2.stop;
2566 }
2567 [] L1CTL.receive { repeat; }
2568 [] T2.timeout {
2569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2570 "Power Level in L1 header has not increased sufficiently");
2571 }
2572 }
2573
2574 /* set a low value to ensure L1 power control level decreases */
2575 f_trxc_fake_rssi(rxlev2dbm(0));
2576
2577 timer T4 := 6.0;
2578 T4.start;
2579 alt {
2580 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002581 /* Update sent MS power to follow what BTS requests */
2582 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2583 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002584 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002585 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002586 T4.stop;
2587 setverdict(pass, "Power level in L1 decreased/increased as expected");
2588 }
2589 [] L1CTL.receive { repeat; }
2590 [] T4.timeout {
2591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2592 "Power Level in L1 header has not decreased sufficiently");
2593 }
2594 }
2595
2596 f_rsl_chan_deact();
2597 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2598
2599}
2600
2601/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002602private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002603 var uint5_t pwr_var := 7;
2604 var L1ctlDlMessage l1_dl;
2605
2606 /* set a low value to ensure power increases */
2607 f_trxc_fake_rssi(rxlev2dbm(10));
2608 f_l1_tune(L1CTL);
2609 RSL.clear;
2610
2611 var RSL_IE_List addl_ies;
2612 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2613
2614 addl_ies := {
2615 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2616 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2617 };
2618
2619 /* establish with power parameters */
2620 f_est_dchan(more_ies := addl_ies);
2621
2622 timer T1 := 10.0;
2623 T1.start;
2624 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002625 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2626 /* Update sent MS power to follow what BTS requests */
2627 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2628 repeat;
2629 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002630 [] L1CTL.receive { repeat; }
2631 [] T1.timeout {
2632 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2633 setverdict(fail, "Power level in L1 header should not have changed");
2634 }
2635 }
2636 }
2637
2638 f_rsl_chan_deact();
2639 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2640
2641}
2642
2643/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002644private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002645 var L1ctlDlMessage l1_dl;
2646 var uint5_t pwr_var := 15;
2647 var uint5_t pwr_max_var := f_get_max_power_from_band();
2648
2649 /* set a low value to ensure power increases */
2650 f_trxc_fake_rssi(rxlev2dbm(10));
2651 f_l1_tune(L1CTL);
2652 RSL.clear;
2653
2654 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2655 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2656
2657 /* establish with fixed power level */
2658 f_est_dchan(more_ies :={valueof(pwr)});
2659
2660 /* check our initial power level */
2661 f_wait_for_l1_power_level(pwr_var);
2662
2663 /* update power param to enable power loop
2664 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2665 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2666
2667 /* wait, then check that our power level was reduced */
2668 timer T1 := 10.0;
2669 T1.start;
2670 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002671 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2672 /* Update sent MS power to follow what BTS requests */
2673 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2674 repeat;
2675 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002676 [] L1CTL.receive { repeat; }
2677 [] T1.timeout {
2678 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2679 if( f_power_level_is_highest_dbm(rcv) ){
2680 setverdict(pass, "Power level in L1 header reduced as expected");
2681 } else {
2682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2683 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2684 }
2685 }
2686 }
2687
2688 f_rsl_chan_deact();
2689 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2690
2691}
2692
2693/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002694private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002695 var L1ctlDlMessage l1_dl;
2696
2697 /* set a high value to ensure power decreases */
2698 f_trxc_fake_rssi(rxlev2dbm(50));
2699 f_l1_tune(L1CTL);
2700 RSL.clear;
2701
2702 var uint5_t pwr_var := 5;
2703 var uint5_t pwr_target_val := 15;
2704
2705 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2706 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2707
2708 /* establish with fixed power level */
2709 f_est_dchan(more_ies :={valueof(pwr)});
2710
2711 /* check our initial power level */
2712 f_wait_for_l1_power_level(pwr_var);
2713
2714 /* update power param to enable power loop
2715 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002716 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002717
2718 /* wait, then check that our power level was increased */
2719 timer T1 := 10.0;
2720 T1.start;
2721 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002722 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2723 /* Update sent MS power to follow what BTS requests */
2724 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2725 repeat;
2726 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002727 [] L1CTL.receive { repeat; }
2728 [] T1.timeout {
2729 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2730 setverdict(pass, "Power level in L1 header increased to lowest power value");
2731 } else {
2732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2733 "Power level in L1 header NOT increased to lowest power value");
2734 }
2735 }
2736 }
2737
2738 f_rsl_chan_deact();
2739 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2740
2741}
2742
Eric Wild095024b2019-06-17 15:08:57 +02002743/* see if we change the power level without receiving power parameters, which should not happen
2744rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002745private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002746 var L1ctlDlMessage l1_dl;
2747
2748 /* set a high value to ensure power decreases */
2749 f_trxc_fake_rssi(rxlev2dbm(50));
2750 f_l1_tune(L1CTL);
2751 RSL.clear;
2752
2753 var uint5_t pwr_var := 5;
2754
2755 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2756 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2757
2758 /* establish with fixed power level */
2759 f_est_dchan(more_ies :={valueof(pwr)});
2760
2761 /* check our initial power level */
2762 f_wait_for_l1_power_level(pwr_var);
2763
2764 /* wait, then check that our power level did not change */
2765 timer T1 := 10.0;
2766 T1.start;
2767 alt {
2768 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2769 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2771 "BS power control should not be active unless we receive a power parameters IE!");
2772 }
2773 repeat;
2774 }
2775 [] L1CTL.receive { repeat; }
2776 [] T1.timeout { setverdict(pass); }
2777 }
2778
2779 f_rsl_chan_deact();
2780 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2781
2782}
2783
Eric Wild095024b2019-06-17 15:08:57 +02002784/* see if we change the power level without receiving power parameters, which should not happen
2785ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002786private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002787 var L1ctlDlMessage l1_dl;
2788
2789 /* set a high value to ensure power decreases */
2790 f_trxc_fake_rssi(rxlev2dbm(50));
2791 f_l1_tune(L1CTL);
2792 RSL.clear;
2793
2794 var uint5_t pwr_var := 5;
2795
2796 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2797 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2798
2799 /* establish with fixed power level */
2800 f_est_dchan(more_ies :={valueof(pwr)});
2801
2802 /* check our initial power level */
2803 f_wait_for_l1_power_level(pwr_var);
2804
2805 /* pwr control without power params IE, should NOT activate MS power control*/
2806 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2807
2808 /* wait, then check that our power level did not change */
2809 timer T1 := 10.0;
2810 T1.start;
2811 alt {
2812 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2813 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2815 "BS power control should not be active unless we receive a power parameters IE!");
2816 }
2817 repeat;
2818 }
2819 [] L1CTL.receive { repeat; }
2820 [] T1.timeout { setverdict(pass); }
2821 }
2822
2823 f_rsl_chan_deact();
2824 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2825
2826}
2827
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002828private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002829 var L1ctlDlMessage l1_dl;
2830 timer T0 := 10.0;
2831 T0.start;
2832 alt {
2833 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2834 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2836 "Power level in L1 header != signaled (RSL) power level.");
2837 }
2838 }
2839 [] L1CTL.receive { repeat; }
2840 [] T0.timeout {
2841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2842 "Timeout waiting for initial power level");
2843 }
2844 }
2845 T0.stop;
2846}
2847
2848private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2849 var IntegerRecord min_dbm_level;
2850 var IntegerRecord max_dbm_level;
2851 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2852
2853 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2854 if (min_dbm_level[i] == level) {
2855 return true;
2856 }
2857 }
2858 return false;
2859}
2860
2861private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2862 var IntegerRecord min_dbm_level;
2863 var IntegerRecord max_dbm_level;
2864 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2865
2866 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2867 if (max_dbm_level[i] == level) {
2868 return true;
2869 }
2870 }
2871 return false;
2872}
2873
2874private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2875 var IntegerRecord min_dbm_level;
2876 var IntegerRecord max_dbm_level;
2877 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2878 return max_dbm_level[0];
2879}
2880
2881type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002882private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002883private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2884 // 45.005 4.1.1
2885 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2886 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2887 2, 1, 0};
2888 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2889 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2890 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2891 var IntegerRecord rv;
2892
2893 select(band){
2894 case (BtsBand_allGSM){
2895 rv := gsm_power;
2896 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2897 max_dbm_level := {2, 1, 0};
2898 }
2899 case("DCS1800"){
2900 rv := dcs_power;
2901 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2902 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2903 }
2904 case("PCS1900"){
2905 rv := pcs_power;
2906 min_dbm_level := {15};
2907 max_dbm_level := {30};
2908 }
Harald Welte194b6912020-10-11 21:01:55 +02002909 case else {
2910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2911 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002912 }
2913
2914 return rv;
2915}
2916
2917private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002918 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 +02002919}
2920
2921testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2922 var ConnHdlr vc_conn;
2923 var ConnHdlrPars pars;
2924 f_init();
2925 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2926 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2927 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2928 pars.bts0_band := f_vty_get_bts0_band();
2929 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2930 vc_conn.done;
2931 }
2932 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2934}
2935
2936testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2937 var ConnHdlr vc_conn;
2938 var ConnHdlrPars pars;
2939 f_init();
2940 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2941 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2942 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2943 pars.bts0_band := f_vty_get_bts0_band();
2944 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2945 vc_conn.done;
2946 }
2947 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2949}
2950
2951testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2952 var ConnHdlr vc_conn;
2953 var ConnHdlrPars pars;
2954 f_init();
2955 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2956 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2957 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2958 pars.bts0_band := f_vty_get_bts0_band();
2959 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2960 vc_conn.done;
2961 }
2962 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2964}
2965
2966testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2967 var ConnHdlr vc_conn;
2968 var ConnHdlrPars pars;
2969 f_init();
2970 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2971 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2972 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2973 pars.bts0_band := f_vty_get_bts0_band();
2974 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2975 vc_conn.done;
2976 }
2977 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2979}
2980
Eric Wild280ccb82019-06-17 11:11:52 +02002981testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2982 var ConnHdlr vc_conn;
2983 var ConnHdlrPars pars;
2984 f_init();
2985 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2986 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2987 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2988 pars.bts0_band := f_vty_get_bts0_band();
2989 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2990 vc_conn.done;
2991 }
2992 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2994}
2995
Eric Wild095024b2019-06-17 15:08:57 +02002996testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2997 var ConnHdlr vc_conn;
2998 var ConnHdlrPars pars;
2999 f_init();
3000 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3001 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3002 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3003 pars.bts0_band := f_vty_get_bts0_band();
3004 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3005 vc_conn.done;
3006 }
3007 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3009}
3010
Philipp Maier149c3922020-10-22 17:29:36 +02003011function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003012 var template RSL_IE_ChannelMode ch_mode;
3013 var ConnHdlr vc_conn;
3014 var ConnHdlrPars pars;
3015 f_init();
3016 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3017 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3018 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003019 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003020 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3021 pcu_comp := false, trxc_comp := true);
3022 vc_conn.done;
3023 }
3024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3025}
Philipp Maier149c3922020-10-22 17:29:36 +02003026
3027testcase TC_meas_res_speech_tchf() runs on test_CT {
3028 f_TC_meas_res_speech_tchf(false);
3029}
3030
3031testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3032 f_TC_meas_res_speech_tchf(true);
3033}
3034
3035function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003036 var template RSL_IE_ChannelMode ch_mode;
3037 var ConnHdlr vc_conn;
3038 var ConnHdlrPars pars;
3039 f_init();
3040 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3041 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3042 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003043 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003044 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3045 pcu_comp := false, trxc_comp := true);
3046 vc_conn.done;
3047 }
3048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3049}
Philipp Maier149c3922020-10-22 17:29:36 +02003050
3051testcase TC_meas_res_speech_tchh() runs on test_CT {
3052 f_TC_meas_res_speech_tchh(false)
3053}
3054
3055testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3056 f_TC_meas_res_speech_tchh(true)
3057}
3058
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003059testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3060 var template RSL_IE_ChannelMode ch_mode;
3061 var ConnHdlr vc_conn;
3062 var ConnHdlrPars pars;
3063 f_init();
3064 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3065 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3066 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3067 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3068 pars.l1_pars.toa256_enabled := true;
3069 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3070 pcu_comp := false, trxc_comp := true);
3071 vc_conn.done;
3072 }
3073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3074}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003075
Harald Welte70767382018-02-21 12:16:40 +01003076testcase TC_meas_res_sign_tchf() runs on test_CT {
3077 var ConnHdlr vc_conn;
3078 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003079 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003080 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003081 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003082 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3083 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003084 vc_conn.done;
3085 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003087}
3088testcase TC_meas_res_sign_tchh() runs on test_CT {
3089 var ConnHdlr vc_conn;
3090 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003091 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003092 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003093 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003094 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3095 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003096 vc_conn.done;
3097 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003099}
3100testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3101 var ConnHdlr vc_conn;
3102 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003103 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003104 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3105 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003106 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3107 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003108 vc_conn.done;
3109 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003111}
3112testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3113 var ConnHdlr vc_conn;
3114 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003115 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003116 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3117 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003118 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3119 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003120 vc_conn.done;
3121 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003123}
Harald Welte685d5982018-02-27 20:42:05 +01003124testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3125 var ConnHdlr vc_conn;
3126 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003127 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003128 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3129 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003130 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003131 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003132 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3133 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003134 vc_conn.done;
3135 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003137}
3138
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003139/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3140 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003141private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003142 var L1ctlDlMessage l1_dl;
3143 var RSL_IE_MS_Power ms_power;
3144 var RSL_Message rsl;
3145 var uint5_t power_level := 0;
3146
3147 f_l1_tune(L1CTL);
3148 RSL.clear;
3149
3150 f_est_dchan();
3151
3152 ms_power.reserved := 0;
3153 ms_power.fpc_epc := false;
3154
3155 /* Send the first power control command. This will disable any BTS/TRX
3156 * internal power control and switch the MS (which is not in scope of
3157 * this test) to a constant power level. We start with a power level
3158 * of 0 */
3159 ms_power.power_level := power_level;
3160 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3161 RSL.send(rsl);
3162
3163 alt {
3164
3165 /* Pick all SACCH blocks for checking */
3166 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3167
3168 /* The first byte of the L1 header contains the power level.
3169 * The reserved bits and the fpc bit is set to 0, so we may
3170 * compare directly. */
3171 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3172 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3173 }
3174
3175 /* Signal a new power level via RSL for the next turn. */
3176 if (power_level < 31) {
3177 power_level := power_level + 1;
3178 ms_power.power_level := power_level;
3179 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3180 RSL.send(rsl);
3181 repeat;
3182 }
3183
3184 }
3185
3186 /* Ignore all other blocks */
3187 [] L1CTL.receive { repeat; }
3188
3189 }
3190
3191 f_rsl_chan_deact();
3192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3193
3194 setverdict(pass);
3195}
3196
3197testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3198 var ConnHdlr vc_conn;
3199 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003200 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003201
3202 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3203 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3204 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3205 vc_conn.done;
3206 }
3207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3208}
Harald Welte70767382018-02-21 12:16:40 +01003209
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003210/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003211TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003212private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003213 var L1ctlDlMessage l1_dl;
3214 var uint5_t ta_to_test := 16;
3215
3216
3217 f_l1_tune(L1CTL);
3218 RSL.clear;
3219
3220 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003221 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003222
3223 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3224
3225
3226 alt {
3227
3228 /* Pick all SACCH blocks for checking */
3229 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3230
3231 /* The second byte of the L1 header contains the TA. */
3232 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3233 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3234 }
3235
3236 }
3237
3238 /* Ignore all other blocks */
3239 [] L1CTL.receive { repeat; }
3240
3241 }
3242
3243 f_rsl_chan_deact();
3244 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3245
3246 setverdict(pass);
3247}
3248
3249testcase TC_rsl_chan_initial_ta() runs on test_CT {
3250 var ConnHdlr vc_conn;
3251 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003252 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003253 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003254 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3255 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003256 vc_conn.done;
3257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3258}
3259
Eric Wilde57e1a62019-05-28 13:30:55 +02003260/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003261private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003262 var L1ctlDlMessage l1_dl;
3263 var uint5_t ms_power_level := 7;
3264
3265 var RSL_IE_MS_Power ms_power;
3266 ms_power.reserved := 0;
3267 ms_power.fpc_epc := false;
3268 ms_power.power_level := ms_power_level;
3269
3270 f_l1_tune(L1CTL);
3271 RSL.clear;
3272
3273 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3274
3275 timer T := 1.0;
3276 T.start;
3277 alt {
3278 /* Pick all SACCH blocks for checking */
3279 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3280 /* The first byte of the L1 header contains the power level.. */
3281 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3282 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3283 }
3284 }
3285 /* Ignore all other blocks */
3286 [] L1CTL.receive { repeat; }
3287 [] T.timeout {
3288 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3289 }
3290 }
3291
3292 f_rsl_chan_deact();
3293 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3294 setverdict(pass);
3295}
3296
3297testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3298 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3299 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3300}
3301
Harald Welte0472ab42018-03-12 15:02:26 +01003302/* 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 +01003303private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003305 RSL.clear;
3306
3307 f_est_dchan();
3308 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003309 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003310
3311 timer T := 40.0;
3312 T.start;
3313 alt {
3314 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3315 setverdict(pass)
3316 }
3317 [] RSL.receive { repeat };
3318 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003320 }
3321 }
3322 f_rsl_chan_deact();
3323}
3324testcase TC_conn_fail_crit() runs on test_CT {
3325 var ConnHdlr vc_conn;
3326 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003327 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003328 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3329 pars.t_guard := 60.0;
3330 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3331 vc_conn.done;
3332}
3333
Harald Welte93640c62018-02-25 16:59:33 +01003334/***********************************************************************
3335 * Paging
3336 ***********************************************************************/
3337
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003338private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003339 if (tmsi == 'FFFFFFFF'O) {
3340 return true;
3341 } else {
3342 return false;
3343 }
3344}
Harald Welte70767382018-02-21 12:16:40 +01003345
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003346private type record allowedFn { integer frame_nr }
3347private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3348private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3349private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3350private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3351private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3352private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3353private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3354private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3355private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003356{
3357 var integer frame_nr_51;
3358 frame_nr_51 := frame_nr mod 51
3359
3360 var allowedFn fn_check;
3361 fn_check.frame_nr := frame_nr_51;
3362
3363 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003365 return;
3366 }
3367
3368 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3369 return;
3370 }
3371 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3372 return;
3373 }
3374 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3375 return;
3376 }
3377 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3378 return;
3379 }
3380 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3381 return;
3382 }
3383 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3384 return;
3385 }
3386 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3387 return;
3388 }
3389 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3390 return;
3391 }
3392
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003394 return;
3395}
3396
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003397private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3398 inout integer num_paging_rcv_ids,
3399 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003400runs on test_CT {
3401 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003402 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003403 repeat;
3404 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003405 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003406 var octetstring without_plen :=
3407 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3408 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003409
3410 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3411
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003412 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3413 /* Ignore empty RR Paging Request (PCH filling) messages.
3414 * TODO: does it make sense to count them? */
3415 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003416 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3417 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003418 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003419 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3420 }
3421 } else if (match(rr, tr_PAGING_REQ2)) {
3422 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3423 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3424 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3425 }
3426 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3427 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3428 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003429 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003430 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3431 }
3432 } else if (match(rr, tr_PAGING_REQ3)) {
3433 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3434 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3435 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3436 }
3437 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3438 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3439 }
3440 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3441 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3442 }
3443 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3444 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3445 }
3446 }
3447 repeat;
3448 }
3449}
3450
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003451private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003452 boolean combined_ccch,
3453 integer bs_ag_blks_res,
3454 float load_factor,
3455 boolean exp_load_ind,
3456 boolean exp_overload,
3457 boolean use_tmsi
3458}
3459
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003460private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003461 integer num_paging_sent,
3462 integer num_paging_rcv_msgs,
3463 integer num_paging_rcv_ids,
3464 integer num_overload
3465}
3466
Harald Welte68e495b2018-02-25 00:05:57 +01003467/* Helper function for paging related testing */
3468private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003469 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003470 f_init_l1ctl();
3471 f_l1_tune(L1CTL);
3472
3473 var PagingTestState st := {
3474 num_paging_sent := 0,
3475 num_paging_rcv_msgs := 0,
3476 num_paging_rcv_ids := 0,
3477 num_overload := 0
3478 };
3479
3480 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3481 var float max_pch_imsi_per_sec;
3482 if (cfg.use_tmsi) {
3483 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3484 } else {
3485 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3486 }
3487 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3488 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003489 var float time_total := 20.0;
3490 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3491 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003492
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003493 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3494 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003495
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003496 timer T_itv := 0.0;
3497 T_itv.start;
3498 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003499 alt {
3500 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003501 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003502 st.num_overload := st.num_overload + 1;
3503 repeat;
3504 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003505 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003507 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003508 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003509 log("Rx LOAD_IND");
3510 /* FIXME: analyze/verify interval + contents */
3511 repeat;
3512 }
3513 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003514 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003515 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003516 [] T_itv.timeout {
3517 /* Send paging cmds based on elapsed time */
3518 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3519 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003520 var MobileIdentityV mi;
3521
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003522 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003523 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003524 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003525 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003526 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003527 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003528
3529 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003530 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 +02003531
3532 st.num_paging_sent := st.num_paging_sent + 1;
3533 }
3534 if (st.num_paging_sent < pkt_total) {
3535 /* Wait for interval to next PAGING COMMAND */
3536 var float time_now := T_total.read;
3537 var float next_sched := int2float(st.num_paging_sent)*interval;
3538 if (next_sched > time_now) {
3539 T_itv.start(next_sched - time_now);
3540 } else {
3541 T_itv.start(0.0);
3542 }
3543 } else {
3544 /* We are done, no need to keep counting */
3545 T_total.stop;
3546 }
3547 }
3548 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003549 }
3550 }
3551
3552 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3553 timer T_wait := 18.0;
3554 T_wait.start;
3555 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003556 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003557 [] L1CTL.receive { repeat; }
3558 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003559 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3560 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003561 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003563 }
Harald Welte68e495b2018-02-25 00:05:57 +01003564 }
3565
3566 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3567 " rcvd_ids=", st.num_paging_rcv_ids);
3568 return st;
3569}
3570
3571/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3572 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3573 * - that CCCH LOAD IND (PCH) are being generated
3574 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3575testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003576 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003577 var PagingTestCfg cfg := {
3578 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003579 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003580 load_factor := 0.8,
3581 exp_load_ind := true,
3582 exp_overload := false,
3583 use_tmsi := false
3584 };
3585 var PagingTestState st := f_TC_paging(cfg);
3586 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3588 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003589 } else {
3590 setverdict(pass);
3591 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003593}
3594
3595/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3596 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3597 * - that CCCH LOAD IND (PCH) are being generated
3598 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3599testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003600 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003601 var PagingTestCfg cfg := {
3602 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003603 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003604 load_factor := 0.8,
3605 exp_load_ind := true,
3606 exp_overload := false,
3607 use_tmsi := true
3608 };
3609 var PagingTestState st := f_TC_paging(cfg);
3610 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3612 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003613 } else {
3614 setverdict(pass);
3615 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003617}
3618
3619/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3620 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3621 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3622 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3623testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003624 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003625 var PagingTestCfg cfg := {
3626 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003627 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003628 load_factor := 2.0,
3629 exp_load_ind := true,
3630 exp_overload := true,
3631 use_tmsi := false
3632 };
3633 var PagingTestState st := f_TC_paging(cfg);
3634 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3635 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003636 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003637 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003638 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 +01003639 } else {
3640 setverdict(pass);
3641 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003643}
3644
3645/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3646 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3647 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3648 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3649testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003650 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003651 var PagingTestCfg cfg := {
3652 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003653 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003654 load_factor := 2.0,
3655 exp_load_ind := true,
3656 exp_overload := true,
3657 use_tmsi := true
3658 };
3659 var PagingTestState st := f_TC_paging(cfg);
3660 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3661 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003662 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003663 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003664 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 +01003665 } else {
3666 setverdict(pass);
3667 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003669}
3670
3671
Harald Welte93640c62018-02-25 16:59:33 +01003672/***********************************************************************
3673 * Immediate Assignment / AGCH
3674 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003675private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003676 len := 0,
3677 ma := ''B
3678}
Harald Welte93640c62018-02-25 16:59:33 +01003679
Harald Weltee8d750e2018-06-10 21:41:35 +02003680private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3681 return int2str(num_tx) & " sent, "
3682 & int2str(num_rx) & " received, "
3683 & int2str(num_del) & " deleted";
3684}
3685
3686private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3687 var L1ctlDlMessage l1_dl;
3688 timer T := 10.0;
3689 var integer num_tx := 0;
3690 var integer num_rx := 0;
3691 var integer num_del := 0;
3692 var charstring res_str;
3693 var float rx_ratio;
3694
Harald Welte10474062019-05-30 16:48:17 +02003695 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003696 f_init_l1ctl();
3697 f_l1_tune(L1CTL);
3698
3699 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003700 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003701 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3702 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003703 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003704 num_tx := num_tx+1;
3705 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003706 }
3707 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003708 T.start;
3709 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003710 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003711 num_del := num_del+1;
3712 repeat;
3713 }
3714 [] RSL_CCHAN.receive {
3715 repeat;
3716 }
3717 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003718 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3719 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3720 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003721 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003722 } else {
3723 num_rx := num_rx+1;
3724 }
3725 repeat;
3726 }
3727 [] L1CTL.receive { repeat; }
3728 [] T.timeout { }
3729 }
3730 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3731 log("AGCH test: " & res_str);
3732 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003734 }
3735 rx_ratio := int2float(num_rx) / int2float(num_tx);
3736 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003737 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 +02003738 } else {
3739 setverdict(pass);
3740 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003742}
3743
Harald Weltee8d750e2018-06-10 21:41:35 +02003744/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3745testcase TC_imm_ass_1000_20ms() runs on test_CT {
3746 f_TC_imm_ass(1000, 0.02, 0.25);
3747}
3748
3749/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3750testcase TC_imm_ass_200_0ms() runs on test_CT {
3751 f_TC_imm_ass(200, 0.0, 0.05);
3752}
3753
3754/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3755testcase TC_imm_ass_200_76ms() runs on test_CT {
3756 f_TC_imm_ass(150, 0.076, 1.00);
3757}
3758
3759
3760
Harald Welte48494ca2018-02-25 16:59:50 +01003761/***********************************************************************
3762 * BCCH
3763 ***********************************************************************/
3764
3765/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003766private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003767 GsmFrameNumber frame_number,
3768 SystemInformation si
3769}
3770
3771/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003772private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003773
3774/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003775private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003776
3777/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003778private function f_si_vecslot_contains(SystemInformationVector arr,
3779 RrMessageType key,
3780 boolean bcch_ext := false)
3781return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003782 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3783 var integer fn_mod51 := arr[i].frame_number mod 51;
3784 if (not bcch_ext and fn_mod51 == 2 or
3785 bcch_ext and fn_mod51 == 6) {
3786 if (arr[i].si.header.message_type == key) {
3787 return true;
3788 }
3789 }
3790 }
3791 return false;
3792}
3793
3794/* 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 +07003795private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3796 integer tc, RrMessageType key,
3797 boolean ext_bcch := false)
3798{
Harald Welte48494ca2018-02-25 16:59:50 +01003799 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003801 }
3802}
3803
3804/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003805private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3806 RrMessageType key)
3807return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003808 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3809 if (f_si_vecslot_contains(arr[tc], key) or
3810 f_si_vecslot_contains(arr[tc], key, true)) {
3811 return true;
3812 }
3813 }
3814 return false;
3815}
3816
3817/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003818private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3819 RrMessageType key,
3820 boolean bcch_ext := false,
3821 integer n := 1, integer m := 4)
3822return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003823 var integer count := 0;
3824 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3826 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003827 }
3828 for (var integer i:= 0; i < m; i := i + 1) {
3829 var integer fn_mod51 := arr[i].frame_number mod 51;
3830 if (not bcch_ext and fn_mod51 == 2 or
3831 bcch_ext and fn_mod51 == 6) {
3832 if (arr[i].si.header.message_type == key) {
3833 count := count + 1;
3834 }
3835 }
3836 }
3837 if (count >= n) {
3838 return true;
3839 } else {
3840 return false;
3841 }
3842}
3843
3844/* 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 +07003845private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3846 integer tc, RrMessageType key,
3847 boolean ext_bcch := false,
3848 integer n, integer m)
3849{
Harald Welte48494ca2018-02-25 16:59:50 +01003850 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003852 }
3853}
3854
3855/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003856private function f_si_vecslot_contains_only(SystemInformationVector arr,
3857 RrMessageType key,
3858 boolean bcch_ext := false)
3859return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003860 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3861 var integer fn_mod51 := arr[i].frame_number mod 51;
3862 if (not bcch_ext and fn_mod51 == 2 or
3863 bcch_ext and fn_mod51 == 6) {
3864 if (arr[i].si.header.message_type != key) {
3865 return false;
3866 }
3867 }
3868 }
3869 return true;
3870}
3871
3872/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003873private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3874 integer tc, RrMessageType key,
3875 boolean ext_bcch := false)
3876{
Harald Welte48494ca2018-02-25 16:59:50 +01003877 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003879 }
3880}
3881
3882/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003883private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003884 boolean bcch_extended,
3885 boolean si1_present,
3886 boolean si2bis_present,
3887 boolean si2ter_present,
3888 boolean si2quater_present,
3889 boolean si7_present,
3890 boolean si8_present,
3891 boolean si9_present,
3892 boolean si13_present,
3893 boolean si13alt_present,
3894 boolean si15_present,
3895 boolean si16_present,
3896 boolean si17_present,
3897 boolean si2n_present,
3898 boolean si21_present,
3899 boolean si22_present
3900}
3901
3902/* 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 +07003903private function f_validate_si_scheduling(SystemInformationConfig cfg,
3904 SystemInformationVectorPerTc si_per_tc)
3905{
Harald Welte48494ca2018-02-25 16:59:50 +01003906 var integer i;
3907 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3908 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003910 }
3911 }
3912 if (cfg.si1_present) {
3913 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3914 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3915 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3916 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3917 /* make sure *ALL* contain SI1 */
3918 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3919 }
3920 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3921 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3922 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3923 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3924 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3925 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3926
3927 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3928 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3929 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3930 * consecutive occurrences of TC = 4. */
3931 if (cfg.si2bis_present and not cfg.si2ter_present) {
3932 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3933 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3934 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3935 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3936 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3937 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3938 }
3939
3940 if (cfg.si7_present or cfg.si8_present) {
3941 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3942 * if System Information type 4 does not contain all information needed for cell
3943 * selection and reselection. */
3944 if (not cfg.bcch_extended) {
3945 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3946 }
3947 if (cfg.si7_present) {
3948 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3949 }
3950 if (cfg.si8_present) {
3951 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3952 }
3953 }
3954
3955 if (cfg.si2quater_present) {
3956 /* iii) System information type 2 quater is sent if needed, as determined by the system
3957 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3958 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3959 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3960 * within any of 4 consecutive occurrences of TC = 5. */
3961 if (not (cfg.bcch_extended)) {
3962 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3963 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3964 } else {
3965 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3966 }
3967 } else {
3968 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3969 }
3970 }
3971 if (cfg.si9_present) {
3972 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3973 * in system information type 3 as defined in 3GPP TS 44.018. */
3974 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3975 }
3976 if (cfg.si13_present) {
3977 /* vii) System Information type 13 is only related to the GPRS service. System Information
3978 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3979 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3980 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3981 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3982 * within any of 4 consecutive occurrences of TC=4. */
3983 if (not cfg.bcch_extended) {
3984 log("not-bccch-extended");
3985 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3986 } else {
3987 log("bccch-extended");
3988 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3989 }
3990 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003992 }
3993 }
3994 if (cfg.si16_present or cfg.si17_present) {
3995 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3996 * should not be sent in a cell where network sharing is used (see rule xv). */
3997 if (cfg.si22_present) {
3998 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3999 }
4000 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004002 }
4003 if (not cfg.bcch_extended) {
4004 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4005 }
4006 if (cfg.si16_present) {
4007 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4008 }
4009 if (cfg.si17_present) {
4010 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4011 }
4012 }
4013
4014 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4015 * broadcast information. The frequency with which they are sent is determined by the
4016 * system operator. System Information type 9 identifies the scheduling of System
4017 * Information type 18 and 20 messages. */
4018
4019 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4020 * Information Type 19 is present, then its scheduling shall be indicated in System
4021 * Information Type 9. */
4022
4023 if (cfg.si15_present) {
4024 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4025 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4026 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4027 * 4 consecutive occurrences of TC = 1. */
4028 if (not cfg.bcch_extended) {
4029 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4030 } else {
4031 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4032 }
4033 }
4034 if (cfg.si13alt_present) {
4035 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4036 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4037 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4038 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4039 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4040 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4041 * of TC = 4. */
4042 if (cfg.si13_present) {
4043 testcase.stop("Error: Cannot have SI13alt and SI13");
4044 }
4045 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004047 }
4048 if (not cfg.bcch_extended) {
4049 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4050 } else {
4051 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4052 }
4053 }
4054 if (cfg.si2n_present) {
4055 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4056 * as determined by the system operator. In the case that the message is sent on the
4057 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4058 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4059 * consecutive occurrences of TC = 4. */
4060 if (not cfg.bcch_extended) {
4061 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4062 } else {
4063 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4064 }
4065 }
4066 if (cfg.si21_present) {
4067 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4068 * determined by the system operator. If Extended Access Barring is in use in the cell
4069 * then this message is sent at least once within any of 4 consecutive occurrences of
4070 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4071 * cell then this message shall only be sent on BCCH Ext. */
4072 if (not cfg.bcch_extended) {
4073 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4074 } else {
4075 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4076 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004078 }
4079 }
4080 }
4081 if (cfg.si22_present) {
4082 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4083 * should not be sent in a cell where SoLSA is used (see rule viii). System
4084 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4085 * =2 and TC=6. */
4086 if (cfg.si16_present or cfg.si17_present) {
4087 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4088 }
4089 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4090 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004092 }
4093 if (not cfg.bcch_extended) {
4094 testcase.stop("Error: SI22 requires BCCH Extd!");
4095 } else {
4096 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4097 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4098 }
4099 }
4100}
4101
4102/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004103private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4104return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004105 timer T := duration;
4106 var SystemInformationVectorPerTc si_per_tc;
4107 var L1ctlDlMessage l1_dl;
4108
4109 /* initialize all per-TC vectors empty */
4110 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4111 si_per_tc[i] := {};
4112 }
4113
4114 /* flush all previous L1 queued msgs */
4115 pt.clear;
4116
4117 T.start;
4118 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004119 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004120 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4121 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4122 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004123 repeat;
4124 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004125
Harald Welte48494ca2018-02-25 16:59:50 +01004126 var integer tc := f_gsm_compute_tc(sig.frame_number);
4127 log("SI received at TC=", tc, ": ", sig.si);
4128 /* append to the per-TC bucket */
4129 si_per_tc[tc] := si_per_tc[tc] & { sig };
4130 repeat;
4131 }
4132 [] pt.receive { repeat; }
4133 [] T.timeout { }
4134 }
4135
4136 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4137 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4138 }
4139 log("si_per_tc=", si_per_tc);
4140 return si_per_tc;
4141}
4142
4143/* helper function: Set given SI via RSL + validate scheduling.
4144 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004145private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004146 var SystemInformationVectorPerTc si_per_tc;
4147 f_init_l1ctl();
4148 f_l1_tune(L1CTL);
4149
4150 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004151 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004152 f_validate_si_scheduling(si_cfg, si_per_tc);
4153
4154 setverdict(pass);
4155}
4156
4157testcase TC_si_sched_default() runs on test_CT {
4158 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004159 /* 2+3+4 are mandatory and set in f_init() */
4160 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004162}
4163
4164testcase TC_si_sched_1() runs on test_CT {
4165 f_init();
4166 si_cfg.si1_present := true;
4167 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004168 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004170}
4171
4172testcase TC_si_sched_2bis() runs on test_CT {
4173 f_init();
4174 si_cfg.si2bis_present := true;
4175 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4176 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004178}
4179
4180testcase TC_si_sched_2ter() runs on test_CT {
4181 f_init();
4182 si_cfg.si2ter_present := true;
4183 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4184 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004186}
4187
4188testcase TC_si_sched_2ter_2bis() runs on test_CT {
4189 f_init();
4190 si_cfg.si2bis_present := true;
4191 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4192 si_cfg.si2ter_present := true;
4193 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4194 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004196}
4197
4198testcase TC_si_sched_2quater() runs on test_CT {
4199 f_init();
4200 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004201 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004202 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004203 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004204}
4205
4206testcase TC_si_sched_13() runs on test_CT {
4207 f_init();
4208 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004209 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004210 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004212}
4213
4214testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4215 f_init();
4216 si_cfg.si2bis_present := true;
4217 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4218 si_cfg.si2ter_present := true;
4219 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4220 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004221 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004222 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004223 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004224 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004226}
4227
4228
Harald Welte68e495b2018-02-25 00:05:57 +01004229testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004230 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004231 /* FIXME: enable / disable individual BCCH info */
4232 //ts_RSL_BCCH_INFO(si_type, info);
4233 /* expect no ERROR REPORT after either of them *
4234 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004236}
4237
Harald Welte93640c62018-02-25 16:59:33 +01004238/***********************************************************************
4239 * Low-Level Protocol Errors / ERROR REPORT
4240 ***********************************************************************/
4241
Harald Welte01d982c2018-02-25 01:31:40 +01004242private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4243 timer T := 5.0;
4244 T.start;
4245 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004246 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004247 setverdict(pass);
4248 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004249 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004251 }
4252 [] RSL_CCHAN.receive {
4253 repeat;
4254 }
4255 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004257 }
4258 }
4259}
4260
4261/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4262testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004263 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004264 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4265 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004266 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004267
4268 f_exp_err_rep(RSL_ERR_PROTO);
4269}
4270
4271/* Provoke a mandatory IE error and match on ERROR REPORT */
4272testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004273 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004274
4275 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4276 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004277 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004278
4279 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4280}
4281
4282/* Provoke an IE content error and match on ERROR REPORT */
4283testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004284 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004285 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4286 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004287 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004288
4289 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4290}
4291
Harald Welteee25aae2019-05-19 14:32:37 +02004292/* attempt to activate channel with wrong RSL Message Discriminator IE */
4293function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4294 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4295 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4296 RSL.send(rsl);
4297 f_rslem_unregister(0, g_chan_nr);
4298}
4299testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4300 var ConnHdlr vc_conn;
4301 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4302
Harald Welte10474062019-05-30 16:48:17 +02004303 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004304
4305 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4306 vc_conn.done;
4307 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4308
4309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4310}
4311
4312/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004313private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004314 var template (value) RSL_Message rsl_tx;
4315 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4316 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4317 RSL.send(rsl_tx);
4318 f_rslem_unregister(0, g_chan_nr);
4319}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004320private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004321 var template (value) RSL_Message rsl_tx;
4322 /* we first have to activate the dedicated channel */
4323 f_rsl_chan_act(g_pars.chan_mode);
4324 /* ... to then send an invalid RLL message */
4325 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4326 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4327 RSL.send(rsl_tx);
4328 f_rslem_unregister(0, g_chan_nr);
4329}
4330testcase TC_err_rep_wrong_msg_type() 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 var template (value) RSL_Message rsl_tx;
4334
Harald Welte10474062019-05-30 16:48:17 +02004335 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004336
4337 /* Common Channel with wrong message type */
4338 RSL_CCHAN.clear;
4339 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4340 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004341 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004342 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4343
4344 /* TRX Management */
4345 RSL_CCHAN.clear;
4346 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4347 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004348 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004349 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4350
4351 /* Dedicated Channel */
4352 RSL_CCHAN.clear;
4353 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4354 vc_conn.done;
4355 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4356
4357 /* RLL */
4358 RSL_CCHAN.clear;
4359 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4360 vc_conn.done;
4361 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4362}
4363
4364/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004365private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004366 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4367 f_rslem_unregister(0, g_chan_nr);
4368}
4369testcase TC_err_rep_wrong_sequence() runs on test_CT {
4370 var ConnHdlr vc_conn;
4371 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4372
Harald Welte10474062019-05-30 16:48:17 +02004373 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004374
4375 RSL_CCHAN.clear;
4376 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4377 vc_conn.done;
4378 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4379}
4380
Harald Welte93640c62018-02-25 16:59:33 +01004381/***********************************************************************
4382 * IPA CRCX/MDCX/DLCS media stream handling
4383 ***********************************************************************/
4384
Harald Weltea871a382018-02-25 02:03:14 +01004385/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004386private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004387 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4388 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004389}
4390testcase TC_ipa_dlcx_not_active() runs on test_CT {
4391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004392 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004393 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4394 vc_conn.done;
4395}
Harald Welte68e495b2018-02-25 00:05:57 +01004396
Harald Weltea3f1df92018-02-25 12:49:55 +01004397/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004398private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004399 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4400 "IPA CRCX ACK");
4401 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4402 "IPA CRCX NACK");
4403}
4404testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4405 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004406 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004407 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4408 vc_conn.done;
4409}
4410
4411/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004412private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004413 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4414 "IPA CRCX ACK");
4415 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4416 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4417 var uint7_t rtp_pt2 := f_rnd_int(127);
4418 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4419 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4420 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4421 "IPA MDCX ACK");
4422 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4423 "IPA DLCX ACK");
4424}
4425testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4426 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004427 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004428 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4429 vc_conn.done;
4430}
4431
Harald Welte3ae11da2018-02-25 13:36:06 +01004432/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004433private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004434 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4435 "IPA CRCX ACK");
4436 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4437 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4438 var uint7_t rtp_pt2 := f_rnd_int(127);
4439 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4440 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4441 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4442 "IPA MDCX ACK");
4443 /* Second MDCX */
4444 remote_ip := f_rnd_int(c_UINT32_MAX);
4445 remote_port := f_rnd_int(c_UINT16_MAX);
4446 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4447 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4448 "IPA MDCX ACK");
4449 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4450 "IPA DLCX ACK");
4451}
4452testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004454 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004455 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4456 vc_conn.done;
4457}
4458
Harald Welte9912eb52018-02-25 13:30:15 +01004459/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004460private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004461 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4462 "IPA CRCX NACK");
4463}
4464testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4465 var ConnHdlrPars pars;
4466 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004467 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004468
4469 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4470 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4471 vc_conn.done;
4472
4473 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4474 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4475 vc_conn.done;
4476}
4477
Harald Weltea3f1df92018-02-25 12:49:55 +01004478
Harald Welte883340c2018-02-28 18:59:29 +01004479/***********************************************************************
4480 * PCU Socket related tests
4481 ***********************************************************************/
4482
Harald Welte07bd2d22019-05-25 11:03:30 +02004483/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004484friend 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 +01004485runs on test_CT {
4486 timer T := 3.0;
4487
4488 /* we don't expect any RTS.req before PDCH are active */
4489 T.start;
4490 alt {
4491 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004493 }
4494 [] PCU.receive { repeat; }
4495 [] T.timeout { }
4496 }
4497
4498 /* Send PDCH activate request for known PDCH timeslot */
4499 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4500
4501 /* we now expect RTS.req for this timeslot (only) */
4502 T.start;
4503 alt {
4504 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4505 setverdict(pass);
4506 }
4507 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4508 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004510 }
4511 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004513 }
4514 [] PCU.receive { repeat; }
4515 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004517 }
4518 [not exp_success] T.timeout {
4519 setverdict(pass);
4520 }
4521 }
4522}
4523
Harald Welte07bd2d22019-05-25 11:03:30 +02004524/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004525friend 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 +01004526runs on test_CT {
4527 timer T := 3.0;
4528
4529 /* Send PDCH activate request for known PDCH timeslot */
4530 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 +02004531 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4532 * when it will actually have been executed in the BTS */
4533 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004534 PCU.clear;
4535 /* we now expect no RTS.req for this timeslot */
4536 T.start;
4537 alt {
4538 [] 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 +02004539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004540 }
4541 [] PCU.receive { repeat; }
4542 [] T.timeout {
4543 setverdict(pass);
4544 }
4545 }
4546}
4547
Harald Weltead033dc2019-05-25 17:28:16 +02004548friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004549 f_init();
4550 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4551}
4552
Harald Welte883340c2018-02-28 18:59:29 +01004553/* PDCH activation via PCU socket; check for presence of RTS.req */
4554testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004555 f_init_pcu_test();
4556
Harald Welte883340c2018-02-28 18:59:29 +01004557 f_TC_pcu_act_req(0, 0, 7, true);
4558}
4559
4560/* PDCH activation via PCU socket on non-PDCU timeslot */
4561testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004562 f_init_pcu_test();
4563
Harald Welte883340c2018-02-28 18:59:29 +01004564 f_TC_pcu_act_req(0, 0, 1, false);
4565}
4566
4567/* PDCH activation via PCU socket on wrong BTS */
4568testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004569 f_init_pcu_test();
4570
Harald Welte883340c2018-02-28 18:59:29 +01004571 f_TC_pcu_act_req(23, 0, 7, false);
4572}
4573
4574/* PDCH activation via PCU socket on wrong TRX */
4575testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004576 f_init_pcu_test();
4577
Harald Welte883340c2018-02-28 18:59:29 +01004578 f_TC_pcu_act_req(0, 23, 7, false);
4579}
4580
4581/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4582testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004583 f_init_pcu_test();
4584
Harald Welte883340c2018-02-28 18:59:29 +01004585 /* Activate PDCH */
4586 f_TC_pcu_act_req(0, 0, 7, true);
4587 f_sleep(1.0);
4588 /* and De-Activate again */
4589 f_TC_pcu_deact_req(0, 0, 7);
4590}
4591
4592/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4593testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004594 f_init_pcu_test();
4595
Harald Welte883340c2018-02-28 18:59:29 +01004596 f_TC_pcu_deact_req(0, 0, 1);
4597}
4598
4599/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4600testcase TC_pcu_ver_si13() runs on test_CT {
4601 const octetstring si13 := '00010203040506070909'O;
4602 var PCUIF_send_data sd;
4603 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004604 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004605
4606 /* Set SI13 via RSL */
4607 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004608
Harald Welte883340c2018-02-28 18:59:29 +01004609 T.start;
4610 alt {
4611 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4612 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4613 setverdict(pass);
4614 } else {
4615 repeat;
4616 }
4617 }
4618 [] PCU.receive { repeat; }
4619 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004621 }
4622 }
4623}
4624
4625private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4626
4627/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004628friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004629 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4630runs on test_CT
4631{
4632 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4633 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4634}
4635
4636/* 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 +02004637friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4638 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004639runs on test_CT
4640{
4641 var PCUIF_send_data sd;
4642
4643 timer T := 3.0;
4644 T.start;
4645 alt {
4646 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4647 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4648 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4649 sd.data.u.rts_req.fn, sapi, data);
4650 }
4651 [] PCU.receive { repeat; }
4652 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004654 }
4655 }
4656}
4657
4658/* Send DATA.req on invalid BTS */
4659testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004660 var TfiUsfArr tua := f_TfiUsfArrInit();
4661 var octetstring data := '0000'O & f_rnd_octstring(21);
4662
4663 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004664
Harald Welte883340c2018-02-28 18:59:29 +01004665 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004666 f_TfiUsfArrSet(tua, 7, 0);
4667 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4668 f_sleep(1.0);
4669
4670 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004671}
4672
4673/* Send DATA.req on invalid TRX */
4674testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004675 var TfiUsfArr tua := f_TfiUsfArrInit();
4676 var octetstring data := '0000'O & f_rnd_octstring(21);
4677
4678 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004679
Harald Welte883340c2018-02-28 18:59:29 +01004680 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004681 f_TfiUsfArrSet(tua, 7, 0);
4682 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4683 f_sleep(1.0);
4684
4685 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004686}
4687
4688/* Send DATA.req on invalid timeslot */
4689testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004690 var TfiUsfArr tua := f_TfiUsfArrInit();
4691 var octetstring data := '0000'O & f_rnd_octstring(21);
4692
4693 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004694
Harald Welte883340c2018-02-28 18:59:29 +01004695 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004696 f_TfiUsfArrSet(tua, 7, 0);
4697 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4698 f_sleep(1.0);
4699
4700 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004701}
4702
4703/* Send DATA.req on timeslot that hasn't been activated */
4704testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004705 var TfiUsfArr tua := f_TfiUsfArrInit();
4706 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004707
Harald Welte7162a612019-05-26 12:56:09 +02004708 f_virtphy_common();
4709
4710 f_TfiUsfArrSet(tua, 7, 0);
4711 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4712 f_sleep(1.0);
4713
4714 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004715}
4716
Harald Weltead033dc2019-05-25 17:28:16 +02004717private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004718 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4719 boolean wait_rts := true)
4720runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004721 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004722 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004723
4724 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004725 if (wait_rts) {
4726 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4727 } else {
4728 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4729 }
Harald Weltead033dc2019-05-25 17:28:16 +02004730
4731 T.start;
4732 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004733 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004734 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4735 setverdict(pass);
4736 }
Harald Welte7162a612019-05-26 12:56:09 +02004737 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4738 setverdict(fail, "Received unexpected ", rx_dl);
4739 }
Harald Weltead033dc2019-05-25 17:28:16 +02004740 [] L1CTL.receive {
4741 repeat;
4742 }
Harald Welte7162a612019-05-26 12:56:09 +02004743 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004744 setverdict(fail, "Timeout waiting for ", data);
4745 }
Harald Welte7162a612019-05-26 12:56:09 +02004746 [not expect_data] T.timeout {
4747 setverdict(pass);
4748 }
Harald Weltead033dc2019-05-25 17:28:16 +02004749 }
4750}
4751
4752private function f_disable_dynamic_ts() runs on test_CT
4753{
4754 f_init_vty_bsc();
4755 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4756 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4757 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4758 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004759 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004760}
4761
4762private function f_virtphy_common() runs on test_CT {
4763 f_disable_dynamic_ts();
4764 f_init_l1ctl();
4765 f_l1_tune(L1CTL);
4766}
4767
4768testcase TC_pcu_data_req_pdtch() runs on test_CT {
4769 var TfiUsfArr tua := f_TfiUsfArrInit();
4770 var octetstring data := '0000'O & f_rnd_octstring(21);
4771
4772 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004773
Harald Welte883340c2018-02-28 18:59:29 +01004774 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004775 f_TfiUsfArrSet(tua, 7, 0);
4776 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4777 f_sleep(1.0);
4778
4779 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004780}
4781
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004782/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004783testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004784 var TfiUsfArr tua := f_TfiUsfArrInit();
4785 var octetstring data := '0000'O & f_rnd_octstring(21);
4786
4787 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004788
Harald Welte883340c2018-02-28 18:59:29 +01004789 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004790 f_TfiUsfArrSet(tua, 7, 0);
4791 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4792 f_sleep(1.0);
4793
4794 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004795}
4796
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004797private function f_TC_pcu_ptcch_ul(uint16_t ra)
4798runs on test_CT {
4799 var template PCUIF_Message pcu_rach_ind;
4800 var PCUIF_send_data sd;
4801 var GsmFrameNumber fn;
4802 timer T;
4803
4804 /* Send an Access Burst on PTCCH/U over the Um-interface */
4805 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4806 chan_nr := ts_RslChanNr_PDCH(7),
4807 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4808
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004809 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4810 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004811
4812 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4813 T.start(52.0 * 4.615 / 1000.0);
4814 alt {
4815 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4816 log("Rx an Access Burst on the PCU interface: ", sd.data);
4817 setverdict(pass);
4818 T.stop;
4819 }
4820 [] PCU.receive { repeat; }
4821 [] T.timeout {
4822 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4823 /* Keep going, that's not the end of the world */
4824 }
4825 }
4826}
4827
4828testcase TC_pcu_ptcch() runs on test_CT {
4829 var L1ctlDlMessage dl;
4830 var octetstring data;
4831 timer T;
4832
4833 f_init_pcu_test();
4834 f_init_l1ctl();
4835 f_l1_tune(L1CTL);
4836
4837 /* Activate PDCH channel on TS7 */
4838 f_TC_pcu_act_req(0, 0, 7, true);
4839
4840 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004841 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004842 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004843 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004844 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004845
4846 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4847 for (var integer i := 0; i < 16; i := i + 1) {
4848 log("Sending an Access Burst towards the L1CTL interface");
4849 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4850 }
4851
4852 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4853 data := f_rnd_octstring(23);
4854
4855 /* Verify PTCCH/D: send a random data block, make sure it's received */
4856 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4857 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4858
4859 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4860 * let's give it more time in case if we miss the beginning. */
4861 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4862 alt {
4863 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4864 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4865 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4866 frame := data)) -> value dl {
4867 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4868 setverdict(pass);
4869 T.stop;
4870 }
4871 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4872 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4873 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4874 l2_data := data)) -> value dl {
4875 log("Rx PTCCH/D data block on L1CTL: ", dl);
4876 setverdict(pass);
4877 T.stop;
4878 }
4879 [] L1CTL.receive { repeat; }
4880 [] T.timeout {
4881 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4882 }
4883 }
4884}
4885
Harald Welte883340c2018-02-28 18:59:29 +01004886/* Send AGCH from PCU; check it appears on Um side */
4887testcase TC_pcu_data_req_agch() runs on test_CT {
4888 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004889 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004890 f_init_l1ctl();
4891 f_l1_tune(L1CTL);
4892
4893 f_TC_pcu_act_req(0, 0, 7, true);
4894 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4895
4896 T.start;
4897 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004898 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004899 setverdict(pass);
4900 }
4901 [] L1CTL.receive { repeat; }
4902 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004904 }
4905 }
4906}
4907
Harald Welte928622b2019-05-26 13:22:59 +02004908/* Send AGCH from PCU; check it appears on Um side */
4909testcase TC_pcu_data_req_pch() runs on test_CT {
4910 timer T := 3.0;
4911 f_init_pcu_test();
4912 f_init_l1ctl();
4913 f_l1_tune(L1CTL);
4914
4915 f_TC_pcu_act_req(0, 0, 7, true);
4916 /* three characters prefix: last 3 digits of IMSI as ASCII */
4917 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4918
4919 T.start;
4920 alt {
4921 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4922 setverdict(pass);
4923 }
4924 [] L1CTL.receive { repeat; }
4925 [] T.timeout {
4926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4927 }
4928 }
4929}
4930
Harald Welte883340c2018-02-28 18:59:29 +01004931/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4932testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4933 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004934 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004935 f_init_l1ctl();
4936 f_l1_tune(L1CTL);
4937
4938 /* append 3 last imsi digits so BTS can compute pagng group */
4939 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4940
4941 timer T := 0.5;
4942 T.start;
4943 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004944 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004945 /* TODO: verify paging group */
4946 setverdict(pass);
4947 }
4948 [] L1CTL.receive { repeat; }
4949 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004951 }
4952 }
4953}
4954
4955/* Send RACH from Um side, expect it to show up on PCU socket */
4956testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004957 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004958 f_init_l1ctl();
4959 f_l1_tune(L1CTL);
4960
4961 var GsmFrameNumber fn_last := 0;
4962 for (var integer i := 0; i < 1000; i := i+1) {
4963 var OCT1 ra := f_rnd_ra_ps();
4964 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4965 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004967 }
4968 fn_last := fn;
4969
4970 timer T := 2.0;
4971 T.start;
4972 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004973 [] 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 +01004974 T.stop;
4975 }
4976 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004978 }
4979 [] PCU.receive { repeat; }
4980 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004982 }
4983 }
4984 }
4985 setverdict(pass);
4986}
4987
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004988/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4989 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4990testcase TC_pcu_ext_rach_content() runs on test_CT {
4991 var template PCUIF_Message pcu_rach_ind;
4992 var GsmFrameNumber fn_last := 0;
4993 var L1ctlRachSynchSeq synch_seq;
4994 var PCUIF_BurstType pcu_bt;
4995 var GsmFrameNumber fn;
4996 var BIT11 ra11;
4997
4998 f_init_pcu_test();
4999 f_init_l1ctl();
5000 f_l1_tune(L1CTL);
5001
5002 for (var integer i := 0; i < 1000; i := i+1) {
5003 /* We need to test both TS1 & TS2 */
5004 if (i rem 2 == 0) {
5005 synch_seq := RACH_SYNCH_SEQ_TS1;
5006 pcu_bt := BURST_TYPE_1;
5007 } else {
5008 synch_seq := RACH_SYNCH_SEQ_TS2;
5009 pcu_bt := BURST_TYPE_2;
5010 }
5011
5012 ra11 := f_rnd_ra11_ps();
5013 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5014 if (fn == fn_last) {
5015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5016 "Two RACH in same FN?!?");
5017 }
5018 fn_last := fn;
5019
5020 /* Compose the expected message */
5021 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005022 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005023 ra := bit2int(ra11),
5024 is_11bit := 1,
5025 burst_type := pcu_bt,
5026 fn := fn);
5027
5028 timer T := 2.0;
5029 T.start;
5030 alt {
5031 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5032 T.stop;
5033 }
5034 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5036 }
5037 [] PCU.receive { repeat; }
5038 [] T.timeout {
5039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5040 }
5041 }
5042 }
5043 setverdict(pass);
5044}
5045
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005046private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5047runs on test_CT {
5048 var template PCUIF_send_data sdt;
5049 var PCUIF_send_data sd;
5050 var int16_t lqual_cb;
5051 timer T := 1.0;
5052
5053 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5054 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5055
5056 /* Send a random PDTCH frame over Um */
5057 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5058 '0000'O & f_rnd_octstring(21)));
5059
5060 T.start;
5061 alt {
5062 /* If expected link quality is above the threshold */
5063 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5064 lqual_cb := sd.data.u.data_ind.lqual_cb;
5065 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5066
5067 /* Make sure the actual link quality matches the expected value */
5068 if (not match(lqual_cb, lqual_cb_exp)) {
5069 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5070 "expected value ", lqual_cb_exp));
5071 } else {
5072 setverdict(pass);
5073 }
5074 }
5075 /* If expected link quality is below the threshold */
5076 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5078 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5079 }
5080 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5081 [] PCU.receive { repeat; }
5082 [lqual_cb_exp < thresh] T.timeout {
5083 log("Rx nothing, as expected");
5084 setverdict(pass);
5085 }
5086 [lqual_cb_exp >= thresh] T.timeout {
5087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5088 "Timeout waiting for PCUIF_DATA.ind");
5089 }
5090 }
5091}
5092
5093/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5094testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5095 f_init_pcu_test();
5096 PCU.clear;
5097
5098 f_init_l1ctl();
5099 f_l1_tune(L1CTL);
5100
5101 /* Activate a PDCH channel on TS7 */
5102 f_TC_pcu_act_req(0, 0, 7, true);
5103
5104 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005105 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005106 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005107 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005108 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005109
5110 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5111 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5112 var TrxcMessage ret;
5113
5114 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5115 valueof(ts_TRXC_FAKE_CI(i)));
5116
5117 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5118 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5119 }
5120}
5121
Harald Welte883340c2018-02-28 18:59:29 +01005122/* Send PAGING via RSL, expect it to shw up on PCU socket */
5123testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005124 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005125
5126 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005127 var MobileIdentityLV mi_lv;
5128 var octetstring mi_lv_enc;
5129 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005130 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005131
Harald Welte883340c2018-02-28 18:59:29 +01005132 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005133 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005134 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005135 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005136 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005137
5138 /* Fancy encoding for PCUIF */
5139 mi_lv := valueof(ts_MI_LV(mi));
5140 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5141 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005142
5143 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005144 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005145 T.start;
5146 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005147 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005148 }
5149 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005151 }
5152 [] PCU.receive { repeat; }
5153 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005155 }
5156 }
5157 }
5158 setverdict(pass);
5159}
5160
Harald Welted66c9b82019-05-25 09:03:15 +02005161/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5162testcase TC_pcu_time_ind() runs on test_CT {
5163 var PCUIF_send_data pcu_sd;
5164 var integer num_time_ind := 0;
5165 var integer first_fn, last_fn;
5166 var float test_duration := 5.0;
5167 timer T;
5168
5169 f_init_pcu_test();
5170 f_TC_pcu_act_req(0, 0, 7, true);
5171
5172 PCU.clear;
5173 T.start(test_duration);
5174 alt {
5175 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5176 num_time_ind := num_time_ind + 1;
5177 if (not isbound(first_fn)) {
5178 first_fn := pcu_sd.data.u.time_ind.fn;
5179 }
5180 last_fn := pcu_sd.data.u.time_ind.fn;
5181 repeat;
5182 }
5183 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5184 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5185 repeat;
5186 }
5187 [] PCU.receive {
5188 repeat;
5189 }
5190 [] T.timeout {}
5191 }
5192 var integer fn_expired := last_fn - first_fn;
5193 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5194
5195 /* verify the number of frames expired matches our expectation */
5196 const float c_GSM_FN_DURATION_MS := 4.61538;
5197 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005198 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005199 if (not match(fn_expired, t_fn_expected)) {
5200 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5201 }
5202
5203 /* There are three TIME.ind in every fn MOD 13 */
5204 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5205 /* Add some tolerance */
5206 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5207 if (not match(num_time_ind, t_time_ind_exp)) {
5208 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5209 }
5210
5211 setverdict(pass);
5212}
5213
Harald Welte4832c862019-05-25 14:57:18 +02005214/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5215testcase TC_pcu_rts_req() runs on test_CT {
5216 var PCUIF_send_data pcu_sd;
5217 var integer first_fn, last_fn;
5218 var integer num_rts_pdtch := 0;
5219 var integer num_rts_ptcch := 0;
5220 var float test_duration := 5.0;
5221 timer T;
5222
5223 f_init_pcu_test();
5224 f_TC_pcu_act_req(0, 0, 7, true);
5225
5226 PCU.clear;
5227 T.start(test_duration);
5228 alt {
5229 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5230 -> value pcu_sd {
5231 num_rts_pdtch := num_rts_pdtch + 1;
5232 if (not isbound(first_fn)) {
5233 first_fn := pcu_sd.data.u.rts_req.fn;
5234 }
5235 last_fn := pcu_sd.data.u.rts_req.fn;
5236 repeat;
5237 }
5238 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5239 -> value pcu_sd {
5240 num_rts_ptcch := num_rts_ptcch + 1;
5241 if (not isbound(first_fn)) {
5242 first_fn := pcu_sd.data.u.rts_req.fn;
5243 }
5244 last_fn := pcu_sd.data.u.rts_req.fn;
5245 repeat;
5246 }
5247 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5248 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5249 repeat;
5250 }
5251 [] PCU.receive {
5252 repeat;
5253 }
5254 [] T.timeout {}
5255 }
5256 var integer fn_expired := last_fn - first_fn;
5257 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5258 ", num_rts_ptcch=", num_rts_ptcch);
5259
5260 /* verify the number of frames expired matches our expectation */
5261 const float c_GSM_FN_DURATION_MS := 4.61538;
5262 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005263 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005264 if (not match(fn_expired, t_fn_expected)) {
5265 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5266 }
5267
5268 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5269 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5270 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5271 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5272 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5273 t_ptcch_exp);
5274 }
5275
5276 /* We have 12 PDTCH blocks every 52-multiframe */
5277 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5278 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5279 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5280 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5281 t_pdtch_exp);
5282 }
5283
5284 setverdict(pass);
5285}
5286
Harald Welte07bd2d22019-05-25 11:03:30 +02005287/* test for generating Abis side OML ALERT from the PCU */
5288testcase TC_pcu_oml_alert() runs on test_CT {
5289 var PCUIF_send_data pcu_sd;
5290 var integer num_time_ind := 0;
5291 var integer first_fn, last_fn;
5292 var float test_duration := 5.0;
5293 timer T;
5294
5295 f_init_pcu_test();
5296 f_TC_pcu_act_req(0, 0, 7, true);
5297
5298 /* re-connect CTRL port from BTS to BSC */
5299 f_ipa_ctrl_stop();
5300 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5301
5302 /* Send that OML Alert */
5303 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5304
5305 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5306 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5307 setverdict(pass);
5308}
5309
Harald Welteeaa9a862019-05-26 23:01:08 +02005310/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5311private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5312 var PCUIF_Message first_info;
5313 var integer pcu_conn_id := -1;
5314 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5315 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5316 var OCT4 tlli := '01020304'O;
5317 var OCT1 cause := '23'O;
5318 timer T := 5.0;
5319
5320 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5321
5322 f_l1_tune(L1CTL);
5323 RSL.clear;
5324
5325 f_est_dchan();
5326 L1CTL.clear;
5327
5328 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5329
5330 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5331 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5332 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5333
5334 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5335 T.start;
5336 alt {
5337 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5338 setverdict(pass);
5339 }
5340 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5341 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5342 }
5343 [] PCU.receive {
5344 repeat;
5345 }
5346 [] T.timeout {
5347 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5348 }
5349 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005350
5351 /* release the channel */
5352 f_rsl_chan_deact();
5353 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5354 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005355}
5356testcase TC_pcu_rr_suspend() runs on test_CT {
5357 var ConnHdlrPars pars;
5358 var ConnHdlr vc_conn;
5359
5360 f_init();
5361
5362 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5363 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5364 vc_conn.done;
5365}
Harald Welte07bd2d22019-05-25 11:03:30 +02005366
Harald Weltea2e0e942019-05-27 18:12:53 +02005367/* Ensure that PCUIF socket can accept only a single connection */
5368testcase TC_pcu_socket_connect_multi() runs on test_CT {
5369 timer T := 5.0;
5370
5371 /* this (among other things) establishes the first connection to the PCUIF socket */
5372 f_init();
5373
5374 /* try to establish a second connection, expect it to fail */
5375 PCU.send(UD_connect:{mp_pcu_socket, -1});
5376 T.start;
5377 alt {
5378 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5379 setverdict(pass);
5380 }
5381 [] PCU.receive(UD_connect_result:?) {
5382 setverdict(fail, "Unexpected unix domain connect result");
5383 }
5384 [] T.timeout {
5385 setverdict(pass);
5386 }
5387 }
5388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5389}
5390
Harald Weltec8effb72019-05-27 18:23:04 +02005391/* Ensure that PCUIF socket can disconnect + reconnect */
5392testcase TC_pcu_socket_reconnect() runs on test_CT {
5393 /* this (among other things) establishes the first connection to the PCUIF socket */
5394 f_init();
5395
5396 f_sleep(1.0);
5397
5398 f_pcuif_close(PCU, g_pcu_conn_id);
5399 g_pcu_conn_id := -1;
5400
5401 f_sleep(1.0);
5402
5403 /* re-connect */
5404 PCU.clear;
5405 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5406 setverdict(pass);
5407
5408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5409}
5410
Harald Weltebe030482019-05-27 22:29:35 +02005411/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005412private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5413runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005414 var L1ctlDlMessage l1_dl;
5415 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005416 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005417 timer T := 5.0;
5418 T.start;
5419 alt {
5420 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005421 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5422 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005423 repeat;
5424 }
5425 }
5426 [] pt.receive {
5427 repeat;
5428 }
5429 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5431 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005432 }
5433 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005434 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005435}
5436
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005437/* Check if GPRS Indicator is present in RR System Information of a given type */
5438private function f_si_has_gprs_indicator(RrMessageType si_type)
5439runs on test_CT return boolean {
5440 var SystemInformation si := f_get_si(L1CTL, si_type);
5441
5442 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005443 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005444 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005445 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005446 }
5447
5448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5449 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005450}
5451
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005452/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5453private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5454runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005455 /* don't call f_init() as this would connect PCU socket */
5456 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005457
5458 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005459 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005460 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005461
5462 f_init_l1ctl();
5463 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005464 f_sleep(2.0);
5465 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005466
5467 if (f_si_has_gprs_indicator(si_type)) {
5468 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005469 } else {
5470 setverdict(pass);
5471 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005472
Harald Weltebe030482019-05-27 22:29:35 +02005473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5474}
5475
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005476testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5477 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5478}
Harald Weltebe030482019-05-27 22:29:35 +02005479
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005480testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5481 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5482}
5483
5484/* Ensure that GPRS capability is advertised after PCU socket connect */
5485private function f_TC_pcu_socket_connect(RrMessageType si_type)
5486runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005487 /* this (among other things) establishes the first connection to the PCUIF socket */
5488 f_init();
5489 f_init_l1ctl();
5490 f_l1_tune(L1CTL);
5491
5492 f_sleep(2.0);
5493 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005494
5495 if (not f_si_has_gprs_indicator(si_type)) {
5496 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005497 } else {
5498 setverdict(pass);
5499 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005500
Harald Weltebe030482019-05-27 22:29:35 +02005501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5502}
5503
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005504testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5505 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5506}
Harald Weltebe030482019-05-27 22:29:35 +02005507
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005508testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5509 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5510}
5511
5512/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5513private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5514runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005515 /* this (among other things) establishes the first connection to the PCUIF socket */
5516 f_init();
5517 f_init_l1ctl();
5518 f_l1_tune(L1CTL);
5519
5520 f_pcuif_close(PCU, g_pcu_conn_id);
5521 g_pcu_conn_id := -1;
5522
5523 f_sleep(1.0);
5524
5525 /* re-connect */
5526 PCU.clear;
5527 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5528
5529 f_sleep(2.0);
5530 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005531
5532 if (f_si_has_gprs_indicator(si_type)) {
5533 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005534 } else {
5535 setverdict(pass);
5536 }
5537
5538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5539}
5540
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005541testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5542 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5543}
5544
5545testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5546 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5547}
5548
Oliver Smithf5239c72019-08-28 10:01:25 +02005549/* 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) */
5550testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5551 var SystemInformation si3 := valueof(ts_SI3_default);
5552
5553 f_init();
5554
Harald Welte76220222020-10-11 20:32:44 +02005555 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5556 * information */
5557 timer T := 2.0;
5558 T.start;
5559 alt {
5560 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5561 [] T.timeout {}
5562 }
5563
Oliver Smithf5239c72019-08-28 10:01:25 +02005564 /* Verify cell_id */
5565 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5566 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5567 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005568 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5569 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5570 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005571 }
5572
5573 /* Verify LAC */
5574 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5575 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5576 if (lac_si3 != lac_pcu) {
5577 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5578 }
5579
5580 setverdict(pass);
5581}
Harald Welted66c9b82019-05-25 09:03:15 +02005582
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005583/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5584testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5585 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005586 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005587
5588 f_init();
5589
5590 info_ind := g_pcu_last_info.u.info_ind;
5591
5592 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5593 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5594 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5595 /* Skip inactive timeslots */
5596 continue;
5597 }
5598
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005599 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005600 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005601 else
5602 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005603
5604 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005605 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005606 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005607 hsn := fhp.maio_hsn.hsn,
5608 maio := fhp.maio_hsn.maio,
5609 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005610 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005611 } else {
5612 tr_ts := tr_PCUIF_InfoTrxTsH0;
5613 }
5614
5615 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5616 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5617 if (not match(ts, tr_ts)) {
5618 setverdict(fail, "Hopping parameters do not match: ",
5619 "received ", ts, " vs expected ", tr_ts);
5620 } else {
5621 setverdict(pass);
5622 }
5623 }
5624 }
5625}
5626
Alexander Couzens5283f552020-07-28 15:39:04 +02005627/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5628testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5629 f_init_vty_bsc();
5630 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5631 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5632
5633 f_init();
5634
5635 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5636 if (not ischosen(remote_addr.v10)) {
5637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5638 log2str("Unexpected remote_addr: ", remote_addr));
5639 }
5640
5641 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5642 setverdict(fail, "Received address family is not IPv4");
5643 }
5644
5645 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5646 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5647 }
5648
5649 setverdict(pass);
5650}
5651
5652/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5653testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5654 f_init_vty_bsc();
5655 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5656
5657 f_init();
5658
5659 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5660 if (not ischosen(remote_addr.v10)) {
5661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5662 log2str("Unexpected remote_addr: ", remote_addr));
5663 }
5664
5665 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5666 setverdict(fail, "Received address family is not IPv6");
5667 }
5668
5669 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5670 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5671 }
5672
5673 setverdict(pass);
5674}
5675
Harald Welte3d04ae62018-04-04 20:29:05 +02005676/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005677 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005678 ***********************************************************************/
5679
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005680private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5681 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005682runs on ConnHdlr {
5683 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005684
5685 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005686 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005687 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5688 repeat;
5689 }
5690 }
5691}
5692
5693private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5694runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005695 /* Expect BTS to immediately acknowledge activation as PDCH */
5696 PCU.clear;
5697 f_rsl_chan_act(g_pars.chan_mode);
5698 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005699 timer T_wait := 2.0;
5700 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005701 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005702 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005703 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005704 [] T_wait.timeout {
5705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5706 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5707 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005708 }
5709 /* try to activate this PDCH from the PCU point of view */
5710 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5711 /* FIXME: is there a response? */
5712}
5713
5714private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5715runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005716 /* Send RSL CHAN REL (deactivate) */
5717 PCU.clear;
5718 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5719 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005720 timer T_wait := 2.0;
5721 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005722 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005723 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005724 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005725 [] T_wait.timeout {
5726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5727 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5728 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005729 }
5730 /* Emulate PCU asking BTS to deactivate PDCH */
5731 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5732 alt {
5733 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5734 setverdict(pass);
5735 }
5736 [] RSL.receive { repeat; }
5737 }
5738}
5739
5740/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005741private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005742 var PCUIF_Message first_info;
5743 var integer ts_nr := g_chan_nr.tn;
5744 var integer trx_nr := 0;
5745 var integer bts_nr := 0;
5746 var integer pcu_conn_id := -1;
5747
5748 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5749
5750 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5751 f_sleep(3.0);
5752 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5753 setverdict(pass);
5754}
5755testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5756 var ConnHdlrPars pars;
5757 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005758 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005759
5760 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5761 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5762 vc_conn.done;
5763}
5764
5765/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005766private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005767 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005768 var integer pcu_conn_id := -1;
5769
5770 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5771
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005772 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5773 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5774 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005775 setverdict(pass);
5776}
5777testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5778 var ConnHdlrPars pars;
5779 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005780 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005781
5782 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5783 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5784 vc_conn.done;
5785}
5786
5787/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005788private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005789 var PCUIF_Message first_info;
5790 var integer ts_nr := g_chan_nr.tn;
5791 var integer trx_nr := 0;
5792 var integer bts_nr := 0;
5793 var integer pcu_conn_id := -1;
5794
5795 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5796
5797 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005798 /* Send a second Chan Activ and expect it to be NACKed */
5799 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5800 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005801 setverdict(pass);
5802}
5803testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5804 var ConnHdlrPars pars;
5805 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005806 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005807
5808 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5809 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5810 vc_conn.done;
5811}
5812
5813/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005814private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005815 var PCUIF_Message first_info;
5816 var integer ts_nr := g_chan_nr.tn;
5817 var integer trx_nr := 0;
5818 var integer bts_nr := 0;
5819 var integer pcu_conn_id := -1;
5820 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5821
5822 /* register for the TCH/F channel number */
5823 f_rslem_register(0, chan_nr);
5824
5825 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5826
5827 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5828 "RSL CHAN ACT");
5829 setverdict(pass);
5830}
5831testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5832 var ConnHdlrPars pars;
5833 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005834 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005835
5836 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5837 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5838 vc_conn.done;
5839}
5840
5841/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005842private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005843 var PCUIF_Message first_info;
5844 var integer ts_nr := g_chan_nr.tn;
5845 var integer trx_nr := 0;
5846 var integer bts_nr := 0;
5847 var integer pcu_conn_id := -1;
5848 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5849 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5850
5851 /* register for the TCH/H channel numbers */
5852 f_rslem_register(0, chan_nr[0]);
5853 f_rslem_register(0, chan_nr[1]);
5854
5855 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5856
5857 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5858 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5859 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5860 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5861 setverdict(pass);
5862}
5863testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5864 var ConnHdlrPars pars;
5865 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005866 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005867
5868 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5869 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5870 vc_conn.done;
5871}
5872
Harald Welte9bbbfb52018-04-05 09:33:19 +02005873/***********************************************************************
5874 * IPA Style Dynamic Timeslot Support
5875 ***********************************************************************/
5876
5877private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5878runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005879 /* Expect BTS to immediately acknowledge activation as PDCH */
5880 PCU.clear;
5881 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5882 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005883 timer T_wait := 2.0;
5884 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005885 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005886 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005887 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005888 [] T_wait.timeout {
5889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5890 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5891 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005892 }
5893 /* try to activate this PDCH from the PCU point of view */
5894 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5895 /* FIXME: is there a response? */
5896
5897 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5898}
5899
5900private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5901runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005902 /* Send RSL CHAN REL (deactivate) */
5903 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5904 PCU.clear;
5905 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005906 timer T_wait := 2.0;
5907 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005908 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005909 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005910 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005911 [] T_wait.timeout {
5912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5913 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5914 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005915 }
5916 /* Emulate PCU asking BTS to deactivate PDCH */
5917 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5918 alt {
5919 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5920 setverdict(pass);
5921 }
5922 [] RSL.receive { repeat; }
5923 }
5924}
5925
5926/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005927private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005928 var PCUIF_Message first_info;
5929 var integer ts_nr := g_chan_nr.tn;
5930 var integer trx_nr := 0;
5931 var integer bts_nr := 0;
5932 var integer pcu_conn_id := -1;
5933
5934 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5935
5936 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5937 f_sleep(3.0);
5938 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5939
5940 setverdict(pass);
5941
5942}
5943testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5944 var ConnHdlrPars pars;
5945 var ConnHdlr vc_conn;
5946 f_init();
5947
5948 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5949 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5950 vc_conn.done;
5951}
5952
5953/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005954private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005955 var PCUIF_Message first_info;
5956 var integer ts_nr := g_chan_nr.tn;
5957 var integer trx_nr := 0;
5958 var integer bts_nr := 0;
5959 var integer pcu_conn_id := -1;
5960
5961 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5962
5963 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5964 "RSL CHAN ACT");
5965 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5966 "RF CHAN REL", true);
5967 setverdict(pass);
5968}
5969testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5970 var ConnHdlrPars pars;
5971 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005972 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005973
5974 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5975 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5976 vc_conn.done;
5977}
5978
5979/* 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 +07005980private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005981 var PCUIF_Message first_info;
5982 var integer ts_nr := g_chan_nr.tn;
5983 var integer trx_nr := 0;
5984 var integer bts_nr := 0;
5985 var integer pcu_conn_id := -1;
5986
5987 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5988
5989 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5990 "RSL CHAN ACT");
5991
5992 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5993 alt {
5994 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5995 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005997 }
5998 [] RSL.receive { repeat; }
5999 }
6000
6001 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6002 "RF CHAN REL", true);
6003 setverdict(pass);
6004}
6005testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6006 var ConnHdlrPars pars;
6007 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006008 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006009
6010 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6011 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6012 vc_conn.done;
6013}
6014
6015/* 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 +07006016private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006017 var PCUIF_Message first_info;
6018 var integer ts_nr := g_chan_nr.tn;
6019 var integer trx_nr := 0;
6020 var integer bts_nr := 0;
6021 var integer pcu_conn_id := -1;
6022
6023 /* register for the TCH/F channel number */
6024 f_rslem_register(0, g_chan_nr);
6025
6026 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6027
6028 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6029
6030 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6031 "RSL CHAN ACT");
6032
6033 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6034
6035 setverdict(pass);
6036}
6037testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6038 var ConnHdlrPars pars;
6039 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006040 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006041
6042 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6043 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6044 vc_conn.done;
6045}
6046
6047
Harald Welte0472ab42018-03-12 15:02:26 +01006048/***********************************************************************
6049 * LAPDm / RLL related
6050 ***********************************************************************/
6051
6052private function f_tx_lapdm(template (value) LapdmFrame l,
6053 template (value) RslLinkId link_id) runs on ConnHdlr {
6054 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006055 var template (value) SacchL1Header l1h;
6056
6057 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006058 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006059 /* Compose dummy L1 header */
6060 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6061 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 +02006062 } else {
6063 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006064 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 +01006065 }
Harald Welte0472ab42018-03-12 15:02:26 +01006066}
6067
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006068private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006069 uint3_t sapi,
6070 RslLinkId link_id,
6071 octetstring l3,
6072 boolean exp
6073}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006074private type record of RllTestCase RllTestCases;
6075private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6076 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006077 sapi := sapi,
6078 link_id := id,
6079 l3 := l3,
6080 exp := exp
6081}
6082
6083/* execute the same callback function with a set of different parameters (tcs) on a
6084 * variety of logical channels */
6085private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6086 var ConnHdlrPars pars;
6087 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006088 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006089
6090 /* test on each of the channels we have */
6091 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6092 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6093
6094 /* test each of the test cases on the current channel */
6095 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6096 pars.spec.rll := tcs[j];
6097 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6098 vc_conn := f_start_handler(fn, pars);
6099 vc_conn.done;
6100 }
6101 }
6102
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006104}
6105
6106/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6107private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6108 var RllTestCase tc := g_pars.spec.rll;
6109 timer T := 3.0;
6110
6111 f_l1_tune(L1CTL);
6112 RSL.clear;
6113
6114 /* activate the logical channel */
6115 f_est_dchan();
6116 L1CTL.clear;
6117
6118 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6119 T.start;
6120 alt {
6121 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6122 if (tc.exp) {
6123 setverdict(pass);
6124 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006126 }
6127 }
6128 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6129 if (tc.exp) {
6130 setverdict(pass);
6131 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006133 }
6134 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006135 /* We also expect to receive the measurements */
6136 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006137 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006139 }
6140 [not tc.exp] T.timeout {
6141 setverdict(pass);
6142 }
6143 }
6144
6145 f_rsl_chan_deact();
6146 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6147 f_rslem_unregister(0, g_chan_nr);
6148}
6149testcase TC_rll_est_ind() runs on test_CT {
6150 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006151 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006152 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006153 /* normal SAPI0 establishment */
6154 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006155 /* SAPI 3 doesn't support contention resolution */
6156 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6157 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6158 /* normal SAPI3 establishment on main DCCH */
6159 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6160 /* normal SAPI3 establishment on SACCH */
6161 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6162 };
6163 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6164}
6165
6166/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6167private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6168 var RllTestCase tc := g_pars.spec.rll;
6169 var L1ctlDlMessage dl;
6170 timer T := 3.0;
6171
6172 f_l1_tune(L1CTL);
6173 RSL.clear;
6174
6175 /* activate the logical channel */
6176 f_est_dchan();
6177 L1CTL.clear;
6178
6179 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6180 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6181 T.start;
6182 alt {
6183 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6184 var LapdmFrame lapdm;
6185 var octetstring l2 := dl.payload.data_ind.payload;
6186 if (dl.dl_info.link_id.c == SACCH) {
6187 /* remove L1 header */
6188 l2 := substr(l2, 2, lengthof(l2)-2);
6189 }
6190 lapdm.ab := dec_LapdmFrameAB(l2);
6191 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6192 setverdict(pass);
6193 } else {
6194 repeat;
6195 }
6196 }
6197 [] L1CTL.receive { repeat; }
6198 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006200 }
6201 }
6202
6203 f_rsl_chan_deact();
6204 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6205 f_rslem_unregister(0, g_chan_nr);
6206}
6207testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6208 var RllTestCases tcs := {
6209 /* normal SAPI3 establishment on main DCCH */
6210 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6211 };
6212 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6213}
6214testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6215 var RllTestCases tcs := {
6216 /* normal SAPI3 establishment on SACCH */
6217 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6218 }
6219 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6220}
6221
6222/* altstep to receive a LAPDm frame matching the given template */
6223private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6224 var L1ctlDlMessage dl;
6225 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6226 var LapdmFrame lapdm;
6227 var octetstring l2 := dl.payload.data_ind.payload;
6228 if (dl.dl_info.link_id.c == SACCH) {
6229 /* remove L1 header */
6230 l2 := substr(l2, 2, lengthof(l2)-2);
6231 }
6232 if (ischosen(exp.ab)) {
6233 lapdm.ab := dec_LapdmFrameAB(l2);
6234 } else if (ischosen(exp.b4)) {
6235 lapdm.b4 := dec_LapdmFrameB4(l2);
6236 } else if (ischosen(exp.bbis)) {
6237 lapdm.bbis := dec_LapdmFrameBbis(l2);
6238 }
6239 log("Rx LAPDm ", lapdm);
6240 if (match(lapdm, exp)) {
6241 setverdict(pass);
6242 } else {
6243 repeat;
6244 }
6245 }
6246 [] L1CTL.receive { repeat; }
6247}
6248private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6249 timer T := t;
6250 T.start;
6251 alt {
6252 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006254 }
6255 [] as_l1_exp_lapdm(exp);
6256 }
6257}
6258
6259/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6260private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6261 /* send SABM from MS -> BTS */
6262 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6263 /* expect RLL EST IND on Abis */
6264 alt {
6265 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6266 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6267 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006269 }
6270 [] RSL.receive { repeat; }
6271 }
6272 /* expect UA from BTS -> MS */
6273 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6274}
6275
6276/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6277private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6278 var RllTestCase tc := g_pars.spec.rll;
6279
6280 f_l1_tune(L1CTL);
6281 RSL.clear;
6282
6283 /* activate the logical channel */
6284 f_est_dchan();
6285 L1CTL.clear;
6286
6287 /* first establish the link-layer */
6288 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6289
6290 /* then send the DISC */
6291 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6292 /* ... and expect the REL IND on the RSL side */
6293 alt {
6294 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6295 setverdict(pass);
6296 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006297 /* We also expect to receive the measurements */
6298 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006299 }
6300
6301 /* release the channel */
6302 f_rsl_chan_deact();
6303 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6304 f_rslem_unregister(0, g_chan_nr);
6305}
6306testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6307 var RllTestCases tcs := {
6308 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6309 };
6310 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6311}
6312
6313testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6314 var RllTestCases tcs := {
6315 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6316 };
6317 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6318}
6319testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6320 var RllTestCases tcs := {
6321 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6322 };
6323 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6324}
6325testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6326 var RllTestCases tcs := {
6327 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6328 };
6329 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6330}
6331
6332/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6333private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6334 var RllTestCase tc := g_pars.spec.rll;
6335 f_l1_tune(L1CTL);
6336 RSL.clear;
6337
6338 /* activate the logical channel */
6339 f_est_dchan();
6340 L1CTL.clear;
6341
6342 /* first establish the link-layer */
6343 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6344
6345 /* then send the REL REQ via RSL */
6346 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6347 /* ... and expect the DISC on the Um side */
6348 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006349 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006350 /* FIXME: send a UA in resposne to the DISC */
6351 }
6352 }
6353
6354 /* release the channel */
6355 f_rsl_chan_deact();
6356 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6357 f_rslem_unregister(0, g_chan_nr);
6358}
6359testcase TC_rll_rel_req() runs on test_CT {
6360 var RllTestCases tcs := {
6361 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6362 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6363 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6364 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6365 };
6366 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6367}
6368
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006369/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006370testcase TC_rll_data_req() runs on test_CT {
6371}
6372
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006373/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006374testcase TC_rll_data_ind() runs on test_CT {
6375}
6376
6377/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6378private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6379 var RllTestCase tc := g_pars.spec.rll;
6380
6381 f_l1_tune(L1CTL);
6382 RSL.clear;
6383
6384 f_est_dchan();
6385 L1CTL.clear;
6386
6387 /* Send UNITDATA REQ on RSL side */
6388 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6389 /* Expect it to arrive on the other side */
6390 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006391 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006392 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006393 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006394 }
6395
6396 /* release the channel */
6397 f_rsl_chan_deact();
6398 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6399 f_rslem_unregister(0, g_chan_nr);
6400}
6401testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6402 var octetstring l3 := f_rnd_octstring(15);
6403 var RllTestCases tcs := {
6404 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6405 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6406 };
6407 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6408}
6409testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6410 var octetstring l3 := f_rnd_octstring(19);
6411 var RllTestCases tcs := {
6412 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6413 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6414 };
6415 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6416}
6417
6418/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6419private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6420 var RllTestCase tc := g_pars.spec.rll;
6421
6422 f_l1_tune(L1CTL);
6423 RSL.clear;
6424
6425 f_est_dchan();
6426 L1CTL.clear;
6427
6428 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006429 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006430 /* Expdct RLL UNITDATA IND on RSL side */
6431 alt {
6432 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6433 setverdict(pass);
6434 }
6435 [] RSL.receive { repeat; }
6436 }
6437
6438 /* release the channel */
6439 f_rsl_chan_deact();
6440 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6441 f_rslem_unregister(0, g_chan_nr);
6442}
6443testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006444 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006445 var RllTestCases tcs := {
6446 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6447 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6448 };
6449 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6450}
6451testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6452 var octetstring l3 := f_rnd_octstring(18);
6453 var RllTestCases tcs := {
6454 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6455 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6456 };
6457 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6458}
6459
Harald Weltee613f962018-04-18 22:38:16 +02006460/***********************************************************************
6461 * Encryption Related
6462 ***********************************************************************/
6463
6464/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006465private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006466 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6467 if (link_id.c == SACCH) {
6468 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6469 } else {
6470 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6471 }
6472}
6473
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006474/* Expect (or not expect) other kinds of messages */
6475private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6476 [exp_any] RSL.receive { repeat; }
6477 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006479 }
6480}
6481
Harald Weltee613f962018-04-18 22:38:16 +02006482/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006483private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006484 RslLinkId link_id,
6485 octetstring l3,
6486 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006487 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006488) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006489 timer T := 3.0;
6490 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6491 T.start;
6492 /* Expect RLL UNITDATA IND on RSL side */
6493 alt {
6494 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6495 setverdict(pass);
6496 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006497 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006498 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006499 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006501 }
Harald Weltee613f962018-04-18 22:38:16 +02006502 }
6503}
6504
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006505/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6506private function f_data_mo(
6507 RslLinkId link_id,
6508 boolean p, uint3_t nr, uint3_t ns,
6509 octetstring l3,
6510 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006511 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006512) runs on ConnHdlr {
6513 timer T := 3.0;
6514 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6515 T.start;
6516 /* Expect RLL DATA IND on RSL side */
6517 alt {
6518 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6519 setverdict(pass);
6520 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006521 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006522 [] as_rsl_any_ind(exp_any);
6523 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006525 }
6526 }
6527}
6528
Harald Weltee613f962018-04-18 22:38:16 +02006529/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006530private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006531 f_l1_tune(L1CTL);
6532 f_est_dchan(true);
6533
6534 /* now we actually need to transmit some data both ways to check if the encryption works */
6535 var L1ctlDlMessage dl;
6536
Stefan Sperling603d98e2018-07-25 16:47:28 +02006537 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006538 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6539
6540 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6541 f_unitdata_mt(link_id, l3);
6542
6543 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6544 f_unitdata_mo(link_id, l3);
6545
6546 /* release the channel */
6547 f_rsl_chan_deact();
6548 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6549 f_rslem_unregister(0, g_chan_nr);
6550}
6551testcase TC_chan_act_a51() runs on test_CT {
6552 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6553 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6554 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6555}
6556testcase TC_chan_act_a52() runs on test_CT {
6557 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6558 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6559 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6560}
6561testcase TC_chan_act_a53() runs on test_CT {
6562 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6563 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6564 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6565}
6566
Eric Wildf1827a72019-05-28 17:37:35 +02006567/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6568 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 +07006569private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006570 f_l1_tune(L1CTL);
6571 f_est_dchan(true);
6572
6573 /* now we actually need to transmit some data both ways to check if the encryption works */
6574 var L1ctlDlMessage dl;
6575
6576 var octetstring l3 := f_rnd_octstring(20);
6577 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6578
6579 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6580 f_unitdata_mt(link_id, l3);
6581
6582 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6583 f_unitdata_mo(link_id, l3);
6584
6585 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006586 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006587
6588 /* modify key to break proper encryption */
6589 g_pars.encr.key := f_rnd_octstring(8);
6590 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6591 rsl.ies := rsl.ies & { ei };
6592 RSL.send(rsl);
6593
6594 timer T0 := 1.0;
6595 T0.start;
6596 /* Expect RSL MODIFY ACK */
6597 alt {
6598 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6599 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6601 }
6602 [] T0.timeout {
6603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6604 }
6605 }
6606
6607 var octetstring l3msg := f_rnd_octstring(15);
6608 timer T1 := 3.0;
6609 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6610 due to broken encryption */
6611 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6612 T1.start;
6613 alt {
6614 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6616 }
6617 [] T1.timeout {
6618 setverdict(pass);
6619 }
6620 }
6621
6622 /* release the channel */
6623 f_rsl_chan_deact();
6624 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6625 f_rslem_unregister(0, g_chan_nr);
6626}
6627testcase TC_rsl_modify_encr() runs on test_CT {
6628 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6629 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6630 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6631}
Harald Weltee613f962018-04-18 22:38:16 +02006632
6633/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006634private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006635 /* L3 payload doesn't matter, as it is passed transparently */
6636 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6637 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6638 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6639
6640 f_l1_tune(L1CTL);
6641
6642 /* first establish a dedicated channel in the clear */
6643 f_est_dchan(false);
6644
6645 /* Establish ABM */
6646 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6647
6648 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6649 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6650 /* expect the L3 to arrive still unencrypted on the MS side */
6651 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6652
6653 /* configure L1 to apply ciphering */
6654 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6655 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6656
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006657 /* send first ciphered I-frame in response and expect it on RSL */
6658 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006659
6660 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6661 * and hence enable encryption also on the downlink */
6662
6663 /* expect bi-directional communication work in encrypted mode */
6664 f_unitdata_mo(link_id, f_rnd_octstring(15));
6665 f_unitdata_mt(link_id, f_rnd_octstring(15));
6666
6667 /* release the channel */
6668 f_rsl_chan_deact();
6669 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6670 f_rslem_unregister(0, g_chan_nr);
6671}
6672testcase TC_encr_cmd_a51() runs on test_CT {
6673 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6674 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6675 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6676}
6677testcase TC_encr_cmd_a52() runs on test_CT {
6678 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6679 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6680 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6681}
6682testcase TC_encr_cmd_a53() runs on test_CT {
6683 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6684 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6685 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6686}
6687
6688private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6689 var LapdmFrame lf;
6690 var octetstring reenc;
6691
6692 /* decode the LAPDm frame */
6693 if (ischosen(exp_match.ab)) {
6694 lf.ab := dec_LapdmFrameAB(enc);
6695 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006697 }
6698
6699 /* check if decoder result matches expectation */
6700 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006702 } else {
6703 log(name, ": matched");
6704 setverdict(pass);
6705 }
6706
6707 /* test if re-encoded frame equals original input */
6708 reenc := enc_LapdmFrame(lf);
6709 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006711 } else {
6712 setverdict(pass);
6713 }
6714}
6715
6716testcase TC_lapdm_selftest() runs on test_CT {
6717 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6718 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6719 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6720 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6721 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6722 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6723 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6724}
6725
Stefan Sperling4880be42018-08-07 18:12:59 +02006726/***********************************************************************
6727 * DTX Related (see GSM 05.08, section 8.3)
6728 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006729private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006730 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006731 var GsmFrameNumber first_fn;
6732 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006733 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006734 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006735 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6736 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006737 const integer frame_dtx_tchf_mod := 104;
6738 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6739 * which operates in terms of blocks rather than frames. */
6740 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6741 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006742 timer T := 5.0;
6743
6744 f_l1_tune(L1CTL);
6745 RSL.clear;
6746 L1CTL.clear;
6747
6748 /* activate TCHF signalling channel */
6749 f_est_dchan(false);
6750
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006751 /* A template for matching dummy LAPDm func=UA frames */
6752 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6753 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6754 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6755
Stefan Sperling4880be42018-08-07 18:12:59 +02006756 T.start;
6757 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006758 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006759 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006760
6761 if (is_first_frame) {
6762 is_first_frame := false;
6763 first_fn := dl.dl_info.frame_nr;
6764 }
6765
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006766 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006767 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006768 T.stop;
6769 f_rsl_chan_deact();
6770 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006771
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006772 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6773 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006774
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006775 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006776 setverdict(fail, "Not enough fill frames received: ",
6777 nfill_frames, " out of ", expected_fill_frames);
6778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006779 } else {
6780 setverdict(pass);
6781 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006782 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006783 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6784 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6785 * we should only see the subset of frames numbers which correspond to a block boundary.
6786 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6787 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6788 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006789 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006790 repeat;
6791 }
6792 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006793 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6794 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6795 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006796 f_rsl_chan_deact();
6797 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006798 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006799 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006800 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006801 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006802 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006803
6804 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006805 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6806 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006807 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6808 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6809 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006810 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6811 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006812 case else {
6813 /* This shall not happen, just to be sure */
6814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6815 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006816 }
6817
6818 f_rsl_chan_deact();
6819 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006820
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006821 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006822 setverdict(pass);
6823 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006824 setverdict(fail, "Not enough fill frames received: ",
6825 nfill_frames, " out of ", expected_fill_frames);
6826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006827 }
6828 } else {
6829 repeat;
6830 }
6831 }
6832 }
6833 [] L1CTL.receive { repeat; }
6834 [] T.timeout {
6835 f_rsl_chan_deact();
6836 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006838 }
6839 }
6840}
6841
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006842private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006843 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006844 var ConnHdlr vc_conn;
6845 var ConnHdlrPars pars;
6846 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006847 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006848 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006849 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006850 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006851 if (dtxd) {
6852 if (i >= 4) { /* DTX is only allowed on TCH/F */
6853 break;
6854 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006855 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006856 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006857 vc_conn.done;
6858 }
6859}
6860
6861/* Verify that L2 fill frames are sent on TCH in signaling mode if
6862 * there is nothing to transmit while DTX is disabled on downlink. */
6863testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6864 f_tch_sign_l2_fill_frame(false);
6865}
6866
6867/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6868 * there is nothing to transmit while DTX is enabled on downlink. */
6869testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6870 f_tch_sign_l2_fill_frame(true);
6871}
Harald Welte0472ab42018-03-12 15:02:26 +01006872
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006873testcase TC_chopped_ipa_ping() runs on test_CT {
6874 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6875}
6876
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006877testcase TC_chopped_ipa_payload() runs on test_CT {
6878 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6879}
6880
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006881
6882/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6883 * Return value: Measurement Report to be sent (encoded octetstring). */
6884type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6885 runs on ConnHdlr return octetstring;
6886
6887private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6888runs on ConnHdlr {
6889 var L1ctlDlMessage l1_dl;
6890 var SacchL1Header l1h;
6891 var octetstring l2;
6892
6893 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6894 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6895 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6896 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6897
6898 /* Pass it to the user specified call-back function */
6899 l2 := cb.apply(l1h, num_blocks);
6900 /* Send a Measurement Report generated by the call-back */
6901 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6902 l1_dl.dl_info.link_id,
6903 l1h, l2));
6904
6905 /* Shall we keep going? */
6906 num_blocks := num_blocks - 1;
6907 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6908 if (num_blocks > 0) { repeat; }
6909 }
6910 [] L1CTL.receive { repeat; }
6911}
6912
6913private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6914runs on ConnHdlr return octetstring {
6915 /* Command the L1 to apply received parameters */
6916 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6917
6918 /* Dummy measurement report (the results are invalid) */
6919 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6920}
6921
6922private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6923runs on ConnHdlr return octetstring {
6924 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6925 setverdict(fail, "Unexpected MS Power level change: ",
6926 g_pars.l1_pars.ms_power_level, " -> ",
6927 l1h.ms_power_lvl);
6928 }
6929
6930 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6931}
6932
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006933private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6934runs on ConnHdlr return octetstring {
6935 /* UL RSSI oscillation driven by SACCH block number */
6936 if (num_blocks rem 2 == 0) {
6937 f_trxc_fake_rssi(-100);
6938 } else {
6939 f_trxc_fake_rssi(-50);
6940 }
6941
6942 /* Make sure that MS power level remains constant */
6943 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6944}
6945
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006946/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6947private function f_TC_ms_pwr_ctrl_constant(charstring id)
6948runs on ConnHdlr {
6949 var integer num_blocks := 8;
6950 timer T := int2float(num_blocks);
6951
6952 f_l1_tune(L1CTL);
6953 RSL.clear;
6954
6955 /* These IEs are needed for autonomous MS power control */
6956 var template (value) RSL_IE_List ies := {
6957 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6958 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6959 }),
6960 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6961 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6962 })
6963 };
6964
6965 /* Ensure that 'rx-current' equals 'rx-target' */
6966 f_trxc_fake_rssi(mp_uplink_power_target);
6967
6968 /* Establish a dedicated channel */
6969 f_est_dchan(more_ies := valueof(ies));
6970
6971 L1CTL.clear;
6972 T.start;
6973 alt {
6974 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6975 [] T.timeout {
6976 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6977 num_blocks, " were not handled");
6978 }
6979 }
6980}
6981testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6982 var ConnHdlr vc_conn;
6983 var ConnHdlrPars pars;
6984
6985 f_init();
6986
6987 /* Explicitly configure the Uplink power target (in dBm) */
6988 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6989
6990 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6991 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6992 log(testcasename(), ": starting on ", pars.chan_nr);
6993
6994 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6995 pars, trxc_comp := true);
6996 vc_conn.done;
6997 }
6998
6999 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7001}
7002
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007003/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7004private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7005runs on ConnHdlr {
7006 var integer num_blocks := 16;
7007 timer T := int2float(num_blocks);
7008
7009 f_l1_tune(L1CTL);
7010 RSL.clear;
7011
7012 /* These IEs are needed for autonomous MS power control */
7013 var template (value) RSL_IE_List ies := {
7014 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7015 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7016 }),
7017 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7018 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7019 })
7020 };
7021
7022 /* Ensure that 'rx-current' equals 'rx-target' */
7023 f_trxc_fake_rssi(mp_uplink_power_target);
7024
7025 /* Establish a dedicated channel */
7026 f_est_dchan(more_ies := valueof(ies));
7027
7028 L1CTL.clear;
7029 T.start;
7030 alt {
7031 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7032 [] T.timeout {
7033 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7034 num_blocks, " were not handled");
7035 }
7036 }
7037}
7038testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7039 var ConnHdlr vc_conn;
7040 var ConnHdlrPars pars;
7041
7042 f_init();
7043
7044 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7045 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7046 /* Explicitly configure the Uplink power range (target and delte) */
7047 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7048 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7049
7050 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7051 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7052 log(testcasename(), ": starting on ", pars.chan_nr);
7053
7054 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7055 pars, trxc_comp := true);
7056 vc_conn.done;
7057 }
7058
7059 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7061}
7062
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007063private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7064 var template L1ctlDlMessage tr_bad_frame;
7065 var L1ctlDlMessage l1_dl;
7066 timer T := 8.0;
7067
7068 f_l1_tune(L1CTL);
7069 RSL.clear;
7070
7071 f_est_dchan();
7072
7073 /* There may be a few errors right after the channel activation */
7074 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7075 L1CTL.clear;
7076
7077 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7078 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7079 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7080 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7081 tr_bad_frame.payload := ?;
7082
7083 T.start;
7084 alt {
7085 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7086 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7087 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7088 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7089 }
7090 [] as_l1_sacch();
7091 [] L1CTL.receive { repeat; }
7092 [] T.timeout {
7093 /* We're done, break the loop */
7094 setverdict(pass);
7095 }
7096 }
7097
7098 f_rsl_chan_deact();
7099 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7100}
7101testcase TC_speech_no_rtp_tchf() runs on test_CT {
7102 var ConnHdlr vc_conn;
7103 var ConnHdlrPars pars;
7104
7105 f_init();
7106
7107 /* TS1, TCH/F, V1 (FR codec) */
7108 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7109 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7110 vc_conn.done;
7111}
7112testcase TC_speech_no_rtp_tchh() runs on test_CT {
7113 var ConnHdlr vc_conn;
7114 var ConnHdlrPars pars;
7115
7116 f_init();
7117
7118 /* TS5, TCH/H, V1 (HR codec) */
7119 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7120 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7121 vc_conn.done;
7122}
7123
Harald Welte0472ab42018-03-12 15:02:26 +01007124/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7125/* protocol error as per 44.006 */
7126/* link layer failure (repetition of I-frame N200 times without ACK */
7127/* repetition of SABM or DISC N200 times without ACK */
7128/* receptiom of SABM in multi-frame established state */
7129
7130
Harald Welte68e495b2018-02-25 00:05:57 +01007131/* TODO Areas:
7132
7133* channel activation
7134** with BS_Power / MS_Power, bypassing power control loop
7135** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007136** with timing advance from initial activation on
7137* mode modify
7138** encryption
7139** multirate
7140* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007141** unsupported algorithm
7142* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007143* BS Power Control
7144* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007145* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007146* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007147** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007148* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007149** DATA_IND from BTS->PCU
7150** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007151
7152*/
Harald Welte70767382018-02-21 12:16:40 +01007153
7154control {
7155 execute( TC_chan_act_stress() );
7156 execute( TC_chan_act_react() );
7157 execute( TC_chan_deact_not_active() );
7158 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007159 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007160 execute( TC_sacch_filling() );
7161 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007162 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007163 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007164 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007165 execute( TC_sacch_chan_act_ho_async() );
7166 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007167 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007168 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007169 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007170 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007171 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007172 execute( TC_rach_load_idle_thresh0() );
7173 execute( TC_rach_load_idle_below_thresh() );
7174 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007175 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007176 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007177 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007178 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007179 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007180 execute( TC_meas_res_sign_tchf() );
7181 execute( TC_meas_res_sign_tchh() );
7182 execute( TC_meas_res_sign_sdcch4() );
7183 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007184 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007185 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007186 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007187 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007188 execute( TC_rsl_bs_pwr_static_ass() );
7189 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007190 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007191 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007192 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007193 execute( TC_rsl_ms_pwr_dyn_up() );
7194 execute( TC_rsl_ms_pwr_dyn_down() );
7195 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7196 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007197 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007198 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007199 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007200 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007201 execute( TC_paging_imsi_80percent() );
7202 execute( TC_paging_tmsi_80percent() );
7203 execute( TC_paging_imsi_200percent() );
7204 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007205 execute( TC_rsl_protocol_error() );
7206 execute( TC_rsl_mand_ie_error() );
7207 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007208 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007209 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007210 execute( TC_si_sched_2bis() );
7211 execute( TC_si_sched_2ter() );
7212 execute( TC_si_sched_2ter_2bis() );
7213 execute( TC_si_sched_2quater() );
7214 execute( TC_si_sched_13() );
7215 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007216 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007217 execute( TC_ipa_crcx_twice_not_active() );
7218 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007219 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007220 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007221
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007222 if (mp_pcu_socket != "") {
7223 execute( TC_pcu_act_req() );
7224 execute( TC_pcu_act_req_wrong_ts() );
7225 execute( TC_pcu_act_req_wrong_bts() );
7226 execute( TC_pcu_act_req_wrong_trx() );
7227 execute( TC_pcu_deact_req() );
7228 execute( TC_pcu_deact_req_wrong_ts() );
7229 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007230 if (mp_l1_supports_gprs) {
7231 execute( TC_pcu_data_req_pdtch() );
7232 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007233 execute( TC_pcu_data_req_wrong_bts() );
7234 execute( TC_pcu_data_req_wrong_trx() );
7235 execute( TC_pcu_data_req_wrong_ts() );
7236 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007237 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007238 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007239 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007240 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007241 execute( TC_pcu_data_req_imm_ass_pch() );
7242 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007243 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007244 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007245 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007246 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007247 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007248 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007249 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007250 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007251 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007252 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007253 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007254 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007255 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007256 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007257 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007258 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007259 execute( TC_dyn_osmo_pdch_act_deact() );
7260 execute( TC_dyn_osmo_pdch_double_act() );
7261 execute( TC_dyn_ipa_pdch_act_deact() );
7262 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7263
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007264 if (PCUIF_Types.mp_pcuif_version >= 10) {
7265 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007266 execute( TC_pcu_socket_nsvc_ipv4() );
7267 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007268 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007269 } else {
7270 log("PCU socket path not available, skipping PCU tests");
7271 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007272
Harald Welte3d04ae62018-04-04 20:29:05 +02007273 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007274 execute( TC_dyn_osmo_pdch_tchf_act() );
7275 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007276 execute( TC_dyn_ipa_pdch_tchf_act() );
7277 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007278
7279 execute( TC_rll_est_ind() );
7280 execute( TC_rll_est_req_DCCH_3() );
7281 execute( TC_rll_est_req_ACCH_3() );
7282 execute( TC_rll_rel_ind_DCCH_0() );
7283 execute( TC_rll_rel_ind_DCCH_3() );
7284 execute( TC_rll_rel_ind_ACCH_0() );
7285 execute( TC_rll_rel_ind_ACCH_3() );
7286 execute( TC_rll_rel_req() );
7287 execute( TC_rll_unit_data_req_DCCH() );
7288 execute( TC_rll_unit_data_req_ACCH() );
7289 execute( TC_rll_unit_data_ind_DCCH() );
7290 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007291
7292 execute( TC_chan_act_a51() );
7293 execute( TC_chan_act_a52() );
7294 execute( TC_chan_act_a53() );
7295 execute( TC_encr_cmd_a51() );
7296 execute( TC_encr_cmd_a52() );
7297 execute( TC_encr_cmd_a53() );
7298
Harald Welteee25aae2019-05-19 14:32:37 +02007299 execute( TC_err_rep_wrong_mdisc() );
7300 execute( TC_err_rep_wrong_msg_type() );
7301 execute( TC_err_rep_wrong_sequence() );
7302
Harald Weltee613f962018-04-18 22:38:16 +02007303 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007304
7305 execute( TC_tch_sign_l2_fill_frame() );
7306 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007307
7308 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007309 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007310
7311 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007312 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007313
7314 execute( TC_speech_no_rtp_tchf() );
7315 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007316}
7317
7318
7319}