blob: a0d668d64588ec98709e1ff50f6bfc86ec5ac7c0 [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
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001258 /* Send handover Access Burst and expect SACCH to start */
1259 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1260
1261 f_sacch_present(si5);
1262
Harald Welte8b01c792019-05-19 22:51:25 +02001263 f_rsl_chan_deact();
1264 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1265
1266
1267 /* Step 2: Activate ASYNC HO channel with MS power IE */
1268
1269 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001270 addl_ies := {
1271 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001272 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1273 };
1274 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1275 /* don't perform immediate assignment here, as we're testing non-IA case */
1276 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001277 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001278
1279 /* Verify that DL SACCH is being received */
1280 f_sacch_present(si5);
1281
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001282 /* Send handover Access Burst and expect SACCH to remain present */
1283 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1284
1285 f_sacch_present(si5);
1286
Harald Welte8b01c792019-05-19 22:51:25 +02001287 f_rsl_chan_deact();
1288 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1289}
1290testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1291 var ConnHdlr vc_conn;
1292 var ConnHdlrPars pars;
1293 f_init();
1294
1295 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1296 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1297 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1298 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1299 vc_conn.done;
1300 }
1301 /* TODO: do the above in parallel, rather than sequentially? */
1302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1303}
1304
1305/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1306 * see section 4.1.4 of 3GPP TS 48.058 */
1307private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1308 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001309 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1310
Harald Welte8b01c792019-05-19 22:51:25 +02001311 var RSL_IE_List addl_ies;
1312
1313 f_l1_tune(L1CTL);
1314 RSL.clear;
1315
1316 /* Step 1: Activate SYNC HO channel without MS power IE */
1317
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001318 var integer ho_ref := oct2int(f_rnd_octstring(1));
1319 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1320 RSL_IE_Body:{ handover_ref := ho_ref }));
1321 addl_ies := {
1322 ho_ref_ie
1323 };
1324
Harald Welte8b01c792019-05-19 22:51:25 +02001325 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001326 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 +02001327 /* don't perform immediate assignment here, as we're testing non-IA case */
1328 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001329 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001330
1331 /* Verify that no DL SACCH is being received */
1332 f_sacch_missing(?);
1333
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001334 /* Send handover Access Burst and expect SACCH to start */
1335 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1336
1337 f_sacch_present(si5);
1338
Harald Welte8b01c792019-05-19 22:51:25 +02001339 f_rsl_chan_deact();
1340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1341
1342
1343 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1344
1345 /* Activate channel on BTS side */
1346 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001347 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001348 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1349 };
1350 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1351 /* don't perform immediate assignment here, as we're testing non-IA case */
1352 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001353 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001354
1355 /* Verify that no DL SACCH is being received */
1356 f_sacch_missing(?);
1357
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001358 /* Send handover Access Burst and expect SACCH to start */
1359 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1360
1361 f_sacch_present(si5);
1362
Harald Welte8b01c792019-05-19 22:51:25 +02001363 f_rsl_chan_deact();
1364 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1365
1366
1367 /* Step 2b: Activate SYNC HO channel with TA IE */
1368
1369 /* Activate channel on BTS side */
1370 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001371 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001372 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 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 no DL SACCH is being received */
1380 f_sacch_missing(?);
1381
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001382 /* Send handover Access Burst and expect SACCH to start */
1383 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1384
1385 f_sacch_present(si5);
1386
Harald Welte8b01c792019-05-19 22:51:25 +02001387 f_rsl_chan_deact();
1388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1389
1390
1391 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1392
1393 /* Activate channel on BTS side */
1394 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001395 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001396 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1397 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1398 };
1399 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1400 /* don't perform immediate assignment here, as we're testing non-IA case */
1401 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001402 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001403
1404 /* Verify that DL SACCH is being received */
1405 f_sacch_present(si5);
1406
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001407 /* Send handover Access Burst and expect SACCH to remain present */
1408 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1409
1410 f_sacch_present(si5);
1411
Harald Welte8b01c792019-05-19 22:51:25 +02001412 f_rsl_chan_deact();
1413 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1414}
1415testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1416 var ConnHdlr vc_conn;
1417 var ConnHdlrPars pars;
1418 f_init();
1419
1420 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1421 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1422 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1423 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1424 vc_conn.done;
1425 }
1426 /* TODO: do the above in parallel, rather than sequentially? */
1427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1428}
Harald Welte629cc6b2018-03-11 17:19:05 +01001429
1430
1431/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001432 * RACH Handling
1433 ***********************************************************************/
1434
Harald Welte8c24c2b2018-02-26 08:31:31 +01001435/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001436private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001437 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001439 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001440
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001442 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001443 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001444 var OCT1 ra := f_rnd_ra_emerg();
1445 if (emerg == true) {
1446 ra := f_rnd_ra_emerg();
1447 } else {
1448 ra := f_rnd_ra_cs();
1449 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001450 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1451 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001453 }
1454 fn_last := fn;
1455
1456 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001457 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001459 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001460 T.stop;
1461 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001462 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001464 }
1465 [] RSL_CCHAN.receive { repeat; }
1466 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001467 test_failed := true;
1468 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 }
1470 }
1471 }
Maxba06feb2019-03-05 10:52:46 +01001472 if (test_failed) {
1473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001474 }
Maxba06feb2019-03-05 10:52:46 +01001475 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001477}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001478
Philipp Maier16ade782020-07-08 21:36:00 +02001479/* Normal variant */
1480testcase TC_rach_content() runs on test_CT {
1481 f_TC_rach_content(emerg := false);
1482}
1483
1484/* Emergency call variant */
1485testcase TC_rach_content_emerg() runs on test_CT {
1486 f_TC_rach_content(emerg := true);
1487}
1488
Harald Welte8c24c2b2018-02-26 08:31:31 +01001489/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1490testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001491 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001492 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001493 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001494 f_l1_tune(L1CTL);
1495
1496 var GsmFrameNumber fn_last := 0;
1497 for (var integer i := 0; i < 1000; i := i+1) {
1498 var OCT1 ra := f_rnd_ra_cs();
1499 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1500 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001502 }
1503 fn_last := fn;
1504 }
1505 var integer rsl_chrqd := 0;
1506 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001507 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001508 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001509 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001510 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001511 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001512 repeat;
1513 }
1514 [] RSL_CCHAN.receive { repeat; }
1515 [] T.timeout { }
1516 }
1517 if (rsl_chrqd == 1000) {
1518 setverdict(pass);
1519 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001521 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001523}
1524
Harald Welte3453ab42019-05-24 21:19:58 +02001525private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1526 var charstring bts_str := "bts " & int2str(bts_nr);
1527 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1528}
1529
1530/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1531private template integer tr_rach_slots_per_interval := (90 .. 130);
1532
1533/* Expect 0 RACH load on an idle BTS that has just started up */
1534testcase TC_rach_load_idle_thresh0() runs on test_CT {
1535 var ASP_RSL_Unitdata rx_ud;
1536
1537 f_init_vty_bsc();
1538 /* send load indications even at 0% load */
1539 f_vty_load_ind_thresh(0);
1540 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1541 f_sleep(2.0);
1542
1543 f_init();
1544
Harald Weltee37f9a52020-10-11 20:45:23 +02001545 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1546 alt {
1547 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1548 [] RSL_CCHAN.receive { repeat }
1549 }
1550
Harald Welte3453ab42019-05-24 21:19:58 +02001551 timer T := 5.0;
1552 T.start;
1553 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001554 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001555 setverdict(pass);
1556 repeat;
1557 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001558 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001559 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1560 repeat;
1561 }
1562 [] RSL_CCHAN.receive {
1563 repeat;
1564 }
1565 [] T.timeout { }
1566 }
1567
1568 f_vty_load_ind_thresh(10);
1569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1570}
1571
1572/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1573testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1574 var ASP_RSL_Unitdata rx_ud;
1575
1576 f_init_vty_bsc();
1577 f_init();
1578
1579 timer T := 5.0;
1580 T.start;
1581 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001582 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001583 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1584 repeat;
1585 }
1586 [] RSL_CCHAN.receive {
1587 repeat;
1588 }
1589 [] T.timeout {
1590 setverdict(pass);
1591 }
1592 }
1593
1594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1595}
1596
1597/* Expect 0 RACH load on an idle BTS that has just started up */
1598testcase TC_rach_load_count() runs on test_CT {
1599 var ASP_RSL_Unitdata rx_ud;
1600 var integer load_access_count := 0;
1601
1602 f_init_vty_bsc();
1603 /* send load indications even at 0% load */
1604 f_vty_load_ind_thresh(0);
1605 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1606 f_sleep(2.0);
1607 f_init();
1608
1609 f_init_l1ctl();
1610 f_sleep(1.0);
1611 f_l1_tune(L1CTL);
1612
Harald Welte52ae1682020-10-11 20:45:55 +02001613 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1614 alt {
1615 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1616 [] RSL_CCHAN.receive { repeat }
1617 }
1618
Harald Welte3453ab42019-05-24 21:19:58 +02001619 var GsmFrameNumber fn_last := 0;
1620 for (var integer i := 0; i < 1000; i := i+1) {
1621 var OCT1 ra := f_rnd_ra_cs();
1622 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1623 if (fn == fn_last) {
1624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1625 }
1626 fn_last := fn;
1627 }
1628
1629 timer T := 5.0;
1630 T.start;
1631 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001632 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001633 -> value rx_ud {
1634 var RSL_IE_Body ie;
1635 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1636 load_access_count := load_access_count + ie.rach_load.access_count;
1637 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1638 setverdict(fail, "Access count cannot be < Busy count");
1639 }
1640 repeat;
1641 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001642 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001643 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1644 repeat;
1645 }
1646 [] RSL_CCHAN.receive {
1647 repeat;
1648 }
1649 [] T.timeout { }
1650 }
1651 if (load_access_count == 1000) {
1652 setverdict(pass);
1653 } else {
1654 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1655 }
1656
1657 f_vty_load_ind_thresh(10);
1658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1659}
1660
Harald Welte54a2a2d2018-02-26 09:14:05 +01001661private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001662 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001663 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001664 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001665 f_sleep(0.5);
1666
1667 /* Transmit RACH request + wait for confirmation */
1668 var OCT1 ra := f_rnd_ra_cs();
1669 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1670
1671 /* Check for expected result */
1672 timer T := 1.5;
1673 T.start;
1674 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001675 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001676 setverdict(pass);
1677 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001678 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001680 }
1681 [] RSL_CCHAN.receive { repeat; }
1682 [not expect_pass] T.timeout {
1683 setverdict(pass);
1684 }
1685 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001687 }
1688 }
1689}
1690
1691/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1692testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001693 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001694 f_init_l1ctl();
1695 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001696 f_sleep(1.0);
1697
1698 /* default max-ta is 63 (full range of GSM timing advance */
1699
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001700 /* We allow early arrival up to 2 symbols */
1701 f_rach_toffs(-1*256, true);
1702 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001703 f_rach_toffs(-10*256, false);
1704
1705 /* 0 / 32 / 63 bits is legal / permitted */
1706 f_rach_toffs(0, true);
1707 f_rach_toffs(32*256, true);
1708 f_rach_toffs(63*256, true);
1709
1710 /* more than 63 bits is not legal / permitted */
1711 f_rach_toffs(64*256, false);
1712 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001714}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001715
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001716private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001717 var GsmFrameNumber fn;
1718 var RSL_Message rm;
1719
1720 f_l1_tune(L1CTL);
1721 RSL.clear;
1722
1723 /* Generate a random Handover Reference */
1724 var integer ho_ref := oct2int(f_rnd_octstring(1));
1725
1726 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1727 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1728 RSL_IE_Body:{ handover_ref := ho_ref }));
1729
1730 /* Activate a channel on the BTS side (no encryption) */
1731 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1732 act_type := t_RSL_IE_ActType_HO_SYNC);
1733
1734 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1735 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001736 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001737
1738 /* Send handover Access Burst */
1739 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1740
1741 /* TODO: test mismatching Handover Reference, and missing IE */
1742
1743 /* Wait for handover detection */
1744 timer T := 3.0;
1745 T.start;
1746 alt {
1747 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1748 log("Handover RACH has been detected: ", rm);
1749 setverdict(pass);
1750 }
1751 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1753 log2str("RSL_CHAN_RQD was not expected: ", rm));
1754 }
1755 [] RSL.receive { repeat; }
1756 [] T.timeout {
1757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1758 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1759 }
1760 }
1761
1762 /* Release the channel */
1763 f_rsl_chan_deact();
1764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1765}
1766
1767/* Test handover RACH detection */
1768testcase TC_ho_rach() runs on test_CT {
1769 var ConnHdlrPars pars;
1770 var ConnHdlr vc_conn;
1771
1772 f_init();
1773
1774 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1775 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1776 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1777 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1778 vc_conn.done;
1779 }
1780
1781 /* TODO: do the above in parallel, rather than sequentially? */
1782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1783}
1784
Harald Welte93640c62018-02-25 16:59:33 +01001785/***********************************************************************
1786 * Measurement Processing / Reporting
1787 ***********************************************************************/
1788
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001789private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001790 spare := '0'B,
1791 lpd := 0,
1792 sapi := sapi,
1793 c_r := c_r,
1794 ea := true
1795}
1796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001797private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001798 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001799 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001800 len := 0, /* overwritten */
1801 m := false,
1802 el := 1,
1803 payload := pl
1804}
1805
1806/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001807private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001808 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001809 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001810 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001811 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 +01001812 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001813 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001814
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001815 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1816 g_pars.l1_pars.ms_power_level, false,
1817 g_pars.l1_pars.ms_actual_ta);
1818
1819 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1820 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1821
1822 log("Sending Measurement Report: ", l1h, l2);
1823 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001824 repeat;
1825 }
1826}
1827
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001828private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001829 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001830 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001831 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1832 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001833 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1834 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001835 repeat;
1836 }
1837}
1838
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001839private altstep as_l1_tch_loop() runs on ConnHdlr {
1840 var L1ctlDlMessage l1_dl;
1841 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1842 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001843
1844 /* occasionaly inject FACCH frames into the uplink */
1845 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1846 var octetstring pl := '010301'O;
1847 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1848 f_pad_oct(pl, 23, '2B'O)));
1849 } else {
1850 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1851 l1_dl.payload.traffic_ind.data));
1852 }
1853
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001854 repeat;
1855 }
1856}
1857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001858private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001859 uint6_t rxlev,
1860 uint3_t rxqual
1861}
1862
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001863private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001864 MeasElem full,
1865 MeasElem sub
1866}
1867
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001868private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001869 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001870 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001871 MeasElemFS meas_ul,
1872 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001873 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001874 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001875 uint8_t ms_actual_ta,
1876 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001877}
1878
1879/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1880private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1881 return 63 + (toffs256s/256);
1882}
1883
Harald Welted5684392018-03-10 18:22:04 +01001884private function f_max(integer a, integer b) return integer {
1885 if (a > b) {
1886 return a;
1887 } else {
1888 return b;
1889 }
1890}
1891
1892private function f_min(integer a, integer b) return integer {
1893 if (a < b) {
1894 return a;
1895 } else {
1896 return b;
1897 }
1898}
1899
1900/* compute negative tolerance val-tolerance, ensure >= min */
1901private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1902 val := val - tolerance;
1903 return f_max(val, min);
1904}
1905
1906/* compute positive tolerance val+tolerance, ensure <= max */
1907private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1908 val := val + tolerance;
1909 return f_min(val, max);
1910}
1911
1912/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1913private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1914return template integer {
1915 var template integer ret;
1916 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1917 return ret;
1918}
1919
1920
Harald Welte70767382018-02-21 12:16:40 +01001921/* build a template for matching measurement results against */
1922private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1923 var ConnL1Pars l1p := g_pars.l1_pars;
1924 var template RSL_IE_UplinkMeas ul_meas := {
1925 len := 3,
1926 rfu := '0'B,
1927 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001928 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001929 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001930 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001931 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001932 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1933 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001934 supp_meas_info := omit
1935 };
Harald Welte685d5982018-02-27 20:42:05 +01001936 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001937 ul_meas.len := (3+8);
1938 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001939 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001940 toa256_min := ?,
1941 toa256_max := ?,
1942 toa256_std_dev := ?
1943 }
Harald Welte685d5982018-02-27 20:42:05 +01001944 }
Harald Welte70767382018-02-21 12:16:40 +01001945 var template RSL_IE_BS_Power bs_power := {
1946 reserved := 0,
1947 epc := false,
1948 fpc := false,
1949 power_level := l1p.bs_power_level
1950 };
1951 var template RSL_IE_L1Info l1_info := {
1952 ms_power_lvl := l1p.ms_power_level,
1953 fpc := false,
1954 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001955 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001956 };
1957 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001958 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001959 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1960 ?, t_toffs);
1961}
1962
Philipp Maierdd841d32019-12-17 14:44:54 +01001963/* build a template for matching measurement results that do not contain any
1964 * MS related measurement (l1_info, l3_info and ms timing offset). */
1965private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1966 var ConnL1Pars l1p := g_pars.l1_pars;
1967 var template RSL_IE_UplinkMeas ul_meas := {
1968 len := 3,
1969 rfu := '0'B,
1970 dtx_d := l1p.dtx_enabled,
1971 rxlev_f_u := ?,
1972 reserved1 := '00'B,
1973 rxlev_s_u := ?,
1974 reserved2 := '00'B,
1975 rxq_f_u := ?,
1976 rxq_s_u := ?,
1977 supp_meas_info := omit
1978 };
1979 if (l1p.toa256_enabled) {
1980 ul_meas.len := (3+8);
1981 ul_meas.supp_meas_info := {
1982 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1983 toa256_min := ?,
1984 toa256_max := ?,
1985 toa256_std_dev := ?
1986 }
1987 }
1988 var template RSL_IE_BS_Power bs_power := {
1989 reserved := 0,
1990 epc := false,
1991 fpc := false,
1992 power_level := l1p.bs_power_level
1993 };
1994
1995 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1996}
1997
Harald Welte70767382018-02-21 12:16:40 +01001998/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001999private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002000 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002001 var boolean chan_est := false;
2002
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002003 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002004
2005 /* Receive osmocom specific measurement reports. This is the normal
2006 * case. Here we verify that the measurement reports we sent are
2007 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002008 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2009 /* increment counter of next to-be-expected meas rep */
2010 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2011 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002012 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002013
2014 /* The following two cases may only happen in the beginning
2015 * of the channel establishment phase. Once we have received
2016 * the "our" measurement report the first time, the channel
2017 * is established and empty or hardcoded TRXCON reports must
2018 * not occur anymore. */
2019 chan_est := true;
2020
2021 repeat;
2022 }
2023
2024 /* When the BTS has established the channel, the MS might need slightly
2025 * more time to establish the channel and actually start sending. The
2026 * result is then a measurement report that just lacks the measurement
2027 * information of the MS. This is normal and we tolerate this behavior. */
2028 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2029 /* increment counter of next to-be-expected meas rep */
2030 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2031 /* Re-start the timer expecting the next MEAS RES */
2032 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002033 repeat;
2034 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002035
2036 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2037 * measurements if the TTCN3 side does not supply measurement input in
2038 * time. In those cases TRXCON will either use a cached measurement
2039 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2040 * report the templates above will not match. We tolerate this
2041 * behavior, but only once. */
2042 [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 +01002043 /* increment counter of next to-be-expected meas rep */
2044 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2045 if (g_first_meas_res) {
2046 g_first_meas_res := false;
2047 repeat;
2048 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002050 }
Harald Welte70767382018-02-21 12:16:40 +01002051 }
2052 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002054 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002055 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002057 }
2058}
2059
Harald Weltee613f962018-04-18 22:38:16 +02002060private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2061 select (rsl_alg_id) {
2062 case (RSL_ALG_ID_A5_0) { return 0; }
2063 case (RSL_ALG_ID_A5_1) { return 1; }
2064 case (RSL_ALG_ID_A5_2) { return 2; }
2065 case (RSL_ALG_ID_A5_3) { return 3; }
2066 case (RSL_ALG_ID_A5_4) { return 4; }
2067 case (RSL_ALG_ID_A5_5) { return 5; }
2068 case (RSL_ALG_ID_A5_6) { return 6; }
2069 case (RSL_ALG_ID_A5_7) { return 7; }
2070 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2072 /* Make compiler happy by calling mtc.stop here. It is already
2073 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002074 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002075 }
2076 }
2077}
2078
2079private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2080 select (rsl_alg_id) {
2081 case (RSL_ALG_ID_A5_1) { return '000'B; }
2082 case (RSL_ALG_ID_A5_2) { return '001'B; }
2083 case (RSL_ALG_ID_A5_3) { return '010'B; }
2084 case (RSL_ALG_ID_A5_4) { return '011'B; }
2085 case (RSL_ALG_ID_A5_5) { return '100'B; }
2086 case (RSL_ALG_ID_A5_6) { return '101'B; }
2087 case (RSL_ALG_ID_A5_7) { return '110'B; }
2088 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2090 /* Make compiler happy by calling mtc.stop here. It is already
2091 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002092 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002093 }
2094 }
2095}
2096
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002097/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2098private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2099 var GsmFrameNumber fn;
2100 timer T := 8.0;
2101
2102 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2103 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2104
2105 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2106 /* Send the actual RACH */
2107 fn := f_L1CTL_RACH(L1CTL, ra);
2108
2109 T.start;
2110 alt {
2111 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2112 [] T.timeout {
2113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2114 }
2115 }
2116 T.stop
2117 return fn;
2118}
Harald Weltee613f962018-04-18 22:38:16 +02002119
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002120/* Tune to a dedicated channel: L1CTL only */
2121private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002122 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002123 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2124 7 /* TODO: mp_tsc */,
2125 mp_trx0_arfcn));
2126 } else {
2127 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2128 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002129 pars.fhp.maio_hsn.hsn,
2130 pars.fhp.maio_hsn.maio,
2131 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002132 }
2133}
2134
Harald Welte70767382018-02-21 12:16:40 +01002135/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002136private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002137 var GsmFrameNumber fn;
2138 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002139 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002140 var integer ra := 23;
2141
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002142 /* Send RACH request and wait for ChanReq */
2143 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002144
2145 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002146 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002147
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002148 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002149 if (g_pars.fhp.enabled) {
2150 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002151 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002152 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002153 }
2154
Harald Welte70767382018-02-21 12:16:40 +01002155 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002156 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 +01002157 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2158
2159 /* receive IMM.ASS on MS side */
2160 var ImmediateAssignment ia_um;
2161 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002162
2163 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2164 if (ch_desc.h != ia_um.chan_desc.h) {
2165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2166 }
2167
Harald Welte70767382018-02-21 12:16:40 +01002168 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002169 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002170 /* enable encryption, if requested */
2171 if (encr_enable) {
2172 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2173 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2174 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002175
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002176 /* Send TCH Mode Request to the L1 if needed */
2177 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2178 var L1ctlTchMode tch_mode;
2179
2180 select (g_pars.chan_mode.coding_alg_rate) {
2181 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2182 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2183 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2184 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2185 case else {
2186 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2187 " is not supported by the L1, falling back to signalling");
2188 tch_mode := L1CTL_CHAN_MODE_SIGN;
2189 }
2190 }
2191
2192 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2193 }
2194
Harald Weltefa45e9e2018-03-10 18:59:03 +01002195 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002196}
2197
2198/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002199private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002200 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002201 RSL.clear;
2202
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002203 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002204 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002205 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002206 }
Harald Welte70767382018-02-21 12:16:40 +01002207
2208 f_est_dchan();
2209
2210 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2211 * RSL measurement reports on Abis side */
2212 timer T := 8.0;
2213 T.start;
2214 alt {
2215 [] as_l1_sacch();
2216 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002217 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002218 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002219 [] L1CTL.receive { repeat; }
2220 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002221 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002222 * of any earlier errors, so if we reach this timeout, we're good */
2223 setverdict(pass);
2224 }
2225 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002227 }
2228 }
2229 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002230 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002231}
Harald Welte0472ab42018-03-12 15:02:26 +01002232
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002233/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2234private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002235 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002236 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2237 timer Tup := 10.0;
2238 Tup.start;
2239 alt {
2240 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2241 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2242 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002243
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002244 if (rx_lvl != max_rx_lvl) {
2245 repeat;
2246 }
2247 Tup.stop;
2248 }
2249 [] L1CTL.receive { repeat; }
2250 [] Tup.timeout {
2251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2252 log2str("Didn't reach full power ", max_rx_lvl));
2253 }
2254 }
2255 return max_rx_lvl;
2256}
2257
2258/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2259private function f_verify_ramp_up() runs on ConnHdlr {
2260 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002261 var integer initial_rx_lvl := -1;
2262 var integer last_rx_lvl := -1;
2263 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2264
2265 timer T := 2.0;
2266 alt {
2267 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2268 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2269 log("Received rx_level=", rx_lvl);
2270 if (initial_rx_lvl == -1) {
2271 initial_rx_lvl := rx_lvl;
2272 last_rx_lvl := rx_lvl;
2273
2274 /* Expect a somehow low value during first received messages */
2275 if (initial_rx_lvl >= max_rx_lvl / 2) {
2276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2277 log2str("Detected high initial tx power during ramp up: ",
2278 initial_rx_lvl , ", full power is", max_rx_lvl));
2279 }
2280 }
2281
2282 /* received Rx level bigger than maximum allowed power by CN */
2283 if (rx_lvl > max_rx_lvl) {
2284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2285 log2str("Detected Tx power higher than full power: ",
2286 rx_lvl , " > ", max_rx_lvl));
2287 }
2288
2289 /* Make sure it never decreases, since we are rumping up */
2290 if (last_rx_lvl > rx_lvl) {
2291 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2292 log2str("Detected Tx power decrease during ramp up: ",
2293 last_rx_lvl , " -> ", rx_lvl));
2294 }
2295
2296 if (rx_lvl == max_rx_lvl and not T.running) {
2297 /* We reached the maximum power, start timer and receive
2298 /* a few more to make sure we don't surpass it */
2299 log("Reached full power, wating a bit more until success");
2300 T.start;
2301 }
2302
2303 last_rx_lvl := rx_lvl;
2304 repeat;
2305 }
2306 [] L1CTL.receive { repeat; }
2307 [] T.timeout { }
2308 }
2309
2310 /* We didn't increase tx power during ramp up */
2311 if (initial_rx_lvl < last_rx_lvl) {
2312 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2313 } else {
2314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2315 log2str("No Tx power increase during whole ramp up: ",
2316 initial_rx_lvl , " -> ", last_rx_lvl));
2317 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002318}
2319
2320/* verify BTS ramps power down to rx_level 0 */
2321private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2322 var L1ctlDlMessage l1_dl;
2323 var integer last_rx_lvl := max_rx_lvl;
2324
2325 timer Tdown := 5.0;
2326 Tdown.start;
2327 alt {
2328 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2329 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2330 log("Received rx_level=", rx_lvl);
2331
2332 /* received Rx level bigger than maximum allowed power by CN */
2333 if (rx_lvl > max_rx_lvl) {
2334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2335 log2str("Detected Tx power higher than full power: ",
2336 rx_lvl , " > ", max_rx_lvl));
2337 }
2338
2339 /* Make sure it never increases, since we are rumping down */
2340 if (last_rx_lvl < rx_lvl) {
2341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2342 log2str("Detected Tx power increase during ramp up: ",
2343 last_rx_lvl , " -> ", rx_lvl));
2344 }
2345
2346 last_rx_lvl := rx_lvl;
2347 if (last_rx_lvl != 0) {
2348 repeat;
2349 }
2350 /* we reached power level 0, we are done */
2351 Tdown.stop;
2352 }
2353 [] L1CTL.receive { repeat; }
2354 [] Tdown.timeout { }
2355 }
2356
2357 /* We didn't increase tx power during ramp down */
2358 if (max_rx_lvl > last_rx_lvl) {
2359 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2360 } else {
2361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2362 log2str("No Tx power decrease during whole ramp down: ",
2363 max_rx_lvl , " -> ", last_rx_lvl));
2364 }
2365}
2366
2367/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002368private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002369 f_l1_tune(L1CTL);
2370 RSL.clear;
2371
2372 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002373
2374 setverdict(pass);
2375}
2376testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2377 var ConnHdlr vc_conn;
2378 var ConnHdlrPars pars;
2379 f_init();
2380 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2381 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2382 pcu_comp := false, trxc_comp := true);
2383 vc_conn.done;
2384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2385}
2386
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002387/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002388private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002389 f_connhdlr_init_vty_bsc();
2390
2391 f_l1_tune(L1CTL);
2392 RSL.clear;
2393
2394 /* Wait until BTS is started and at full power */
2395 var integer max_rx_lvl := f_wait_ramp_up();
2396 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2397
2398 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2399 f_verify_ramp_down(max_rx_lvl);
2400
2401 setverdict(pass);
2402}
2403testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2404 var ConnHdlr vc_conn;
2405 var ConnHdlrPars pars;
2406 f_init();
2407 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2408 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2409 pcu_comp := false, trxc_comp := true);
2410 vc_conn.done;
2411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2412}
2413
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002414/* Verify Tx power:
2415 * + ramping down during ADM state UNLOCKED->LOCKED
2416 * + ramping up during ADM state LOCKED->UNLOCKED
2417 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002418private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002419 var L1ctlDlMessage l1_dl;
2420 var integer last_rx_lvl;
2421
2422 f_connhdlr_init_vty_bsc();
2423
2424 f_l1_tune(L1CTL);
2425 RSL.clear;
2426
2427 /* Wait until BTS is started and at full power */
2428 var integer max_rx_lvl := f_wait_ramp_up();
2429 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2430
2431 log("ADM STATE UNLOCKED->LOCKED");
2432 f_vty_enter_cfg_trx(BSCVTY);
2433 f_vty_transceive(BSCVTY, "rf_locked 1");
2434 last_rx_lvl := max_rx_lvl;
2435 f_verify_ramp_down(max_rx_lvl);
2436
2437 /* Let some time after we received 0dBm, then check we don't receive BCCH
2438 * anymore because scheduler has stopped after ramping down */
2439 f_sleep(2.0);
2440 L1CTL.clear;
2441 timer Tlocked := 2.0;
2442 Tlocked.start;
2443 alt {
2444 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2446 log2str("Received data_ind during rf_locked: ", l1_dl));
2447 }
2448 [] L1CTL.receive { repeat; }
2449 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2450 }
2451
2452 log("ADM STATE LOCKED->UNLOCKED");
2453 f_vty_transceive(BSCVTY, "rf_locked 0");
2454 f_verify_ramp_up();
2455 setverdict(pass);
2456}
2457testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2458 var ConnHdlr vc_conn;
2459 var ConnHdlrPars pars;
2460 f_init();
2461 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2462 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2463 pcu_comp := false, trxc_comp := true);
2464 vc_conn.done;
2465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2466}
2467
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002468private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002469 timer T := 8.0;
2470 T.start;
2471 var RSL_Message rsl;
2472 alt {
2473 [] as_l1_sacch();
2474 [] L1CTL.receive { repeat; }
2475 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2476 if (rsl.ies[3].body.bs_power.power_level == level) {
2477 setverdict(pass)
2478 } else {
2479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2480 }
2481 }
2482 [] T.timeout {
2483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2484 }
2485 }
2486}
2487
2488/* see if the rsl meas res contains our expeced bs power level
2489bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002490private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002491 f_l1_tune(L1CTL);
2492 RSL.clear;
2493
2494 if (mp_bts_trxc_port != -1) {
2495 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2496 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2497 }
2498
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002499 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002500 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2501 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2502
2503 f_est_dchan(more_ies :={valueof(pwr)});
2504
2505 f_check_meas_bs_power_level(pwr_var);
2506
2507 f_rsl_chan_deact();
2508 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2509}
2510
2511/* see if the rsl meas res contains our expeced bs power level
2512bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002513private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002514 f_l1_tune(L1CTL);
2515 RSL.clear;
2516
2517 if (mp_bts_trxc_port != -1) {
2518 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2519 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2520 }
2521
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002522 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002523 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2524
2525 f_est_dchan();
2526
2527 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2528
2529 f_check_meas_bs_power_level(pwr_var);
2530
2531 f_rsl_chan_deact();
2532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2533}
2534
2535testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2536 var ConnHdlr vc_conn;
2537 var ConnHdlrPars pars;
2538 f_init();
2539 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2540 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2541 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2542 pcu_comp := false, trxc_comp := true);
2543 vc_conn.done;
2544 }
2545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2546}
2547
2548testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2549 var ConnHdlr vc_conn;
2550 var ConnHdlrPars pars;
2551 f_init();
2552 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2553 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2554 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2555 pcu_comp := false, trxc_comp := true);
2556 vc_conn.done;
2557 }
2558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2559}
2560
Eric Wild61edb7e2019-06-03 12:38:31 +02002561/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2562second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2563These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002564private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002565 var uint5_t pwr_var := 7;
2566 var L1ctlDlMessage l1_dl;
2567
2568 f_trxc_fake_rssi(rxlev2dbm(10));
2569 f_l1_tune(L1CTL);
2570 RSL.clear;
2571
2572 var RSL_IE_List addl_ies;
2573 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2574
2575 addl_ies := {
2576 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2577 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2578 };
2579
2580 /* establish with power parameters */
2581 f_est_dchan(more_ies := addl_ies);
2582
2583 /* set a high value to ensure L1 power control level increases */
2584 f_trxc_fake_rssi(rxlev2dbm(20));
2585
2586 timer T2 := 6.0;
2587 T2.start;
2588 alt {
2589 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002590 /* Update sent MS power to follow what BTS requests */
2591 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2592 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002593 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002594 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002595 T2.stop;
2596 }
2597 [] L1CTL.receive { repeat; }
2598 [] T2.timeout {
2599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2600 "Power Level in L1 header has not increased sufficiently");
2601 }
2602 }
2603
2604 /* set a low value to ensure L1 power control level decreases */
2605 f_trxc_fake_rssi(rxlev2dbm(0));
2606
2607 timer T4 := 6.0;
2608 T4.start;
2609 alt {
2610 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002611 /* Update sent MS power to follow what BTS requests */
2612 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2613 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002614 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002615 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002616 T4.stop;
2617 setverdict(pass, "Power level in L1 decreased/increased as expected");
2618 }
2619 [] L1CTL.receive { repeat; }
2620 [] T4.timeout {
2621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2622 "Power Level in L1 header has not decreased sufficiently");
2623 }
2624 }
2625
2626 f_rsl_chan_deact();
2627 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2628
2629}
2630
2631/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002632private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002633 var uint5_t pwr_var := 7;
2634 var L1ctlDlMessage l1_dl;
2635
2636 /* set a low value to ensure power increases */
2637 f_trxc_fake_rssi(rxlev2dbm(10));
2638 f_l1_tune(L1CTL);
2639 RSL.clear;
2640
2641 var RSL_IE_List addl_ies;
2642 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2643
2644 addl_ies := {
2645 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2646 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2647 };
2648
2649 /* establish with power parameters */
2650 f_est_dchan(more_ies := addl_ies);
2651
2652 timer T1 := 10.0;
2653 T1.start;
2654 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002655 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2656 /* Update sent MS power to follow what BTS requests */
2657 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2658 repeat;
2659 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002660 [] L1CTL.receive { repeat; }
2661 [] T1.timeout {
2662 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2663 setverdict(fail, "Power level in L1 header should not have changed");
2664 }
2665 }
2666 }
2667
2668 f_rsl_chan_deact();
2669 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2670
2671}
2672
2673/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002674private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002675 var L1ctlDlMessage l1_dl;
2676 var uint5_t pwr_var := 15;
2677 var uint5_t pwr_max_var := f_get_max_power_from_band();
2678
2679 /* set a low value to ensure power increases */
2680 f_trxc_fake_rssi(rxlev2dbm(10));
2681 f_l1_tune(L1CTL);
2682 RSL.clear;
2683
2684 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2685 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2686
2687 /* establish with fixed power level */
2688 f_est_dchan(more_ies :={valueof(pwr)});
2689
2690 /* check our initial power level */
2691 f_wait_for_l1_power_level(pwr_var);
2692
2693 /* update power param to enable power loop
2694 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2695 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2696
2697 /* wait, then check that our power level was reduced */
2698 timer T1 := 10.0;
2699 T1.start;
2700 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002701 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2702 /* Update sent MS power to follow what BTS requests */
2703 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2704 repeat;
2705 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002706 [] L1CTL.receive { repeat; }
2707 [] T1.timeout {
2708 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2709 if( f_power_level_is_highest_dbm(rcv) ){
2710 setverdict(pass, "Power level in L1 header reduced as expected");
2711 } else {
2712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2713 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2714 }
2715 }
2716 }
2717
2718 f_rsl_chan_deact();
2719 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2720
2721}
2722
2723/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002724private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002725 var L1ctlDlMessage l1_dl;
2726
2727 /* set a high value to ensure power decreases */
2728 f_trxc_fake_rssi(rxlev2dbm(50));
2729 f_l1_tune(L1CTL);
2730 RSL.clear;
2731
2732 var uint5_t pwr_var := 5;
2733 var uint5_t pwr_target_val := 15;
2734
2735 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2736 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2737
2738 /* establish with fixed power level */
2739 f_est_dchan(more_ies :={valueof(pwr)});
2740
2741 /* check our initial power level */
2742 f_wait_for_l1_power_level(pwr_var);
2743
2744 /* update power param to enable power loop
2745 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002746 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002747
2748 /* wait, then check that our power level was increased */
2749 timer T1 := 10.0;
2750 T1.start;
2751 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002752 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2753 /* Update sent MS power to follow what BTS requests */
2754 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2755 repeat;
2756 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002757 [] L1CTL.receive { repeat; }
2758 [] T1.timeout {
2759 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2760 setverdict(pass, "Power level in L1 header increased to lowest power value");
2761 } else {
2762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2763 "Power level in L1 header NOT increased to lowest power value");
2764 }
2765 }
2766 }
2767
2768 f_rsl_chan_deact();
2769 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2770
2771}
2772
Eric Wild095024b2019-06-17 15:08:57 +02002773/* see if we change the power level without receiving power parameters, which should not happen
2774rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002775private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002776 var L1ctlDlMessage l1_dl;
2777
2778 /* set a high value to ensure power decreases */
2779 f_trxc_fake_rssi(rxlev2dbm(50));
2780 f_l1_tune(L1CTL);
2781 RSL.clear;
2782
2783 var uint5_t pwr_var := 5;
2784
2785 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2786 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2787
2788 /* establish with fixed power level */
2789 f_est_dchan(more_ies :={valueof(pwr)});
2790
2791 /* check our initial power level */
2792 f_wait_for_l1_power_level(pwr_var);
2793
2794 /* wait, then check that our power level did not change */
2795 timer T1 := 10.0;
2796 T1.start;
2797 alt {
2798 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2799 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2801 "BS power control should not be active unless we receive a power parameters IE!");
2802 }
2803 repeat;
2804 }
2805 [] L1CTL.receive { repeat; }
2806 [] T1.timeout { setverdict(pass); }
2807 }
2808
2809 f_rsl_chan_deact();
2810 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2811
2812}
2813
Eric Wild095024b2019-06-17 15:08:57 +02002814/* see if we change the power level without receiving power parameters, which should not happen
2815ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002816private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002817 var L1ctlDlMessage l1_dl;
2818
2819 /* set a high value to ensure power decreases */
2820 f_trxc_fake_rssi(rxlev2dbm(50));
2821 f_l1_tune(L1CTL);
2822 RSL.clear;
2823
2824 var uint5_t pwr_var := 5;
2825
2826 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2827 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2828
2829 /* establish with fixed power level */
2830 f_est_dchan(more_ies :={valueof(pwr)});
2831
2832 /* check our initial power level */
2833 f_wait_for_l1_power_level(pwr_var);
2834
2835 /* pwr control without power params IE, should NOT activate MS power control*/
2836 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2837
2838 /* wait, then check that our power level did not change */
2839 timer T1 := 10.0;
2840 T1.start;
2841 alt {
2842 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2843 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2845 "BS power control should not be active unless we receive a power parameters IE!");
2846 }
2847 repeat;
2848 }
2849 [] L1CTL.receive { repeat; }
2850 [] T1.timeout { setverdict(pass); }
2851 }
2852
2853 f_rsl_chan_deact();
2854 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2855
2856}
2857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002858private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002859 var L1ctlDlMessage l1_dl;
2860 timer T0 := 10.0;
2861 T0.start;
2862 alt {
2863 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2864 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2866 "Power level in L1 header != signaled (RSL) power level.");
2867 }
2868 }
2869 [] L1CTL.receive { repeat; }
2870 [] T0.timeout {
2871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2872 "Timeout waiting for initial power level");
2873 }
2874 }
2875 T0.stop;
2876}
2877
2878private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2879 var IntegerRecord min_dbm_level;
2880 var IntegerRecord max_dbm_level;
2881 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2882
2883 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2884 if (min_dbm_level[i] == level) {
2885 return true;
2886 }
2887 }
2888 return false;
2889}
2890
2891private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2892 var IntegerRecord min_dbm_level;
2893 var IntegerRecord max_dbm_level;
2894 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2895
2896 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2897 if (max_dbm_level[i] == level) {
2898 return true;
2899 }
2900 }
2901 return false;
2902}
2903
2904private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2905 var IntegerRecord min_dbm_level;
2906 var IntegerRecord max_dbm_level;
2907 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2908 return max_dbm_level[0];
2909}
2910
2911type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002912private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002913private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2914 // 45.005 4.1.1
2915 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2916 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2917 2, 1, 0};
2918 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2919 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2920 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2921 var IntegerRecord rv;
2922
2923 select(band){
2924 case (BtsBand_allGSM){
2925 rv := gsm_power;
2926 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2927 max_dbm_level := {2, 1, 0};
2928 }
2929 case("DCS1800"){
2930 rv := dcs_power;
2931 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2932 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2933 }
2934 case("PCS1900"){
2935 rv := pcs_power;
2936 min_dbm_level := {15};
2937 max_dbm_level := {30};
2938 }
Harald Welte194b6912020-10-11 21:01:55 +02002939 case else {
2940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2941 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002942 }
2943
2944 return rv;
2945}
2946
2947private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002948 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 +02002949}
2950
2951testcase TC_rsl_ms_pwr_dyn_ass_updown() 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 -100");
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_ass_updown), 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_up() 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 -10");
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_up), 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
2981testcase TC_rsl_ms_pwr_dyn_max() 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 -10");
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_max), 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
2996testcase TC_rsl_ms_pwr_dyn_down() 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_down), 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
Eric Wild280ccb82019-06-17 11:11:52 +02003011testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3012 var ConnHdlr vc_conn;
3013 var ConnHdlrPars pars;
3014 f_init();
3015 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3016 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3017 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3018 pars.bts0_band := f_vty_get_bts0_band();
3019 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3020 vc_conn.done;
3021 }
3022 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3024}
3025
Eric Wild095024b2019-06-17 15:08:57 +02003026testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3027 var ConnHdlr vc_conn;
3028 var ConnHdlrPars pars;
3029 f_init();
3030 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3031 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3032 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3033 pars.bts0_band := f_vty_get_bts0_band();
3034 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3035 vc_conn.done;
3036 }
3037 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3039}
3040
Philipp Maier149c3922020-10-22 17:29:36 +02003041function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003042 var template RSL_IE_ChannelMode ch_mode;
3043 var ConnHdlr vc_conn;
3044 var ConnHdlrPars pars;
3045 f_init();
3046 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3047 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3048 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003049 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003050 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3051 pcu_comp := false, trxc_comp := true);
3052 vc_conn.done;
3053 }
3054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3055}
Philipp Maier149c3922020-10-22 17:29:36 +02003056
3057testcase TC_meas_res_speech_tchf() runs on test_CT {
3058 f_TC_meas_res_speech_tchf(false);
3059}
3060
3061testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3062 f_TC_meas_res_speech_tchf(true);
3063}
3064
3065function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003066 var template RSL_IE_ChannelMode ch_mode;
3067 var ConnHdlr vc_conn;
3068 var ConnHdlrPars pars;
3069 f_init();
3070 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3071 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3072 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003073 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003074 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3075 pcu_comp := false, trxc_comp := true);
3076 vc_conn.done;
3077 }
3078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3079}
Philipp Maier149c3922020-10-22 17:29:36 +02003080
3081testcase TC_meas_res_speech_tchh() runs on test_CT {
3082 f_TC_meas_res_speech_tchh(false)
3083}
3084
3085testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3086 f_TC_meas_res_speech_tchh(true)
3087}
3088
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003089testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3090 var template RSL_IE_ChannelMode ch_mode;
3091 var ConnHdlr vc_conn;
3092 var ConnHdlrPars pars;
3093 f_init();
3094 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3095 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3096 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3097 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3098 pars.l1_pars.toa256_enabled := true;
3099 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3100 pcu_comp := false, trxc_comp := true);
3101 vc_conn.done;
3102 }
3103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3104}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003105
Harald Welte70767382018-02-21 12:16:40 +01003106testcase TC_meas_res_sign_tchf() runs on test_CT {
3107 var ConnHdlr vc_conn;
3108 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003109 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003110 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003111 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003112 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3113 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003114 vc_conn.done;
3115 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003117}
3118testcase TC_meas_res_sign_tchh() runs on test_CT {
3119 var ConnHdlr vc_conn;
3120 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003121 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003122 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003123 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003124 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3125 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003126 vc_conn.done;
3127 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003129}
3130testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3131 var ConnHdlr vc_conn;
3132 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003133 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003134 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3135 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003136 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3137 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003138 vc_conn.done;
3139 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003141}
3142testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3143 var ConnHdlr vc_conn;
3144 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003145 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003146 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3147 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003148 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3149 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003150 vc_conn.done;
3151 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003153}
Harald Welte685d5982018-02-27 20:42:05 +01003154testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3155 var ConnHdlr vc_conn;
3156 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003157 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003158 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3159 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003160 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003161 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003162 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3163 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003164 vc_conn.done;
3165 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003167}
3168
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003169/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3170 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003171private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003172 var L1ctlDlMessage l1_dl;
3173 var RSL_IE_MS_Power ms_power;
3174 var RSL_Message rsl;
3175 var uint5_t power_level := 0;
3176
3177 f_l1_tune(L1CTL);
3178 RSL.clear;
3179
3180 f_est_dchan();
3181
3182 ms_power.reserved := 0;
3183 ms_power.fpc_epc := false;
3184
3185 /* Send the first power control command. This will disable any BTS/TRX
3186 * internal power control and switch the MS (which is not in scope of
3187 * this test) to a constant power level. We start with a power level
3188 * of 0 */
3189 ms_power.power_level := power_level;
3190 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3191 RSL.send(rsl);
3192
3193 alt {
3194
3195 /* Pick all SACCH blocks for checking */
3196 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3197
3198 /* The first byte of the L1 header contains the power level.
3199 * The reserved bits and the fpc bit is set to 0, so we may
3200 * compare directly. */
3201 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3202 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3203 }
3204
3205 /* Signal a new power level via RSL for the next turn. */
3206 if (power_level < 31) {
3207 power_level := power_level + 1;
3208 ms_power.power_level := power_level;
3209 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3210 RSL.send(rsl);
3211 repeat;
3212 }
3213
3214 }
3215
3216 /* Ignore all other blocks */
3217 [] L1CTL.receive { repeat; }
3218
3219 }
3220
3221 f_rsl_chan_deact();
3222 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3223
3224 setverdict(pass);
3225}
3226
3227testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3228 var ConnHdlr vc_conn;
3229 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003230 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003231
3232 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3233 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3234 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3235 vc_conn.done;
3236 }
3237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3238}
Harald Welte70767382018-02-21 12:16:40 +01003239
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003240/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003241TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003242private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003243 var L1ctlDlMessage l1_dl;
3244 var uint5_t ta_to_test := 16;
3245
3246
3247 f_l1_tune(L1CTL);
3248 RSL.clear;
3249
3250 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003251 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003252
3253 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3254
3255
3256 alt {
3257
3258 /* Pick all SACCH blocks for checking */
3259 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3260
3261 /* The second byte of the L1 header contains the TA. */
3262 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3263 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3264 }
3265
3266 }
3267
3268 /* Ignore all other blocks */
3269 [] L1CTL.receive { repeat; }
3270
3271 }
3272
3273 f_rsl_chan_deact();
3274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3275
3276 setverdict(pass);
3277}
3278
3279testcase TC_rsl_chan_initial_ta() runs on test_CT {
3280 var ConnHdlr vc_conn;
3281 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003282 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003283 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003284 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3285 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003286 vc_conn.done;
3287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3288}
3289
Eric Wilde57e1a62019-05-28 13:30:55 +02003290/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003291private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003292 var L1ctlDlMessage l1_dl;
3293 var uint5_t ms_power_level := 7;
3294
3295 var RSL_IE_MS_Power ms_power;
3296 ms_power.reserved := 0;
3297 ms_power.fpc_epc := false;
3298 ms_power.power_level := ms_power_level;
3299
3300 f_l1_tune(L1CTL);
3301 RSL.clear;
3302
3303 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3304
3305 timer T := 1.0;
3306 T.start;
3307 alt {
3308 /* Pick all SACCH blocks for checking */
3309 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3310 /* The first byte of the L1 header contains the power level.. */
3311 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3312 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3313 }
3314 }
3315 /* Ignore all other blocks */
3316 [] L1CTL.receive { repeat; }
3317 [] T.timeout {
3318 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3319 }
3320 }
3321
3322 f_rsl_chan_deact();
3323 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3324 setverdict(pass);
3325}
3326
3327testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3328 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3329 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3330}
3331
Harald Welte0472ab42018-03-12 15:02:26 +01003332/* 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 +01003333private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003334 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003335 RSL.clear;
3336
3337 f_est_dchan();
3338 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003339 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003340
3341 timer T := 40.0;
3342 T.start;
3343 alt {
3344 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3345 setverdict(pass)
3346 }
3347 [] RSL.receive { repeat };
3348 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003350 }
3351 }
3352 f_rsl_chan_deact();
3353}
3354testcase TC_conn_fail_crit() runs on test_CT {
3355 var ConnHdlr vc_conn;
3356 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003357 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003358 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3359 pars.t_guard := 60.0;
3360 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3361 vc_conn.done;
3362}
3363
Harald Welte93640c62018-02-25 16:59:33 +01003364/***********************************************************************
3365 * Paging
3366 ***********************************************************************/
3367
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003368private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003369 if (tmsi == 'FFFFFFFF'O) {
3370 return true;
3371 } else {
3372 return false;
3373 }
3374}
Harald Welte70767382018-02-21 12:16:40 +01003375
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003376private type record allowedFn { integer frame_nr }
3377private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3378private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3379private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3380private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3381private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3382private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3383private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3384private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3385private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003386{
3387 var integer frame_nr_51;
3388 frame_nr_51 := frame_nr mod 51
3389
3390 var allowedFn fn_check;
3391 fn_check.frame_nr := frame_nr_51;
3392
3393 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003395 return;
3396 }
3397
3398 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3399 return;
3400 }
3401 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3402 return;
3403 }
3404 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3405 return;
3406 }
3407 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3408 return;
3409 }
3410 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3411 return;
3412 }
3413 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3414 return;
3415 }
3416 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3417 return;
3418 }
3419 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3420 return;
3421 }
3422
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003424 return;
3425}
3426
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003427private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3428 inout integer num_paging_rcv_ids,
3429 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003430runs on test_CT {
3431 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003432 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003433 repeat;
3434 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003435 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003436 var octetstring without_plen :=
3437 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3438 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003439
3440 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3441
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003442 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3443 /* Ignore empty RR Paging Request (PCH filling) messages.
3444 * TODO: does it make sense to count them? */
3445 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003446 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3447 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003448 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003449 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3450 }
3451 } else if (match(rr, tr_PAGING_REQ2)) {
3452 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3453 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3454 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3455 }
3456 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3457 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3458 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003459 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003460 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3461 }
3462 } else if (match(rr, tr_PAGING_REQ3)) {
3463 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3464 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3465 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3466 }
3467 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3468 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3469 }
3470 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3471 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3472 }
3473 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3474 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3475 }
3476 }
3477 repeat;
3478 }
3479}
3480
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003481private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003482 boolean combined_ccch,
3483 integer bs_ag_blks_res,
3484 float load_factor,
3485 boolean exp_load_ind,
3486 boolean exp_overload,
3487 boolean use_tmsi
3488}
3489
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003490private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003491 integer num_paging_sent,
3492 integer num_paging_rcv_msgs,
3493 integer num_paging_rcv_ids,
3494 integer num_overload
3495}
3496
Harald Welte68e495b2018-02-25 00:05:57 +01003497/* Helper function for paging related testing */
3498private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003499 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003500 f_init_l1ctl();
3501 f_l1_tune(L1CTL);
3502
3503 var PagingTestState st := {
3504 num_paging_sent := 0,
3505 num_paging_rcv_msgs := 0,
3506 num_paging_rcv_ids := 0,
3507 num_overload := 0
3508 };
3509
3510 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3511 var float max_pch_imsi_per_sec;
3512 if (cfg.use_tmsi) {
3513 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3514 } else {
3515 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3516 }
3517 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3518 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003519 var float time_total := 20.0;
3520 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3521 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003522
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003523 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3524 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003525
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003526 timer T_itv := 0.0;
3527 T_itv.start;
3528 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003529 alt {
3530 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003531 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003532 st.num_overload := st.num_overload + 1;
3533 repeat;
3534 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003535 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003537 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003538 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003539 log("Rx LOAD_IND");
3540 /* FIXME: analyze/verify interval + contents */
3541 repeat;
3542 }
3543 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003544 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003545 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003546 [] T_itv.timeout {
3547 /* Send paging cmds based on elapsed time */
3548 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3549 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003550 var MobileIdentityV mi;
3551
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003552 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003553 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003554 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003555 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003556 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003557 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003558
3559 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003560 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 +02003561
3562 st.num_paging_sent := st.num_paging_sent + 1;
3563 }
3564 if (st.num_paging_sent < pkt_total) {
3565 /* Wait for interval to next PAGING COMMAND */
3566 var float time_now := T_total.read;
3567 var float next_sched := int2float(st.num_paging_sent)*interval;
3568 if (next_sched > time_now) {
3569 T_itv.start(next_sched - time_now);
3570 } else {
3571 T_itv.start(0.0);
3572 }
3573 } else {
3574 /* We are done, no need to keep counting */
3575 T_total.stop;
3576 }
3577 }
3578 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003579 }
3580 }
3581
3582 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3583 timer T_wait := 18.0;
3584 T_wait.start;
3585 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003586 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003587 [] L1CTL.receive { repeat; }
3588 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003589 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3590 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003591 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003593 }
Harald Welte68e495b2018-02-25 00:05:57 +01003594 }
3595
3596 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3597 " rcvd_ids=", st.num_paging_rcv_ids);
3598 return st;
3599}
3600
3601/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3602 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3603 * - that CCCH LOAD IND (PCH) are being generated
3604 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3605testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003606 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003607 var PagingTestCfg cfg := {
3608 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003609 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003610 load_factor := 0.8,
3611 exp_load_ind := true,
3612 exp_overload := false,
3613 use_tmsi := false
3614 };
3615 var PagingTestState st := f_TC_paging(cfg);
3616 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3618 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003619 } else {
3620 setverdict(pass);
3621 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003623}
3624
3625/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3626 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3627 * - that CCCH LOAD IND (PCH) are being generated
3628 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3629testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003630 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003631 var PagingTestCfg cfg := {
3632 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003633 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003634 load_factor := 0.8,
3635 exp_load_ind := true,
3636 exp_overload := false,
3637 use_tmsi := true
3638 };
3639 var PagingTestState st := f_TC_paging(cfg);
3640 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3642 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003643 } else {
3644 setverdict(pass);
3645 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003647}
3648
3649/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3650 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3651 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3652 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3653testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003654 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003655 var PagingTestCfg cfg := {
3656 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003657 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003658 load_factor := 2.0,
3659 exp_load_ind := true,
3660 exp_overload := true,
3661 use_tmsi := false
3662 };
3663 var PagingTestState st := f_TC_paging(cfg);
3664 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3665 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003666 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003667 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 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 +01003669 } else {
3670 setverdict(pass);
3671 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003673}
3674
3675/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3676 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3677 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3678 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3679testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003680 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003681 var PagingTestCfg cfg := {
3682 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003683 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003684 load_factor := 2.0,
3685 exp_load_ind := true,
3686 exp_overload := true,
3687 use_tmsi := true
3688 };
3689 var PagingTestState st := f_TC_paging(cfg);
3690 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3691 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003692 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003693 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003694 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 +01003695 } else {
3696 setverdict(pass);
3697 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003699}
3700
3701
Harald Welte93640c62018-02-25 16:59:33 +01003702/***********************************************************************
3703 * Immediate Assignment / AGCH
3704 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003705private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003706 len := 0,
3707 ma := ''B
3708}
Harald Welte93640c62018-02-25 16:59:33 +01003709
Harald Weltee8d750e2018-06-10 21:41:35 +02003710private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3711 return int2str(num_tx) & " sent, "
3712 & int2str(num_rx) & " received, "
3713 & int2str(num_del) & " deleted";
3714}
3715
3716private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3717 var L1ctlDlMessage l1_dl;
3718 timer T := 10.0;
3719 var integer num_tx := 0;
3720 var integer num_rx := 0;
3721 var integer num_del := 0;
3722 var charstring res_str;
3723 var float rx_ratio;
3724
Harald Welte10474062019-05-30 16:48:17 +02003725 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003726 f_init_l1ctl();
3727 f_l1_tune(L1CTL);
3728
3729 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003730 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003731 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3732 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003733 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003734 num_tx := num_tx+1;
3735 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003736 }
3737 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003738 T.start;
3739 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003740 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003741 num_del := num_del+1;
3742 repeat;
3743 }
3744 [] RSL_CCHAN.receive {
3745 repeat;
3746 }
3747 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003748 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3749 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3750 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003751 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003752 } else {
3753 num_rx := num_rx+1;
3754 }
3755 repeat;
3756 }
3757 [] L1CTL.receive { repeat; }
3758 [] T.timeout { }
3759 }
3760 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3761 log("AGCH test: " & res_str);
3762 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003764 }
3765 rx_ratio := int2float(num_rx) / int2float(num_tx);
3766 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003767 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 +02003768 } else {
3769 setverdict(pass);
3770 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003772}
3773
Harald Weltee8d750e2018-06-10 21:41:35 +02003774/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3775testcase TC_imm_ass_1000_20ms() runs on test_CT {
3776 f_TC_imm_ass(1000, 0.02, 0.25);
3777}
3778
3779/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3780testcase TC_imm_ass_200_0ms() runs on test_CT {
3781 f_TC_imm_ass(200, 0.0, 0.05);
3782}
3783
3784/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3785testcase TC_imm_ass_200_76ms() runs on test_CT {
3786 f_TC_imm_ass(150, 0.076, 1.00);
3787}
3788
3789
3790
Harald Welte48494ca2018-02-25 16:59:50 +01003791/***********************************************************************
3792 * BCCH
3793 ***********************************************************************/
3794
3795/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003796private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003797 GsmFrameNumber frame_number,
3798 SystemInformation si
3799}
3800
3801/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003802private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003803
3804/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003805private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003806
3807/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003808private function f_si_vecslot_contains(SystemInformationVector arr,
3809 RrMessageType key,
3810 boolean bcch_ext := false)
3811return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003812 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3813 var integer fn_mod51 := arr[i].frame_number mod 51;
3814 if (not bcch_ext and fn_mod51 == 2 or
3815 bcch_ext and fn_mod51 == 6) {
3816 if (arr[i].si.header.message_type == key) {
3817 return true;
3818 }
3819 }
3820 }
3821 return false;
3822}
3823
3824/* 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 +07003825private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3826 integer tc, RrMessageType key,
3827 boolean ext_bcch := false)
3828{
Harald Welte48494ca2018-02-25 16:59:50 +01003829 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003831 }
3832}
3833
3834/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003835private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3836 RrMessageType key)
3837return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003838 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3839 if (f_si_vecslot_contains(arr[tc], key) or
3840 f_si_vecslot_contains(arr[tc], key, true)) {
3841 return true;
3842 }
3843 }
3844 return false;
3845}
3846
3847/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003848private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3849 RrMessageType key,
3850 boolean bcch_ext := false,
3851 integer n := 1, integer m := 4)
3852return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003853 var integer count := 0;
3854 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3856 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003857 }
3858 for (var integer i:= 0; i < m; i := i + 1) {
3859 var integer fn_mod51 := arr[i].frame_number mod 51;
3860 if (not bcch_ext and fn_mod51 == 2 or
3861 bcch_ext and fn_mod51 == 6) {
3862 if (arr[i].si.header.message_type == key) {
3863 count := count + 1;
3864 }
3865 }
3866 }
3867 if (count >= n) {
3868 return true;
3869 } else {
3870 return false;
3871 }
3872}
3873
3874/* 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 +07003875private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3876 integer tc, RrMessageType key,
3877 boolean ext_bcch := false,
3878 integer n, integer m)
3879{
Harald Welte48494ca2018-02-25 16:59:50 +01003880 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003882 }
3883}
3884
3885/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003886private function f_si_vecslot_contains_only(SystemInformationVector arr,
3887 RrMessageType key,
3888 boolean bcch_ext := false)
3889return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003890 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3891 var integer fn_mod51 := arr[i].frame_number mod 51;
3892 if (not bcch_ext and fn_mod51 == 2 or
3893 bcch_ext and fn_mod51 == 6) {
3894 if (arr[i].si.header.message_type != key) {
3895 return false;
3896 }
3897 }
3898 }
3899 return true;
3900}
3901
3902/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003903private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3904 integer tc, RrMessageType key,
3905 boolean ext_bcch := false)
3906{
Harald Welte48494ca2018-02-25 16:59:50 +01003907 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003909 }
3910}
3911
3912/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003913private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003914 boolean bcch_extended,
3915 boolean si1_present,
3916 boolean si2bis_present,
3917 boolean si2ter_present,
3918 boolean si2quater_present,
3919 boolean si7_present,
3920 boolean si8_present,
3921 boolean si9_present,
3922 boolean si13_present,
3923 boolean si13alt_present,
3924 boolean si15_present,
3925 boolean si16_present,
3926 boolean si17_present,
3927 boolean si2n_present,
3928 boolean si21_present,
3929 boolean si22_present
3930}
3931
3932/* 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 +07003933private function f_validate_si_scheduling(SystemInformationConfig cfg,
3934 SystemInformationVectorPerTc si_per_tc)
3935{
Harald Welte48494ca2018-02-25 16:59:50 +01003936 var integer i;
3937 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3938 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003940 }
3941 }
3942 if (cfg.si1_present) {
3943 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3944 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3945 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3946 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3947 /* make sure *ALL* contain SI1 */
3948 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3949 }
3950 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3951 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3952 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3953 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3954 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3955 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3956
3957 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3958 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3959 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3960 * consecutive occurrences of TC = 4. */
3961 if (cfg.si2bis_present and not cfg.si2ter_present) {
3962 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3963 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3964 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3965 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3966 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3967 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3968 }
3969
3970 if (cfg.si7_present or cfg.si8_present) {
3971 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3972 * if System Information type 4 does not contain all information needed for cell
3973 * selection and reselection. */
3974 if (not cfg.bcch_extended) {
3975 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3976 }
3977 if (cfg.si7_present) {
3978 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3979 }
3980 if (cfg.si8_present) {
3981 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3982 }
3983 }
3984
3985 if (cfg.si2quater_present) {
3986 /* iii) System information type 2 quater is sent if needed, as determined by the system
3987 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3988 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3989 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3990 * within any of 4 consecutive occurrences of TC = 5. */
3991 if (not (cfg.bcch_extended)) {
3992 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3993 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3994 } else {
3995 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3996 }
3997 } else {
3998 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3999 }
4000 }
4001 if (cfg.si9_present) {
4002 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4003 * in system information type 3 as defined in 3GPP TS 44.018. */
4004 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4005 }
4006 if (cfg.si13_present) {
4007 /* vii) System Information type 13 is only related to the GPRS service. System Information
4008 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4009 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4010 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4011 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4012 * within any of 4 consecutive occurrences of TC=4. */
4013 if (not cfg.bcch_extended) {
4014 log("not-bccch-extended");
4015 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4016 } else {
4017 log("bccch-extended");
4018 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4019 }
4020 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004022 }
4023 }
4024 if (cfg.si16_present or cfg.si17_present) {
4025 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4026 * should not be sent in a cell where network sharing is used (see rule xv). */
4027 if (cfg.si22_present) {
4028 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4029 }
4030 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004032 }
4033 if (not cfg.bcch_extended) {
4034 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4035 }
4036 if (cfg.si16_present) {
4037 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4038 }
4039 if (cfg.si17_present) {
4040 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4041 }
4042 }
4043
4044 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4045 * broadcast information. The frequency with which they are sent is determined by the
4046 * system operator. System Information type 9 identifies the scheduling of System
4047 * Information type 18 and 20 messages. */
4048
4049 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4050 * Information Type 19 is present, then its scheduling shall be indicated in System
4051 * Information Type 9. */
4052
4053 if (cfg.si15_present) {
4054 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4055 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4056 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4057 * 4 consecutive occurrences of TC = 1. */
4058 if (not cfg.bcch_extended) {
4059 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4060 } else {
4061 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4062 }
4063 }
4064 if (cfg.si13alt_present) {
4065 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4066 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4067 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4068 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4069 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4070 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4071 * of TC = 4. */
4072 if (cfg.si13_present) {
4073 testcase.stop("Error: Cannot have SI13alt and SI13");
4074 }
4075 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004077 }
4078 if (not cfg.bcch_extended) {
4079 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4080 } else {
4081 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4082 }
4083 }
4084 if (cfg.si2n_present) {
4085 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4086 * as determined by the system operator. In the case that the message is sent on the
4087 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4088 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4089 * consecutive occurrences of TC = 4. */
4090 if (not cfg.bcch_extended) {
4091 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4092 } else {
4093 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4094 }
4095 }
4096 if (cfg.si21_present) {
4097 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4098 * determined by the system operator. If Extended Access Barring is in use in the cell
4099 * then this message is sent at least once within any of 4 consecutive occurrences of
4100 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4101 * cell then this message shall only be sent on BCCH Ext. */
4102 if (not cfg.bcch_extended) {
4103 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4104 } else {
4105 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4106 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004108 }
4109 }
4110 }
4111 if (cfg.si22_present) {
4112 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4113 * should not be sent in a cell where SoLSA is used (see rule viii). System
4114 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4115 * =2 and TC=6. */
4116 if (cfg.si16_present or cfg.si17_present) {
4117 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4118 }
4119 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4120 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004122 }
4123 if (not cfg.bcch_extended) {
4124 testcase.stop("Error: SI22 requires BCCH Extd!");
4125 } else {
4126 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4127 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4128 }
4129 }
4130}
4131
4132/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004133private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4134return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004135 timer T := duration;
4136 var SystemInformationVectorPerTc si_per_tc;
4137 var L1ctlDlMessage l1_dl;
4138
4139 /* initialize all per-TC vectors empty */
4140 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4141 si_per_tc[i] := {};
4142 }
4143
4144 /* flush all previous L1 queued msgs */
4145 pt.clear;
4146
4147 T.start;
4148 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004149 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004150 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4151 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4152 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004153 repeat;
4154 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004155
Harald Welte48494ca2018-02-25 16:59:50 +01004156 var integer tc := f_gsm_compute_tc(sig.frame_number);
4157 log("SI received at TC=", tc, ": ", sig.si);
4158 /* append to the per-TC bucket */
4159 si_per_tc[tc] := si_per_tc[tc] & { sig };
4160 repeat;
4161 }
4162 [] pt.receive { repeat; }
4163 [] T.timeout { }
4164 }
4165
4166 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4167 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4168 }
4169 log("si_per_tc=", si_per_tc);
4170 return si_per_tc;
4171}
4172
4173/* helper function: Set given SI via RSL + validate scheduling.
4174 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004175private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004176 var SystemInformationVectorPerTc si_per_tc;
4177 f_init_l1ctl();
4178 f_l1_tune(L1CTL);
4179
4180 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004181 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004182 f_validate_si_scheduling(si_cfg, si_per_tc);
4183
4184 setverdict(pass);
4185}
4186
4187testcase TC_si_sched_default() runs on test_CT {
4188 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004189 /* 2+3+4 are mandatory and set in f_init() */
4190 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004192}
4193
4194testcase TC_si_sched_1() runs on test_CT {
4195 f_init();
4196 si_cfg.si1_present := true;
4197 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004198 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004200}
4201
4202testcase TC_si_sched_2bis() runs on test_CT {
4203 f_init();
4204 si_cfg.si2bis_present := true;
4205 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4206 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004208}
4209
4210testcase TC_si_sched_2ter() runs on test_CT {
4211 f_init();
4212 si_cfg.si2ter_present := true;
4213 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4214 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004216}
4217
4218testcase TC_si_sched_2ter_2bis() runs on test_CT {
4219 f_init();
4220 si_cfg.si2bis_present := true;
4221 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4222 si_cfg.si2ter_present := true;
4223 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4224 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004226}
4227
4228testcase TC_si_sched_2quater() runs on test_CT {
4229 f_init();
4230 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004231 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004232 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004234}
4235
4236testcase TC_si_sched_13() runs on test_CT {
4237 f_init();
4238 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004239 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004240 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004242}
4243
4244testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4245 f_init();
4246 si_cfg.si2bis_present := true;
4247 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4248 si_cfg.si2ter_present := true;
4249 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4250 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004251 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004252 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004253 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004254 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004256}
4257
4258
Harald Welte68e495b2018-02-25 00:05:57 +01004259testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004260 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004261 /* FIXME: enable / disable individual BCCH info */
4262 //ts_RSL_BCCH_INFO(si_type, info);
4263 /* expect no ERROR REPORT after either of them *
4264 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004266}
4267
Harald Welte93640c62018-02-25 16:59:33 +01004268/***********************************************************************
4269 * Low-Level Protocol Errors / ERROR REPORT
4270 ***********************************************************************/
4271
Harald Welte01d982c2018-02-25 01:31:40 +01004272private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4273 timer T := 5.0;
4274 T.start;
4275 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004276 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004277 setverdict(pass);
4278 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004279 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004281 }
4282 [] RSL_CCHAN.receive {
4283 repeat;
4284 }
4285 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004287 }
4288 }
4289}
4290
4291/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4292testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004293 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004294 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4295 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004296 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004297
4298 f_exp_err_rep(RSL_ERR_PROTO);
4299}
4300
4301/* Provoke a mandatory IE error and match on ERROR REPORT */
4302testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004303 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004304
4305 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4306 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004307 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004308
4309 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4310}
4311
4312/* Provoke an IE content error and match on ERROR REPORT */
4313testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004314 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004315 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4316 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004317 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004318
4319 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4320}
4321
Harald Welteee25aae2019-05-19 14:32:37 +02004322/* attempt to activate channel with wrong RSL Message Discriminator IE */
4323function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4324 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4325 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4326 RSL.send(rsl);
4327 f_rslem_unregister(0, g_chan_nr);
4328}
4329testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4330 var ConnHdlr vc_conn;
4331 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4332
Harald Welte10474062019-05-30 16:48:17 +02004333 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004334
4335 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4336 vc_conn.done;
4337 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4338
4339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4340}
4341
4342/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004343private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004344 var template (value) RSL_Message rsl_tx;
4345 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4346 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4347 RSL.send(rsl_tx);
4348 f_rslem_unregister(0, g_chan_nr);
4349}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004350private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004351 var template (value) RSL_Message rsl_tx;
4352 /* we first have to activate the dedicated channel */
4353 f_rsl_chan_act(g_pars.chan_mode);
4354 /* ... to then send an invalid RLL message */
4355 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4356 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4357 RSL.send(rsl_tx);
4358 f_rslem_unregister(0, g_chan_nr);
4359}
4360testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4361 var ConnHdlr vc_conn;
4362 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4363 var template (value) RSL_Message rsl_tx;
4364
Harald Welte10474062019-05-30 16:48:17 +02004365 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004366
4367 /* Common Channel with wrong message type */
4368 RSL_CCHAN.clear;
4369 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4370 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004371 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004372 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4373
4374 /* TRX Management */
4375 RSL_CCHAN.clear;
4376 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4377 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004378 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004379 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4380
4381 /* Dedicated Channel */
4382 RSL_CCHAN.clear;
4383 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4384 vc_conn.done;
4385 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4386
4387 /* RLL */
4388 RSL_CCHAN.clear;
4389 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4390 vc_conn.done;
4391 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4392}
4393
4394/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004395private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004396 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4397 f_rslem_unregister(0, g_chan_nr);
4398}
4399testcase TC_err_rep_wrong_sequence() runs on test_CT {
4400 var ConnHdlr vc_conn;
4401 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4402
Harald Welte10474062019-05-30 16:48:17 +02004403 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004404
4405 RSL_CCHAN.clear;
4406 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4407 vc_conn.done;
4408 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4409}
4410
Harald Welte93640c62018-02-25 16:59:33 +01004411/***********************************************************************
4412 * IPA CRCX/MDCX/DLCS media stream handling
4413 ***********************************************************************/
4414
Harald Weltea871a382018-02-25 02:03:14 +01004415/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004416private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004417 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4418 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004419}
4420testcase TC_ipa_dlcx_not_active() runs on test_CT {
4421 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004422 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004423 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4424 vc_conn.done;
4425}
Harald Welte68e495b2018-02-25 00:05:57 +01004426
Harald Weltea3f1df92018-02-25 12:49:55 +01004427/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004428private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004429 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4430 "IPA CRCX ACK");
4431 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4432 "IPA CRCX NACK");
4433}
4434testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4435 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004436 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004437 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4438 vc_conn.done;
4439}
4440
4441/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004442private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004443 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4444 "IPA CRCX ACK");
4445 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4446 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4447 var uint7_t rtp_pt2 := f_rnd_int(127);
4448 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4449 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4450 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4451 "IPA MDCX ACK");
4452 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4453 "IPA DLCX ACK");
4454}
4455testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4456 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004457 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004458 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4459 vc_conn.done;
4460}
4461
Harald Welte3ae11da2018-02-25 13:36:06 +01004462/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004463private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004464 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4465 "IPA CRCX ACK");
4466 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4467 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4468 var uint7_t rtp_pt2 := f_rnd_int(127);
4469 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4470 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4471 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4472 "IPA MDCX ACK");
4473 /* Second MDCX */
4474 remote_ip := f_rnd_int(c_UINT32_MAX);
4475 remote_port := f_rnd_int(c_UINT16_MAX);
4476 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4477 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4478 "IPA MDCX ACK");
4479 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4480 "IPA DLCX ACK");
4481}
4482testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4483 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004484 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004485 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4486 vc_conn.done;
4487}
4488
Harald Welte9912eb52018-02-25 13:30:15 +01004489/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004490private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004491 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4492 "IPA CRCX NACK");
4493}
4494testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4495 var ConnHdlrPars pars;
4496 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004497 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004498
4499 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4500 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4501 vc_conn.done;
4502
4503 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4504 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4505 vc_conn.done;
4506}
4507
Harald Weltea3f1df92018-02-25 12:49:55 +01004508
Harald Welte883340c2018-02-28 18:59:29 +01004509/***********************************************************************
4510 * PCU Socket related tests
4511 ***********************************************************************/
4512
Harald Welte07bd2d22019-05-25 11:03:30 +02004513/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004514friend 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 +01004515runs on test_CT {
4516 timer T := 3.0;
4517
4518 /* we don't expect any RTS.req before PDCH are active */
4519 T.start;
4520 alt {
4521 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004523 }
4524 [] PCU.receive { repeat; }
4525 [] T.timeout { }
4526 }
4527
4528 /* Send PDCH activate request for known PDCH timeslot */
4529 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4530
4531 /* we now expect RTS.req for this timeslot (only) */
4532 T.start;
4533 alt {
4534 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4535 setverdict(pass);
4536 }
4537 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4538 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, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004540 }
4541 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004543 }
4544 [] PCU.receive { repeat; }
4545 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004547 }
4548 [not exp_success] T.timeout {
4549 setverdict(pass);
4550 }
4551 }
4552}
4553
Harald Welte07bd2d22019-05-25 11:03:30 +02004554/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004555friend 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 +01004556runs on test_CT {
4557 timer T := 3.0;
4558
4559 /* Send PDCH activate request for known PDCH timeslot */
4560 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 +02004561 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4562 * when it will actually have been executed in the BTS */
4563 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004564 PCU.clear;
4565 /* we now expect no RTS.req for this timeslot */
4566 T.start;
4567 alt {
4568 [] 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 +02004569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004570 }
4571 [] PCU.receive { repeat; }
4572 [] T.timeout {
4573 setverdict(pass);
4574 }
4575 }
4576}
4577
Harald Weltead033dc2019-05-25 17:28:16 +02004578friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004579 f_init();
4580 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4581}
4582
Harald Welte883340c2018-02-28 18:59:29 +01004583/* PDCH activation via PCU socket; check for presence of RTS.req */
4584testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004585 f_init_pcu_test();
4586
Harald Welte883340c2018-02-28 18:59:29 +01004587 f_TC_pcu_act_req(0, 0, 7, true);
4588}
4589
4590/* PDCH activation via PCU socket on non-PDCU timeslot */
4591testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004592 f_init_pcu_test();
4593
Harald Welte883340c2018-02-28 18:59:29 +01004594 f_TC_pcu_act_req(0, 0, 1, false);
4595}
4596
4597/* PDCH activation via PCU socket on wrong BTS */
4598testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004599 f_init_pcu_test();
4600
Harald Welte883340c2018-02-28 18:59:29 +01004601 f_TC_pcu_act_req(23, 0, 7, false);
4602}
4603
4604/* PDCH activation via PCU socket on wrong TRX */
4605testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004606 f_init_pcu_test();
4607
Harald Welte883340c2018-02-28 18:59:29 +01004608 f_TC_pcu_act_req(0, 23, 7, false);
4609}
4610
4611/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4612testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004613 f_init_pcu_test();
4614
Harald Welte883340c2018-02-28 18:59:29 +01004615 /* Activate PDCH */
4616 f_TC_pcu_act_req(0, 0, 7, true);
4617 f_sleep(1.0);
4618 /* and De-Activate again */
4619 f_TC_pcu_deact_req(0, 0, 7);
4620}
4621
4622/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4623testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004624 f_init_pcu_test();
4625
Harald Welte883340c2018-02-28 18:59:29 +01004626 f_TC_pcu_deact_req(0, 0, 1);
4627}
4628
4629/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4630testcase TC_pcu_ver_si13() runs on test_CT {
4631 const octetstring si13 := '00010203040506070909'O;
4632 var PCUIF_send_data sd;
4633 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004634 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004635
4636 /* Set SI13 via RSL */
4637 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004638
Harald Welte883340c2018-02-28 18:59:29 +01004639 T.start;
4640 alt {
4641 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4642 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4643 setverdict(pass);
4644 } else {
4645 repeat;
4646 }
4647 }
4648 [] PCU.receive { repeat; }
4649 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004651 }
4652 }
4653}
4654
4655private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4656
4657/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004658friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004659 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4660runs on test_CT
4661{
4662 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4663 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4664}
4665
4666/* 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 +02004667friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4668 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004669runs on test_CT
4670{
4671 var PCUIF_send_data sd;
4672
4673 timer T := 3.0;
4674 T.start;
4675 alt {
4676 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4677 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4678 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4679 sd.data.u.rts_req.fn, sapi, data);
4680 }
4681 [] PCU.receive { repeat; }
4682 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004684 }
4685 }
4686}
4687
4688/* Send DATA.req on invalid BTS */
4689testcase TC_pcu_data_req_wrong_bts() 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(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004701}
4702
4703/* Send DATA.req on invalid TRX */
4704testcase TC_pcu_data_req_wrong_trx() 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);
4707
4708 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004709
Harald Welte883340c2018-02-28 18:59:29 +01004710 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004711 f_TfiUsfArrSet(tua, 7, 0);
4712 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4713 f_sleep(1.0);
4714
4715 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004716}
4717
4718/* Send DATA.req on invalid timeslot */
4719testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004720 var TfiUsfArr tua := f_TfiUsfArrInit();
4721 var octetstring data := '0000'O & f_rnd_octstring(21);
4722
4723 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004724
Harald Welte883340c2018-02-28 18:59:29 +01004725 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004726 f_TfiUsfArrSet(tua, 7, 0);
4727 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4728 f_sleep(1.0);
4729
4730 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004731}
4732
4733/* Send DATA.req on timeslot that hasn't been activated */
4734testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004735 var TfiUsfArr tua := f_TfiUsfArrInit();
4736 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004737
Harald Welte7162a612019-05-26 12:56:09 +02004738 f_virtphy_common();
4739
4740 f_TfiUsfArrSet(tua, 7, 0);
4741 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4742 f_sleep(1.0);
4743
4744 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004745}
4746
Harald Weltead033dc2019-05-25 17:28:16 +02004747private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004748 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4749 boolean wait_rts := true)
4750runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004751 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004752 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004753
4754 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004755 if (wait_rts) {
4756 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4757 } else {
4758 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4759 }
Harald Weltead033dc2019-05-25 17:28:16 +02004760
4761 T.start;
4762 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004763 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004764 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4765 setverdict(pass);
4766 }
Harald Welte7162a612019-05-26 12:56:09 +02004767 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4768 setverdict(fail, "Received unexpected ", rx_dl);
4769 }
Harald Weltead033dc2019-05-25 17:28:16 +02004770 [] L1CTL.receive {
4771 repeat;
4772 }
Harald Welte7162a612019-05-26 12:56:09 +02004773 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004774 setverdict(fail, "Timeout waiting for ", data);
4775 }
Harald Welte7162a612019-05-26 12:56:09 +02004776 [not expect_data] T.timeout {
4777 setverdict(pass);
4778 }
Harald Weltead033dc2019-05-25 17:28:16 +02004779 }
4780}
4781
4782private function f_disable_dynamic_ts() runs on test_CT
4783{
4784 f_init_vty_bsc();
4785 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4786 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4787 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4788 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004789 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004790}
4791
4792private function f_virtphy_common() runs on test_CT {
4793 f_disable_dynamic_ts();
4794 f_init_l1ctl();
4795 f_l1_tune(L1CTL);
4796}
4797
4798testcase TC_pcu_data_req_pdtch() runs on test_CT {
4799 var TfiUsfArr tua := f_TfiUsfArrInit();
4800 var octetstring data := '0000'O & f_rnd_octstring(21);
4801
4802 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004803
Harald Welte883340c2018-02-28 18:59:29 +01004804 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004805 f_TfiUsfArrSet(tua, 7, 0);
4806 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4807 f_sleep(1.0);
4808
4809 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004810}
4811
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004812/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004813testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004814 var TfiUsfArr tua := f_TfiUsfArrInit();
4815 var octetstring data := '0000'O & f_rnd_octstring(21);
4816
4817 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004818
Harald Welte883340c2018-02-28 18:59:29 +01004819 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004820 f_TfiUsfArrSet(tua, 7, 0);
4821 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4822 f_sleep(1.0);
4823
4824 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004825}
4826
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004827private function f_TC_pcu_ptcch_ul(uint16_t ra)
4828runs on test_CT {
4829 var template PCUIF_Message pcu_rach_ind;
4830 var PCUIF_send_data sd;
4831 var GsmFrameNumber fn;
4832 timer T;
4833
4834 /* Send an Access Burst on PTCCH/U over the Um-interface */
4835 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4836 chan_nr := ts_RslChanNr_PDCH(7),
4837 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4838
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004839 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4840 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004841
4842 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4843 T.start(52.0 * 4.615 / 1000.0);
4844 alt {
4845 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4846 log("Rx an Access Burst on the PCU interface: ", sd.data);
4847 setverdict(pass);
4848 T.stop;
4849 }
4850 [] PCU.receive { repeat; }
4851 [] T.timeout {
4852 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4853 /* Keep going, that's not the end of the world */
4854 }
4855 }
4856}
4857
4858testcase TC_pcu_ptcch() runs on test_CT {
4859 var L1ctlDlMessage dl;
4860 var octetstring data;
4861 timer T;
4862
4863 f_init_pcu_test();
4864 f_init_l1ctl();
4865 f_l1_tune(L1CTL);
4866
4867 /* Activate PDCH channel on TS7 */
4868 f_TC_pcu_act_req(0, 0, 7, true);
4869
4870 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004871 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004872 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004873 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004874 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004875
4876 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4877 for (var integer i := 0; i < 16; i := i + 1) {
4878 log("Sending an Access Burst towards the L1CTL interface");
4879 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4880 }
4881
4882 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4883 data := f_rnd_octstring(23);
4884
4885 /* Verify PTCCH/D: send a random data block, make sure it's received */
4886 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4887 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4888
4889 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4890 * let's give it more time in case if we miss the beginning. */
4891 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4892 alt {
4893 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4894 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4895 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4896 frame := data)) -> value dl {
4897 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4898 setverdict(pass);
4899 T.stop;
4900 }
4901 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4902 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4903 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4904 l2_data := data)) -> value dl {
4905 log("Rx PTCCH/D data block on L1CTL: ", dl);
4906 setverdict(pass);
4907 T.stop;
4908 }
4909 [] L1CTL.receive { repeat; }
4910 [] T.timeout {
4911 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4912 }
4913 }
4914}
4915
Harald Welte883340c2018-02-28 18:59:29 +01004916/* Send AGCH from PCU; check it appears on Um side */
4917testcase TC_pcu_data_req_agch() runs on test_CT {
4918 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004919 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004920 f_init_l1ctl();
4921 f_l1_tune(L1CTL);
4922
4923 f_TC_pcu_act_req(0, 0, 7, true);
4924 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4925
4926 T.start;
4927 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004928 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004929 setverdict(pass);
4930 }
4931 [] L1CTL.receive { repeat; }
4932 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004934 }
4935 }
4936}
4937
Harald Welte928622b2019-05-26 13:22:59 +02004938/* Send AGCH from PCU; check it appears on Um side */
4939testcase TC_pcu_data_req_pch() runs on test_CT {
4940 timer T := 3.0;
4941 f_init_pcu_test();
4942 f_init_l1ctl();
4943 f_l1_tune(L1CTL);
4944
4945 f_TC_pcu_act_req(0, 0, 7, true);
4946 /* three characters prefix: last 3 digits of IMSI as ASCII */
4947 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4948
4949 T.start;
4950 alt {
4951 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4952 setverdict(pass);
4953 }
4954 [] L1CTL.receive { repeat; }
4955 [] T.timeout {
4956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4957 }
4958 }
4959}
4960
Harald Welte883340c2018-02-28 18:59:29 +01004961/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4962testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4963 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004964 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004965 f_init_l1ctl();
4966 f_l1_tune(L1CTL);
4967
4968 /* append 3 last imsi digits so BTS can compute pagng group */
4969 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4970
4971 timer T := 0.5;
4972 T.start;
4973 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004974 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004975 /* TODO: verify paging group */
4976 setverdict(pass);
4977 }
4978 [] L1CTL.receive { repeat; }
4979 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004981 }
4982 }
4983}
4984
4985/* Send RACH from Um side, expect it to show up on PCU socket */
4986testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004987 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004988 f_init_l1ctl();
4989 f_l1_tune(L1CTL);
4990
4991 var GsmFrameNumber fn_last := 0;
4992 for (var integer i := 0; i < 1000; i := i+1) {
4993 var OCT1 ra := f_rnd_ra_ps();
4994 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4995 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004997 }
4998 fn_last := fn;
4999
5000 timer T := 2.0;
5001 T.start;
5002 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005003 [] 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 +01005004 T.stop;
5005 }
5006 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005008 }
5009 [] PCU.receive { repeat; }
5010 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005012 }
5013 }
5014 }
5015 setverdict(pass);
5016}
5017
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005018/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5019 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5020testcase TC_pcu_ext_rach_content() runs on test_CT {
5021 var template PCUIF_Message pcu_rach_ind;
5022 var GsmFrameNumber fn_last := 0;
5023 var L1ctlRachSynchSeq synch_seq;
5024 var PCUIF_BurstType pcu_bt;
5025 var GsmFrameNumber fn;
5026 var BIT11 ra11;
5027
5028 f_init_pcu_test();
5029 f_init_l1ctl();
5030 f_l1_tune(L1CTL);
5031
5032 for (var integer i := 0; i < 1000; i := i+1) {
5033 /* We need to test both TS1 & TS2 */
5034 if (i rem 2 == 0) {
5035 synch_seq := RACH_SYNCH_SEQ_TS1;
5036 pcu_bt := BURST_TYPE_1;
5037 } else {
5038 synch_seq := RACH_SYNCH_SEQ_TS2;
5039 pcu_bt := BURST_TYPE_2;
5040 }
5041
5042 ra11 := f_rnd_ra11_ps();
5043 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5044 if (fn == fn_last) {
5045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5046 "Two RACH in same FN?!?");
5047 }
5048 fn_last := fn;
5049
5050 /* Compose the expected message */
5051 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005052 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005053 ra := bit2int(ra11),
5054 is_11bit := 1,
5055 burst_type := pcu_bt,
5056 fn := fn);
5057
5058 timer T := 2.0;
5059 T.start;
5060 alt {
5061 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5062 T.stop;
5063 }
5064 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5066 }
5067 [] PCU.receive { repeat; }
5068 [] T.timeout {
5069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5070 }
5071 }
5072 }
5073 setverdict(pass);
5074}
5075
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005076private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5077runs on test_CT {
5078 var template PCUIF_send_data sdt;
5079 var PCUIF_send_data sd;
5080 var int16_t lqual_cb;
5081 timer T := 1.0;
5082
5083 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5084 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5085
5086 /* Send a random PDTCH frame over Um */
5087 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5088 '0000'O & f_rnd_octstring(21)));
5089
5090 T.start;
5091 alt {
5092 /* If expected link quality is above the threshold */
5093 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5094 lqual_cb := sd.data.u.data_ind.lqual_cb;
5095 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5096
5097 /* Make sure the actual link quality matches the expected value */
5098 if (not match(lqual_cb, lqual_cb_exp)) {
5099 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5100 "expected value ", lqual_cb_exp));
5101 } else {
5102 setverdict(pass);
5103 }
5104 }
5105 /* If expected link quality is below the threshold */
5106 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5108 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5109 }
5110 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5111 [] PCU.receive { repeat; }
5112 [lqual_cb_exp < thresh] T.timeout {
5113 log("Rx nothing, as expected");
5114 setverdict(pass);
5115 }
5116 [lqual_cb_exp >= thresh] T.timeout {
5117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5118 "Timeout waiting for PCUIF_DATA.ind");
5119 }
5120 }
5121}
5122
5123/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5124testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5125 f_init_pcu_test();
5126 PCU.clear;
5127
5128 f_init_l1ctl();
5129 f_l1_tune(L1CTL);
5130
5131 /* Activate a PDCH channel on TS7 */
5132 f_TC_pcu_act_req(0, 0, 7, true);
5133
5134 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005135 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005136 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005137 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005138 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005139
5140 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5141 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5142 var TrxcMessage ret;
5143
5144 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5145 valueof(ts_TRXC_FAKE_CI(i)));
5146
5147 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5148 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5149 }
5150}
5151
Harald Welte883340c2018-02-28 18:59:29 +01005152/* Send PAGING via RSL, expect it to shw up on PCU socket */
5153testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005154 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005155
5156 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005157 var MobileIdentityLV mi_lv;
5158 var octetstring mi_lv_enc;
5159 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005160 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005161
Harald Welte883340c2018-02-28 18:59:29 +01005162 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005163 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005164 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005165 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005166 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005167
5168 /* Fancy encoding for PCUIF */
5169 mi_lv := valueof(ts_MI_LV(mi));
5170 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5171 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005172
5173 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005174 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005175 T.start;
5176 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005177 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005178 }
5179 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005181 }
5182 [] PCU.receive { repeat; }
5183 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005185 }
5186 }
5187 }
5188 setverdict(pass);
5189}
5190
Harald Welted66c9b82019-05-25 09:03:15 +02005191/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5192testcase TC_pcu_time_ind() runs on test_CT {
5193 var PCUIF_send_data pcu_sd;
5194 var integer num_time_ind := 0;
5195 var integer first_fn, last_fn;
5196 var float test_duration := 5.0;
5197 timer T;
5198
5199 f_init_pcu_test();
5200 f_TC_pcu_act_req(0, 0, 7, true);
5201
5202 PCU.clear;
5203 T.start(test_duration);
5204 alt {
5205 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5206 num_time_ind := num_time_ind + 1;
5207 if (not isbound(first_fn)) {
5208 first_fn := pcu_sd.data.u.time_ind.fn;
5209 }
5210 last_fn := pcu_sd.data.u.time_ind.fn;
5211 repeat;
5212 }
5213 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5214 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5215 repeat;
5216 }
5217 [] PCU.receive {
5218 repeat;
5219 }
5220 [] T.timeout {}
5221 }
5222 var integer fn_expired := last_fn - first_fn;
5223 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5224
5225 /* verify the number of frames expired matches our expectation */
5226 const float c_GSM_FN_DURATION_MS := 4.61538;
5227 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005228 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005229 if (not match(fn_expired, t_fn_expected)) {
5230 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5231 }
5232
5233 /* There are three TIME.ind in every fn MOD 13 */
5234 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5235 /* Add some tolerance */
5236 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5237 if (not match(num_time_ind, t_time_ind_exp)) {
5238 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5239 }
5240
5241 setverdict(pass);
5242}
5243
Harald Welte4832c862019-05-25 14:57:18 +02005244/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5245testcase TC_pcu_rts_req() runs on test_CT {
5246 var PCUIF_send_data pcu_sd;
5247 var integer first_fn, last_fn;
5248 var integer num_rts_pdtch := 0;
5249 var integer num_rts_ptcch := 0;
5250 var float test_duration := 5.0;
5251 timer T;
5252
5253 f_init_pcu_test();
5254 f_TC_pcu_act_req(0, 0, 7, true);
5255
5256 PCU.clear;
5257 T.start(test_duration);
5258 alt {
5259 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5260 -> value pcu_sd {
5261 num_rts_pdtch := num_rts_pdtch + 1;
5262 if (not isbound(first_fn)) {
5263 first_fn := pcu_sd.data.u.rts_req.fn;
5264 }
5265 last_fn := pcu_sd.data.u.rts_req.fn;
5266 repeat;
5267 }
5268 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5269 -> value pcu_sd {
5270 num_rts_ptcch := num_rts_ptcch + 1;
5271 if (not isbound(first_fn)) {
5272 first_fn := pcu_sd.data.u.rts_req.fn;
5273 }
5274 last_fn := pcu_sd.data.u.rts_req.fn;
5275 repeat;
5276 }
5277 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5278 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5279 repeat;
5280 }
5281 [] PCU.receive {
5282 repeat;
5283 }
5284 [] T.timeout {}
5285 }
5286 var integer fn_expired := last_fn - first_fn;
5287 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5288 ", num_rts_ptcch=", num_rts_ptcch);
5289
5290 /* verify the number of frames expired matches our expectation */
5291 const float c_GSM_FN_DURATION_MS := 4.61538;
5292 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005293 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005294 if (not match(fn_expired, t_fn_expected)) {
5295 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5296 }
5297
5298 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5299 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5300 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5301 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5302 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5303 t_ptcch_exp);
5304 }
5305
5306 /* We have 12 PDTCH blocks every 52-multiframe */
5307 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5308 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5309 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5310 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5311 t_pdtch_exp);
5312 }
5313
5314 setverdict(pass);
5315}
5316
Harald Welte07bd2d22019-05-25 11:03:30 +02005317/* test for generating Abis side OML ALERT from the PCU */
5318testcase TC_pcu_oml_alert() runs on test_CT {
5319 var PCUIF_send_data pcu_sd;
5320 var integer num_time_ind := 0;
5321 var integer first_fn, last_fn;
5322 var float test_duration := 5.0;
5323 timer T;
5324
5325 f_init_pcu_test();
5326 f_TC_pcu_act_req(0, 0, 7, true);
5327
5328 /* re-connect CTRL port from BTS to BSC */
5329 f_ipa_ctrl_stop();
5330 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5331
5332 /* Send that OML Alert */
5333 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5334
5335 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5336 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5337 setverdict(pass);
5338}
5339
Harald Welteeaa9a862019-05-26 23:01:08 +02005340/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5341private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5342 var PCUIF_Message first_info;
5343 var integer pcu_conn_id := -1;
5344 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5345 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5346 var OCT4 tlli := '01020304'O;
5347 var OCT1 cause := '23'O;
5348 timer T := 5.0;
5349
5350 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5351
5352 f_l1_tune(L1CTL);
5353 RSL.clear;
5354
5355 f_est_dchan();
5356 L1CTL.clear;
5357
5358 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5359
5360 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5361 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5362 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5363
5364 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5365 T.start;
5366 alt {
5367 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5368 setverdict(pass);
5369 }
5370 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5371 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5372 }
5373 [] PCU.receive {
5374 repeat;
5375 }
5376 [] T.timeout {
5377 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5378 }
5379 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005380
5381 /* release the channel */
5382 f_rsl_chan_deact();
5383 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5384 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005385}
5386testcase TC_pcu_rr_suspend() runs on test_CT {
5387 var ConnHdlrPars pars;
5388 var ConnHdlr vc_conn;
5389
5390 f_init();
5391
5392 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5393 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5394 vc_conn.done;
5395}
Harald Welte07bd2d22019-05-25 11:03:30 +02005396
Harald Weltea2e0e942019-05-27 18:12:53 +02005397/* Ensure that PCUIF socket can accept only a single connection */
5398testcase TC_pcu_socket_connect_multi() runs on test_CT {
5399 timer T := 5.0;
5400
5401 /* this (among other things) establishes the first connection to the PCUIF socket */
5402 f_init();
5403
5404 /* try to establish a second connection, expect it to fail */
5405 PCU.send(UD_connect:{mp_pcu_socket, -1});
5406 T.start;
5407 alt {
5408 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5409 setverdict(pass);
5410 }
5411 [] PCU.receive(UD_connect_result:?) {
5412 setverdict(fail, "Unexpected unix domain connect result");
5413 }
5414 [] T.timeout {
5415 setverdict(pass);
5416 }
5417 }
5418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5419}
5420
Harald Weltec8effb72019-05-27 18:23:04 +02005421/* Ensure that PCUIF socket can disconnect + reconnect */
5422testcase TC_pcu_socket_reconnect() runs on test_CT {
5423 /* this (among other things) establishes the first connection to the PCUIF socket */
5424 f_init();
5425
5426 f_sleep(1.0);
5427
5428 f_pcuif_close(PCU, g_pcu_conn_id);
5429 g_pcu_conn_id := -1;
5430
5431 f_sleep(1.0);
5432
5433 /* re-connect */
5434 PCU.clear;
5435 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5436 setverdict(pass);
5437
5438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5439}
5440
Harald Weltebe030482019-05-27 22:29:35 +02005441/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005442private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5443runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005444 var L1ctlDlMessage l1_dl;
5445 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005446 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005447 timer T := 5.0;
5448 T.start;
5449 alt {
5450 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005451 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5452 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005453 repeat;
5454 }
5455 }
5456 [] pt.receive {
5457 repeat;
5458 }
5459 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5461 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005462 }
5463 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005464 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005465}
5466
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005467/* Check if GPRS Indicator is present in RR System Information of a given type */
5468private function f_si_has_gprs_indicator(RrMessageType si_type)
5469runs on test_CT return boolean {
5470 var SystemInformation si := f_get_si(L1CTL, si_type);
5471
5472 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005473 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005474 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005475 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005476 }
5477
5478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5479 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005480}
5481
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005482/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5483private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5484runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005485 /* don't call f_init() as this would connect PCU socket */
5486 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005487
5488 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005489 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005490 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005491
5492 f_init_l1ctl();
5493 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005494 f_sleep(2.0);
5495 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005496
5497 if (f_si_has_gprs_indicator(si_type)) {
5498 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005499 } else {
5500 setverdict(pass);
5501 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005502
Harald Weltebe030482019-05-27 22:29:35 +02005503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5504}
5505
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005506testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5507 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5508}
Harald Weltebe030482019-05-27 22:29:35 +02005509
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005510testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5511 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5512}
5513
5514/* Ensure that GPRS capability is advertised after PCU socket connect */
5515private function f_TC_pcu_socket_connect(RrMessageType si_type)
5516runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005517 /* this (among other things) establishes the first connection to the PCUIF socket */
5518 f_init();
5519 f_init_l1ctl();
5520 f_l1_tune(L1CTL);
5521
5522 f_sleep(2.0);
5523 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005524
5525 if (not f_si_has_gprs_indicator(si_type)) {
5526 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005527 } else {
5528 setverdict(pass);
5529 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005530
Harald Weltebe030482019-05-27 22:29:35 +02005531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5532}
5533
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005534testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5535 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5536}
Harald Weltebe030482019-05-27 22:29:35 +02005537
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005538testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5539 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5540}
5541
5542/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5543private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5544runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005545 /* this (among other things) establishes the first connection to the PCUIF socket */
5546 f_init();
5547 f_init_l1ctl();
5548 f_l1_tune(L1CTL);
5549
5550 f_pcuif_close(PCU, g_pcu_conn_id);
5551 g_pcu_conn_id := -1;
5552
5553 f_sleep(1.0);
5554
5555 /* re-connect */
5556 PCU.clear;
5557 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5558
5559 f_sleep(2.0);
5560 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005561
5562 if (f_si_has_gprs_indicator(si_type)) {
5563 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005564 } else {
5565 setverdict(pass);
5566 }
5567
5568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5569}
5570
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005571testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5572 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5573}
5574
5575testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5576 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5577}
5578
Oliver Smithf5239c72019-08-28 10:01:25 +02005579/* 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) */
5580testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5581 var SystemInformation si3 := valueof(ts_SI3_default);
5582
5583 f_init();
5584
Harald Welte76220222020-10-11 20:32:44 +02005585 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5586 * information */
5587 timer T := 2.0;
5588 T.start;
5589 alt {
5590 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5591 [] T.timeout {}
5592 }
5593
Oliver Smithf5239c72019-08-28 10:01:25 +02005594 /* Verify cell_id */
5595 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5596 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5597 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005598 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5599 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5600 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005601 }
5602
5603 /* Verify LAC */
5604 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5605 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5606 if (lac_si3 != lac_pcu) {
5607 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5608 }
5609
5610 setverdict(pass);
5611}
Harald Welted66c9b82019-05-25 09:03:15 +02005612
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005613/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5614testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5615 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005616 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005617
5618 f_init();
5619
5620 info_ind := g_pcu_last_info.u.info_ind;
5621
5622 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5623 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5624 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5625 /* Skip inactive timeslots */
5626 continue;
5627 }
5628
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005629 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005630 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005631 else
5632 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005633
5634 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005635 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005636 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005637 hsn := fhp.maio_hsn.hsn,
5638 maio := fhp.maio_hsn.maio,
5639 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005640 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005641 } else {
5642 tr_ts := tr_PCUIF_InfoTrxTsH0;
5643 }
5644
5645 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5646 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5647 if (not match(ts, tr_ts)) {
5648 setverdict(fail, "Hopping parameters do not match: ",
5649 "received ", ts, " vs expected ", tr_ts);
5650 } else {
5651 setverdict(pass);
5652 }
5653 }
5654 }
5655}
5656
Alexander Couzens5283f552020-07-28 15:39:04 +02005657/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5658testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5659 f_init_vty_bsc();
5660 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5661 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5662
5663 f_init();
5664
5665 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5666 if (not ischosen(remote_addr.v10)) {
5667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5668 log2str("Unexpected remote_addr: ", remote_addr));
5669 }
5670
5671 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5672 setverdict(fail, "Received address family is not IPv4");
5673 }
5674
5675 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5676 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5677 }
5678
5679 setverdict(pass);
5680}
5681
5682/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5683testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5684 f_init_vty_bsc();
5685 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5686
5687 f_init();
5688
5689 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5690 if (not ischosen(remote_addr.v10)) {
5691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5692 log2str("Unexpected remote_addr: ", remote_addr));
5693 }
5694
5695 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5696 setverdict(fail, "Received address family is not IPv6");
5697 }
5698
5699 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5700 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5701 }
5702
5703 setverdict(pass);
5704}
5705
Harald Welte3d04ae62018-04-04 20:29:05 +02005706/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005707 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005708 ***********************************************************************/
5709
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005710private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5711 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005712runs on ConnHdlr {
5713 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005714
5715 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005716 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005717 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5718 repeat;
5719 }
5720 }
5721}
5722
5723private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5724runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005725 /* Expect BTS to immediately acknowledge activation as PDCH */
5726 PCU.clear;
5727 f_rsl_chan_act(g_pars.chan_mode);
5728 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005729 timer T_wait := 2.0;
5730 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005731 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005732 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005733 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005734 [] T_wait.timeout {
5735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5736 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5737 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005738 }
5739 /* try to activate this PDCH from the PCU point of view */
5740 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5741 /* FIXME: is there a response? */
5742}
5743
5744private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5745runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005746 /* Send RSL CHAN REL (deactivate) */
5747 PCU.clear;
5748 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5749 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005750 timer T_wait := 2.0;
5751 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005752 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005753 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005754 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005755 [] T_wait.timeout {
5756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5757 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5758 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005759 }
5760 /* Emulate PCU asking BTS to deactivate PDCH */
5761 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5762 alt {
5763 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5764 setverdict(pass);
5765 }
5766 [] RSL.receive { repeat; }
5767 }
5768}
5769
5770/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005771private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005772 var PCUIF_Message first_info;
5773 var integer ts_nr := g_chan_nr.tn;
5774 var integer trx_nr := 0;
5775 var integer bts_nr := 0;
5776 var integer pcu_conn_id := -1;
5777
5778 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5779
5780 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5781 f_sleep(3.0);
5782 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5783 setverdict(pass);
5784}
5785testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5786 var ConnHdlrPars pars;
5787 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005788 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005789
5790 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5791 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5792 vc_conn.done;
5793}
5794
5795/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005796private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005797 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005798 var integer pcu_conn_id := -1;
5799
5800 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5801
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005802 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5803 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5804 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005805 setverdict(pass);
5806}
5807testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5808 var ConnHdlrPars pars;
5809 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005810 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005811
5812 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5813 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5814 vc_conn.done;
5815}
5816
5817/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005818private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005819 var PCUIF_Message first_info;
5820 var integer ts_nr := g_chan_nr.tn;
5821 var integer trx_nr := 0;
5822 var integer bts_nr := 0;
5823 var integer pcu_conn_id := -1;
5824
5825 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5826
5827 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005828 /* Send a second Chan Activ and expect it to be NACKed */
5829 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5830 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005831 setverdict(pass);
5832}
5833testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5834 var ConnHdlrPars pars;
5835 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005836 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005837
5838 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5839 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5840 vc_conn.done;
5841}
5842
5843/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005844private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005845 var PCUIF_Message first_info;
5846 var integer ts_nr := g_chan_nr.tn;
5847 var integer trx_nr := 0;
5848 var integer bts_nr := 0;
5849 var integer pcu_conn_id := -1;
5850 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5851
5852 /* register for the TCH/F channel number */
5853 f_rslem_register(0, chan_nr);
5854
5855 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5856
5857 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5858 "RSL CHAN ACT");
5859 setverdict(pass);
5860}
5861testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5862 var ConnHdlrPars pars;
5863 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005864 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005865
5866 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5867 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5868 vc_conn.done;
5869}
5870
5871/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005872private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005873 var PCUIF_Message first_info;
5874 var integer ts_nr := g_chan_nr.tn;
5875 var integer trx_nr := 0;
5876 var integer bts_nr := 0;
5877 var integer pcu_conn_id := -1;
5878 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5879 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5880
5881 /* register for the TCH/H channel numbers */
5882 f_rslem_register(0, chan_nr[0]);
5883 f_rslem_register(0, chan_nr[1]);
5884
5885 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5886
5887 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5888 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5889 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5890 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5891 setverdict(pass);
5892}
5893testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5894 var ConnHdlrPars pars;
5895 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005896 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005897
5898 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5899 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5900 vc_conn.done;
5901}
5902
Harald Welte9bbbfb52018-04-05 09:33:19 +02005903/***********************************************************************
5904 * IPA Style Dynamic Timeslot Support
5905 ***********************************************************************/
5906
5907private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5908runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005909 /* Expect BTS to immediately acknowledge activation as PDCH */
5910 PCU.clear;
5911 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5912 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005913 timer T_wait := 2.0;
5914 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005915 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005916 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005917 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005918 [] T_wait.timeout {
5919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5920 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5921 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005922 }
5923 /* try to activate this PDCH from the PCU point of view */
5924 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5925 /* FIXME: is there a response? */
5926
5927 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5928}
5929
5930private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5931runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005932 /* Send RSL CHAN REL (deactivate) */
5933 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5934 PCU.clear;
5935 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005936 timer T_wait := 2.0;
5937 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005938 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005939 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005940 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005941 [] T_wait.timeout {
5942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5943 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5944 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005945 }
5946 /* Emulate PCU asking BTS to deactivate PDCH */
5947 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5948 alt {
5949 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5950 setverdict(pass);
5951 }
5952 [] RSL.receive { repeat; }
5953 }
5954}
5955
5956/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005957private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005958 var PCUIF_Message first_info;
5959 var integer ts_nr := g_chan_nr.tn;
5960 var integer trx_nr := 0;
5961 var integer bts_nr := 0;
5962 var integer pcu_conn_id := -1;
5963
5964 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5965
5966 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5967 f_sleep(3.0);
5968 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5969
5970 setverdict(pass);
5971
5972}
5973testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5974 var ConnHdlrPars pars;
5975 var ConnHdlr vc_conn;
5976 f_init();
5977
5978 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5979 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5980 vc_conn.done;
5981}
5982
5983/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005984private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005985 var PCUIF_Message first_info;
5986 var integer ts_nr := g_chan_nr.tn;
5987 var integer trx_nr := 0;
5988 var integer bts_nr := 0;
5989 var integer pcu_conn_id := -1;
5990
5991 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5992
5993 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5994 "RSL CHAN ACT");
5995 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5996 "RF CHAN REL", true);
5997 setverdict(pass);
5998}
5999testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6000 var ConnHdlrPars pars;
6001 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006002 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006003
6004 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6005 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6006 vc_conn.done;
6007}
6008
6009/* 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 +07006010private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006011 var PCUIF_Message first_info;
6012 var integer ts_nr := g_chan_nr.tn;
6013 var integer trx_nr := 0;
6014 var integer bts_nr := 0;
6015 var integer pcu_conn_id := -1;
6016
6017 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6018
6019 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6020 "RSL CHAN ACT");
6021
6022 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6023 alt {
6024 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6025 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006027 }
6028 [] RSL.receive { repeat; }
6029 }
6030
6031 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6032 "RF CHAN REL", true);
6033 setverdict(pass);
6034}
6035testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6036 var ConnHdlrPars pars;
6037 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006038 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006039
6040 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6041 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6042 vc_conn.done;
6043}
6044
6045/* 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 +07006046private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006047 var PCUIF_Message first_info;
6048 var integer ts_nr := g_chan_nr.tn;
6049 var integer trx_nr := 0;
6050 var integer bts_nr := 0;
6051 var integer pcu_conn_id := -1;
6052
6053 /* register for the TCH/F channel number */
6054 f_rslem_register(0, g_chan_nr);
6055
6056 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6057
6058 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6059
6060 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6061 "RSL CHAN ACT");
6062
6063 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6064
6065 setverdict(pass);
6066}
6067testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6068 var ConnHdlrPars pars;
6069 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006070 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006071
6072 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6073 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6074 vc_conn.done;
6075}
6076
6077
Harald Welte0472ab42018-03-12 15:02:26 +01006078/***********************************************************************
6079 * LAPDm / RLL related
6080 ***********************************************************************/
6081
6082private function f_tx_lapdm(template (value) LapdmFrame l,
6083 template (value) RslLinkId link_id) runs on ConnHdlr {
6084 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006085 var template (value) SacchL1Header l1h;
6086
6087 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006088 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006089 /* Compose dummy L1 header */
6090 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6091 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 +02006092 } else {
6093 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006094 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 +01006095 }
Harald Welte0472ab42018-03-12 15:02:26 +01006096}
6097
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006098private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006099 uint3_t sapi,
6100 RslLinkId link_id,
6101 octetstring l3,
6102 boolean exp
6103}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006104private type record of RllTestCase RllTestCases;
6105private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6106 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006107 sapi := sapi,
6108 link_id := id,
6109 l3 := l3,
6110 exp := exp
6111}
6112
6113/* execute the same callback function with a set of different parameters (tcs) on a
6114 * variety of logical channels */
6115private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6116 var ConnHdlrPars pars;
6117 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006118 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006119
6120 /* test on each of the channels we have */
6121 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6122 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6123
6124 /* test each of the test cases on the current channel */
6125 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6126 pars.spec.rll := tcs[j];
6127 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6128 vc_conn := f_start_handler(fn, pars);
6129 vc_conn.done;
6130 }
6131 }
6132
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006134}
6135
6136/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6137private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6138 var RllTestCase tc := g_pars.spec.rll;
6139 timer T := 3.0;
6140
6141 f_l1_tune(L1CTL);
6142 RSL.clear;
6143
6144 /* activate the logical channel */
6145 f_est_dchan();
6146 L1CTL.clear;
6147
6148 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6149 T.start;
6150 alt {
6151 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6152 if (tc.exp) {
6153 setverdict(pass);
6154 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006156 }
6157 }
6158 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6159 if (tc.exp) {
6160 setverdict(pass);
6161 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006163 }
6164 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006165 /* We also expect to receive the measurements */
6166 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006167 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006169 }
6170 [not tc.exp] T.timeout {
6171 setverdict(pass);
6172 }
6173 }
6174
6175 f_rsl_chan_deact();
6176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6177 f_rslem_unregister(0, g_chan_nr);
6178}
6179testcase TC_rll_est_ind() runs on test_CT {
6180 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006181 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006182 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006183 /* normal SAPI0 establishment */
6184 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006185 /* SAPI 3 doesn't support contention resolution */
6186 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6187 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6188 /* normal SAPI3 establishment on main DCCH */
6189 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6190 /* normal SAPI3 establishment on SACCH */
6191 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6192 };
6193 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6194}
6195
6196/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6197private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6198 var RllTestCase tc := g_pars.spec.rll;
6199 var L1ctlDlMessage dl;
6200 timer T := 3.0;
6201
6202 f_l1_tune(L1CTL);
6203 RSL.clear;
6204
6205 /* activate the logical channel */
6206 f_est_dchan();
6207 L1CTL.clear;
6208
6209 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6210 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6211 T.start;
6212 alt {
6213 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6214 var LapdmFrame lapdm;
6215 var octetstring l2 := dl.payload.data_ind.payload;
6216 if (dl.dl_info.link_id.c == SACCH) {
6217 /* remove L1 header */
6218 l2 := substr(l2, 2, lengthof(l2)-2);
6219 }
6220 lapdm.ab := dec_LapdmFrameAB(l2);
6221 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6222 setverdict(pass);
6223 } else {
6224 repeat;
6225 }
6226 }
6227 [] L1CTL.receive { repeat; }
6228 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006230 }
6231 }
6232
6233 f_rsl_chan_deact();
6234 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6235 f_rslem_unregister(0, g_chan_nr);
6236}
6237testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6238 var RllTestCases tcs := {
6239 /* normal SAPI3 establishment on main DCCH */
6240 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6241 };
6242 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6243}
6244testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6245 var RllTestCases tcs := {
6246 /* normal SAPI3 establishment on SACCH */
6247 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6248 }
6249 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6250}
6251
6252/* altstep to receive a LAPDm frame matching the given template */
6253private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6254 var L1ctlDlMessage dl;
6255 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6256 var LapdmFrame lapdm;
6257 var octetstring l2 := dl.payload.data_ind.payload;
6258 if (dl.dl_info.link_id.c == SACCH) {
6259 /* remove L1 header */
6260 l2 := substr(l2, 2, lengthof(l2)-2);
6261 }
6262 if (ischosen(exp.ab)) {
6263 lapdm.ab := dec_LapdmFrameAB(l2);
6264 } else if (ischosen(exp.b4)) {
6265 lapdm.b4 := dec_LapdmFrameB4(l2);
6266 } else if (ischosen(exp.bbis)) {
6267 lapdm.bbis := dec_LapdmFrameBbis(l2);
6268 }
6269 log("Rx LAPDm ", lapdm);
6270 if (match(lapdm, exp)) {
6271 setverdict(pass);
6272 } else {
6273 repeat;
6274 }
6275 }
6276 [] L1CTL.receive { repeat; }
6277}
6278private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6279 timer T := t;
6280 T.start;
6281 alt {
6282 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006284 }
6285 [] as_l1_exp_lapdm(exp);
6286 }
6287}
6288
6289/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6290private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6291 /* send SABM from MS -> BTS */
6292 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6293 /* expect RLL EST IND on Abis */
6294 alt {
6295 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6296 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6297 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006299 }
6300 [] RSL.receive { repeat; }
6301 }
6302 /* expect UA from BTS -> MS */
6303 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6304}
6305
6306/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6307private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6308 var RllTestCase tc := g_pars.spec.rll;
6309
6310 f_l1_tune(L1CTL);
6311 RSL.clear;
6312
6313 /* activate the logical channel */
6314 f_est_dchan();
6315 L1CTL.clear;
6316
6317 /* first establish the link-layer */
6318 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6319
6320 /* then send the DISC */
6321 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6322 /* ... and expect the REL IND on the RSL side */
6323 alt {
6324 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6325 setverdict(pass);
6326 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006327 /* We also expect to receive the measurements */
6328 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006329 }
6330
6331 /* release the channel */
6332 f_rsl_chan_deact();
6333 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6334 f_rslem_unregister(0, g_chan_nr);
6335}
6336testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6337 var RllTestCases tcs := {
6338 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6339 };
6340 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6341}
6342
6343testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6344 var RllTestCases tcs := {
6345 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6346 };
6347 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6348}
6349testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6350 var RllTestCases tcs := {
6351 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6352 };
6353 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6354}
6355testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6356 var RllTestCases tcs := {
6357 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6358 };
6359 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6360}
6361
6362/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6363private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6364 var RllTestCase tc := g_pars.spec.rll;
6365 f_l1_tune(L1CTL);
6366 RSL.clear;
6367
6368 /* activate the logical channel */
6369 f_est_dchan();
6370 L1CTL.clear;
6371
6372 /* first establish the link-layer */
6373 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6374
6375 /* then send the REL REQ via RSL */
6376 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6377 /* ... and expect the DISC on the Um side */
6378 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006379 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006380 /* FIXME: send a UA in resposne to the DISC */
6381 }
6382 }
6383
6384 /* release the channel */
6385 f_rsl_chan_deact();
6386 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6387 f_rslem_unregister(0, g_chan_nr);
6388}
6389testcase TC_rll_rel_req() runs on test_CT {
6390 var RllTestCases tcs := {
6391 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6392 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6393 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6394 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6395 };
6396 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6397}
6398
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006399/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006400testcase TC_rll_data_req() runs on test_CT {
6401}
6402
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006403/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006404testcase TC_rll_data_ind() runs on test_CT {
6405}
6406
6407/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6408private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6409 var RllTestCase tc := g_pars.spec.rll;
6410
6411 f_l1_tune(L1CTL);
6412 RSL.clear;
6413
6414 f_est_dchan();
6415 L1CTL.clear;
6416
6417 /* Send UNITDATA REQ on RSL side */
6418 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6419 /* Expect it to arrive on the other side */
6420 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006421 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006422 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006423 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006424 }
6425
6426 /* release the channel */
6427 f_rsl_chan_deact();
6428 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6429 f_rslem_unregister(0, g_chan_nr);
6430}
6431testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6432 var octetstring l3 := f_rnd_octstring(15);
6433 var RllTestCases tcs := {
6434 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6435 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6436 };
6437 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6438}
6439testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6440 var octetstring l3 := f_rnd_octstring(19);
6441 var RllTestCases tcs := {
6442 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6443 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6444 };
6445 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6446}
6447
6448/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6449private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6450 var RllTestCase tc := g_pars.spec.rll;
6451
6452 f_l1_tune(L1CTL);
6453 RSL.clear;
6454
6455 f_est_dchan();
6456 L1CTL.clear;
6457
6458 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006459 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006460 /* Expdct RLL UNITDATA IND on RSL side */
6461 alt {
6462 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6463 setverdict(pass);
6464 }
6465 [] RSL.receive { repeat; }
6466 }
6467
6468 /* release the channel */
6469 f_rsl_chan_deact();
6470 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6471 f_rslem_unregister(0, g_chan_nr);
6472}
6473testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006474 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006475 var RllTestCases tcs := {
6476 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6477 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6478 };
6479 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6480}
6481testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6482 var octetstring l3 := f_rnd_octstring(18);
6483 var RllTestCases tcs := {
6484 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6485 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6486 };
6487 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6488}
6489
Harald Weltee613f962018-04-18 22:38:16 +02006490/***********************************************************************
6491 * Encryption Related
6492 ***********************************************************************/
6493
6494/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006495private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006496 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6497 if (link_id.c == SACCH) {
6498 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6499 } else {
6500 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6501 }
6502}
6503
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006504/* Expect (or not expect) other kinds of messages */
6505private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6506 [exp_any] RSL.receive { repeat; }
6507 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006509 }
6510}
6511
Harald Weltee613f962018-04-18 22:38:16 +02006512/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006513private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006514 RslLinkId link_id,
6515 octetstring l3,
6516 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006517 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006518) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006519 timer T := 3.0;
6520 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6521 T.start;
6522 /* Expect RLL UNITDATA IND on RSL side */
6523 alt {
6524 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6525 setverdict(pass);
6526 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006527 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006528 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006529 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006531 }
Harald Weltee613f962018-04-18 22:38:16 +02006532 }
6533}
6534
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006535/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6536private function f_data_mo(
6537 RslLinkId link_id,
6538 boolean p, uint3_t nr, uint3_t ns,
6539 octetstring l3,
6540 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006541 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006542) runs on ConnHdlr {
6543 timer T := 3.0;
6544 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6545 T.start;
6546 /* Expect RLL DATA IND on RSL side */
6547 alt {
6548 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6549 setverdict(pass);
6550 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006551 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006552 [] as_rsl_any_ind(exp_any);
6553 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006555 }
6556 }
6557}
6558
Harald Weltee613f962018-04-18 22:38:16 +02006559/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006560private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006561 f_l1_tune(L1CTL);
6562 f_est_dchan(true);
6563
6564 /* now we actually need to transmit some data both ways to check if the encryption works */
6565 var L1ctlDlMessage dl;
6566
Stefan Sperling603d98e2018-07-25 16:47:28 +02006567 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006568 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6569
6570 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6571 f_unitdata_mt(link_id, l3);
6572
6573 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6574 f_unitdata_mo(link_id, l3);
6575
6576 /* release the channel */
6577 f_rsl_chan_deact();
6578 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6579 f_rslem_unregister(0, g_chan_nr);
6580}
6581testcase TC_chan_act_a51() runs on test_CT {
6582 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6583 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6584 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6585}
6586testcase TC_chan_act_a52() runs on test_CT {
6587 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6588 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6589 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6590}
6591testcase TC_chan_act_a53() runs on test_CT {
6592 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6593 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6594 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6595}
6596
Eric Wildf1827a72019-05-28 17:37:35 +02006597/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6598 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 +07006599private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006600 f_l1_tune(L1CTL);
6601 f_est_dchan(true);
6602
6603 /* now we actually need to transmit some data both ways to check if the encryption works */
6604 var L1ctlDlMessage dl;
6605
6606 var octetstring l3 := f_rnd_octstring(20);
6607 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6608
6609 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6610 f_unitdata_mt(link_id, l3);
6611
6612 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6613 f_unitdata_mo(link_id, l3);
6614
6615 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006616 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006617
6618 /* modify key to break proper encryption */
6619 g_pars.encr.key := f_rnd_octstring(8);
6620 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6621 rsl.ies := rsl.ies & { ei };
6622 RSL.send(rsl);
6623
6624 timer T0 := 1.0;
6625 T0.start;
6626 /* Expect RSL MODIFY ACK */
6627 alt {
6628 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6629 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6631 }
6632 [] T0.timeout {
6633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6634 }
6635 }
6636
6637 var octetstring l3msg := f_rnd_octstring(15);
6638 timer T1 := 3.0;
6639 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6640 due to broken encryption */
6641 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6642 T1.start;
6643 alt {
6644 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6646 }
6647 [] T1.timeout {
6648 setverdict(pass);
6649 }
6650 }
6651
6652 /* release the channel */
6653 f_rsl_chan_deact();
6654 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6655 f_rslem_unregister(0, g_chan_nr);
6656}
6657testcase TC_rsl_modify_encr() runs on test_CT {
6658 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6659 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6660 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6661}
Harald Weltee613f962018-04-18 22:38:16 +02006662
6663/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006664private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006665 /* L3 payload doesn't matter, as it is passed transparently */
6666 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6667 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6668 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6669
6670 f_l1_tune(L1CTL);
6671
6672 /* first establish a dedicated channel in the clear */
6673 f_est_dchan(false);
6674
6675 /* Establish ABM */
6676 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6677
6678 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6679 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6680 /* expect the L3 to arrive still unencrypted on the MS side */
6681 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6682
6683 /* configure L1 to apply ciphering */
6684 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6685 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6686
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006687 /* send first ciphered I-frame in response and expect it on RSL */
6688 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006689
6690 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6691 * and hence enable encryption also on the downlink */
6692
6693 /* expect bi-directional communication work in encrypted mode */
6694 f_unitdata_mo(link_id, f_rnd_octstring(15));
6695 f_unitdata_mt(link_id, f_rnd_octstring(15));
6696
6697 /* release the channel */
6698 f_rsl_chan_deact();
6699 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6700 f_rslem_unregister(0, g_chan_nr);
6701}
6702testcase TC_encr_cmd_a51() runs on test_CT {
6703 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6704 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6705 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6706}
6707testcase TC_encr_cmd_a52() runs on test_CT {
6708 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6709 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6710 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6711}
6712testcase TC_encr_cmd_a53() runs on test_CT {
6713 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6714 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6715 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6716}
6717
6718private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6719 var LapdmFrame lf;
6720 var octetstring reenc;
6721
6722 /* decode the LAPDm frame */
6723 if (ischosen(exp_match.ab)) {
6724 lf.ab := dec_LapdmFrameAB(enc);
6725 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006727 }
6728
6729 /* check if decoder result matches expectation */
6730 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006732 } else {
6733 log(name, ": matched");
6734 setverdict(pass);
6735 }
6736
6737 /* test if re-encoded frame equals original input */
6738 reenc := enc_LapdmFrame(lf);
6739 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006741 } else {
6742 setverdict(pass);
6743 }
6744}
6745
6746testcase TC_lapdm_selftest() runs on test_CT {
6747 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6748 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6749 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6750 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6751 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6752 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6753 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6754}
6755
Stefan Sperling4880be42018-08-07 18:12:59 +02006756/***********************************************************************
6757 * DTX Related (see GSM 05.08, section 8.3)
6758 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006759private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006760 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006761 var GsmFrameNumber first_fn;
6762 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006763 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006764 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006765 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6766 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006767 const integer frame_dtx_tchf_mod := 104;
6768 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6769 * which operates in terms of blocks rather than frames. */
6770 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6771 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006772 timer T := 5.0;
6773
6774 f_l1_tune(L1CTL);
6775 RSL.clear;
6776 L1CTL.clear;
6777
6778 /* activate TCHF signalling channel */
6779 f_est_dchan(false);
6780
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006781 /* A template for matching dummy LAPDm func=UA frames */
6782 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6783 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6784 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6785
Stefan Sperling4880be42018-08-07 18:12:59 +02006786 T.start;
6787 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006788 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006789 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006790
6791 if (is_first_frame) {
6792 is_first_frame := false;
6793 first_fn := dl.dl_info.frame_nr;
6794 }
6795
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006796 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006797 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006798 T.stop;
6799 f_rsl_chan_deact();
6800 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006801
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006802 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6803 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006804
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006805 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006806 setverdict(fail, "Not enough fill frames received: ",
6807 nfill_frames, " out of ", expected_fill_frames);
6808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006809 } else {
6810 setverdict(pass);
6811 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006812 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006813 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6814 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6815 * we should only see the subset of frames numbers which correspond to a block boundary.
6816 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6817 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6818 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006819 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006820 repeat;
6821 }
6822 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006823 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6824 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6825 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006826 f_rsl_chan_deact();
6827 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006828 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006829 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006830 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006831 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006832 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006833
6834 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006835 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6836 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006837 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6838 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6839 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006840 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6841 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006842 case else {
6843 /* This shall not happen, just to be sure */
6844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6845 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006846 }
6847
6848 f_rsl_chan_deact();
6849 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006850
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006851 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006852 setverdict(pass);
6853 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006854 setverdict(fail, "Not enough fill frames received: ",
6855 nfill_frames, " out of ", expected_fill_frames);
6856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006857 }
6858 } else {
6859 repeat;
6860 }
6861 }
6862 }
6863 [] L1CTL.receive { repeat; }
6864 [] T.timeout {
6865 f_rsl_chan_deact();
6866 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006868 }
6869 }
6870}
6871
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006872private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006873 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006874 var ConnHdlr vc_conn;
6875 var ConnHdlrPars pars;
6876 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006877 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006878 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006879 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006880 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006881 if (dtxd) {
6882 if (i >= 4) { /* DTX is only allowed on TCH/F */
6883 break;
6884 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006885 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006886 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006887 vc_conn.done;
6888 }
6889}
6890
6891/* Verify that L2 fill frames are sent on TCH in signaling mode if
6892 * there is nothing to transmit while DTX is disabled on downlink. */
6893testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6894 f_tch_sign_l2_fill_frame(false);
6895}
6896
6897/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6898 * there is nothing to transmit while DTX is enabled on downlink. */
6899testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6900 f_tch_sign_l2_fill_frame(true);
6901}
Harald Welte0472ab42018-03-12 15:02:26 +01006902
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006903testcase TC_chopped_ipa_ping() runs on test_CT {
6904 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6905}
6906
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006907testcase TC_chopped_ipa_payload() runs on test_CT {
6908 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6909}
6910
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006911
6912/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6913 * Return value: Measurement Report to be sent (encoded octetstring). */
6914type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6915 runs on ConnHdlr return octetstring;
6916
6917private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6918runs on ConnHdlr {
6919 var L1ctlDlMessage l1_dl;
6920 var SacchL1Header l1h;
6921 var octetstring l2;
6922
6923 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6924 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6925 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6926 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6927
6928 /* Pass it to the user specified call-back function */
6929 l2 := cb.apply(l1h, num_blocks);
6930 /* Send a Measurement Report generated by the call-back */
6931 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6932 l1_dl.dl_info.link_id,
6933 l1h, l2));
6934
6935 /* Shall we keep going? */
6936 num_blocks := num_blocks - 1;
6937 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6938 if (num_blocks > 0) { repeat; }
6939 }
6940 [] L1CTL.receive { repeat; }
6941}
6942
6943private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6944runs on ConnHdlr return octetstring {
6945 /* Command the L1 to apply received parameters */
6946 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6947
6948 /* Dummy measurement report (the results are invalid) */
6949 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6950}
6951
6952private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6953runs on ConnHdlr return octetstring {
6954 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6955 setverdict(fail, "Unexpected MS Power level change: ",
6956 g_pars.l1_pars.ms_power_level, " -> ",
6957 l1h.ms_power_lvl);
6958 }
6959
6960 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6961}
6962
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006963private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6964runs on ConnHdlr return octetstring {
6965 /* UL RSSI oscillation driven by SACCH block number */
6966 if (num_blocks rem 2 == 0) {
6967 f_trxc_fake_rssi(-100);
6968 } else {
6969 f_trxc_fake_rssi(-50);
6970 }
6971
6972 /* Make sure that MS power level remains constant */
6973 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6974}
6975
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006976/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6977private function f_TC_ms_pwr_ctrl_constant(charstring id)
6978runs on ConnHdlr {
6979 var integer num_blocks := 8;
6980 timer T := int2float(num_blocks);
6981
6982 f_l1_tune(L1CTL);
6983 RSL.clear;
6984
6985 /* These IEs are needed for autonomous MS power control */
6986 var template (value) RSL_IE_List ies := {
6987 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6988 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6989 }),
6990 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6991 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6992 })
6993 };
6994
6995 /* Ensure that 'rx-current' equals 'rx-target' */
6996 f_trxc_fake_rssi(mp_uplink_power_target);
6997
6998 /* Establish a dedicated channel */
6999 f_est_dchan(more_ies := valueof(ies));
7000
7001 L1CTL.clear;
7002 T.start;
7003 alt {
7004 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7005 [] T.timeout {
7006 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7007 num_blocks, " were not handled");
7008 }
7009 }
7010}
7011testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7012 var ConnHdlr vc_conn;
7013 var ConnHdlrPars pars;
7014
7015 f_init();
7016
7017 /* Explicitly configure the Uplink power target (in dBm) */
7018 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7019
7020 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7021 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7022 log(testcasename(), ": starting on ", pars.chan_nr);
7023
7024 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7025 pars, trxc_comp := true);
7026 vc_conn.done;
7027 }
7028
7029 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7031}
7032
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007033/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7034private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7035runs on ConnHdlr {
7036 var integer num_blocks := 16;
7037 timer T := int2float(num_blocks);
7038
7039 f_l1_tune(L1CTL);
7040 RSL.clear;
7041
7042 /* These IEs are needed for autonomous MS power control */
7043 var template (value) RSL_IE_List ies := {
7044 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7045 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7046 }),
7047 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7048 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7049 })
7050 };
7051
7052 /* Ensure that 'rx-current' equals 'rx-target' */
7053 f_trxc_fake_rssi(mp_uplink_power_target);
7054
7055 /* Establish a dedicated channel */
7056 f_est_dchan(more_ies := valueof(ies));
7057
7058 L1CTL.clear;
7059 T.start;
7060 alt {
7061 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7062 [] T.timeout {
7063 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7064 num_blocks, " were not handled");
7065 }
7066 }
7067}
7068testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7069 var ConnHdlr vc_conn;
7070 var ConnHdlrPars pars;
7071
7072 f_init();
7073
7074 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7075 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7076 /* Explicitly configure the Uplink power range (target and delte) */
7077 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7078 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7079
7080 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7081 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7082 log(testcasename(), ": starting on ", pars.chan_nr);
7083
7084 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7085 pars, trxc_comp := true);
7086 vc_conn.done;
7087 }
7088
7089 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7091}
7092
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007093private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7094 var template L1ctlDlMessage tr_bad_frame;
7095 var L1ctlDlMessage l1_dl;
7096 timer T := 8.0;
7097
7098 f_l1_tune(L1CTL);
7099 RSL.clear;
7100
7101 f_est_dchan();
7102
7103 /* There may be a few errors right after the channel activation */
7104 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7105 L1CTL.clear;
7106
7107 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7108 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7109 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7110 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7111 tr_bad_frame.payload := ?;
7112
7113 T.start;
7114 alt {
7115 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7116 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7117 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7118 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7119 }
7120 [] as_l1_sacch();
7121 [] L1CTL.receive { repeat; }
7122 [] T.timeout {
7123 /* We're done, break the loop */
7124 setverdict(pass);
7125 }
7126 }
7127
7128 f_rsl_chan_deact();
7129 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7130}
7131testcase TC_speech_no_rtp_tchf() runs on test_CT {
7132 var ConnHdlr vc_conn;
7133 var ConnHdlrPars pars;
7134
7135 f_init();
7136
7137 /* TS1, TCH/F, V1 (FR codec) */
7138 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7139 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7140 vc_conn.done;
7141}
7142testcase TC_speech_no_rtp_tchh() runs on test_CT {
7143 var ConnHdlr vc_conn;
7144 var ConnHdlrPars pars;
7145
7146 f_init();
7147
7148 /* TS5, TCH/H, V1 (HR codec) */
7149 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7150 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7151 vc_conn.done;
7152}
7153
Harald Welte0472ab42018-03-12 15:02:26 +01007154/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7155/* protocol error as per 44.006 */
7156/* link layer failure (repetition of I-frame N200 times without ACK */
7157/* repetition of SABM or DISC N200 times without ACK */
7158/* receptiom of SABM in multi-frame established state */
7159
7160
Harald Welte68e495b2018-02-25 00:05:57 +01007161/* TODO Areas:
7162
7163* channel activation
7164** with BS_Power / MS_Power, bypassing power control loop
7165** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007166** with timing advance from initial activation on
7167* mode modify
7168** encryption
7169** multirate
7170* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007171** unsupported algorithm
7172* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007173* BS Power Control
7174* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007175* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007176* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007177** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007178* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007179** DATA_IND from BTS->PCU
7180** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007181
7182*/
Harald Welte70767382018-02-21 12:16:40 +01007183
7184control {
7185 execute( TC_chan_act_stress() );
7186 execute( TC_chan_act_react() );
7187 execute( TC_chan_deact_not_active() );
7188 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007189 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007190 execute( TC_sacch_filling() );
7191 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007192 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007193 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007194 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007195 execute( TC_sacch_chan_act_ho_async() );
7196 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007197 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007198 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007199 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007200 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007201 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007202 execute( TC_rach_load_idle_thresh0() );
7203 execute( TC_rach_load_idle_below_thresh() );
7204 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007205 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007206 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007207 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007208 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007209 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007210 execute( TC_meas_res_sign_tchf() );
7211 execute( TC_meas_res_sign_tchh() );
7212 execute( TC_meas_res_sign_sdcch4() );
7213 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007214 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007215 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007216 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007217 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007218 execute( TC_rsl_bs_pwr_static_ass() );
7219 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007220 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007221 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007222 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007223 execute( TC_rsl_ms_pwr_dyn_up() );
7224 execute( TC_rsl_ms_pwr_dyn_down() );
7225 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7226 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007227 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007228 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007229 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007230 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007231 execute( TC_paging_imsi_80percent() );
7232 execute( TC_paging_tmsi_80percent() );
7233 execute( TC_paging_imsi_200percent() );
7234 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007235 execute( TC_rsl_protocol_error() );
7236 execute( TC_rsl_mand_ie_error() );
7237 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007238 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007239 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007240 execute( TC_si_sched_2bis() );
7241 execute( TC_si_sched_2ter() );
7242 execute( TC_si_sched_2ter_2bis() );
7243 execute( TC_si_sched_2quater() );
7244 execute( TC_si_sched_13() );
7245 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007246 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007247 execute( TC_ipa_crcx_twice_not_active() );
7248 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007249 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007250 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007251
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007252 if (mp_pcu_socket != "") {
7253 execute( TC_pcu_act_req() );
7254 execute( TC_pcu_act_req_wrong_ts() );
7255 execute( TC_pcu_act_req_wrong_bts() );
7256 execute( TC_pcu_act_req_wrong_trx() );
7257 execute( TC_pcu_deact_req() );
7258 execute( TC_pcu_deact_req_wrong_ts() );
7259 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007260 if (mp_l1_supports_gprs) {
7261 execute( TC_pcu_data_req_pdtch() );
7262 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007263 execute( TC_pcu_data_req_wrong_bts() );
7264 execute( TC_pcu_data_req_wrong_trx() );
7265 execute( TC_pcu_data_req_wrong_ts() );
7266 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007267 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007268 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007269 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007270 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007271 execute( TC_pcu_data_req_imm_ass_pch() );
7272 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007273 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007274 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007275 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007276 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007277 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007278 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007279 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007280 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007281 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007282 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007283 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007284 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007285 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007286 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007287 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007288 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007289 execute( TC_dyn_osmo_pdch_act_deact() );
7290 execute( TC_dyn_osmo_pdch_double_act() );
7291 execute( TC_dyn_ipa_pdch_act_deact() );
7292 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7293
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007294 if (PCUIF_Types.mp_pcuif_version >= 10) {
7295 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007296 execute( TC_pcu_socket_nsvc_ipv4() );
7297 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007298 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007299 } else {
7300 log("PCU socket path not available, skipping PCU tests");
7301 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007302
Harald Welte3d04ae62018-04-04 20:29:05 +02007303 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007304 execute( TC_dyn_osmo_pdch_tchf_act() );
7305 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007306 execute( TC_dyn_ipa_pdch_tchf_act() );
7307 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007308
7309 execute( TC_rll_est_ind() );
7310 execute( TC_rll_est_req_DCCH_3() );
7311 execute( TC_rll_est_req_ACCH_3() );
7312 execute( TC_rll_rel_ind_DCCH_0() );
7313 execute( TC_rll_rel_ind_DCCH_3() );
7314 execute( TC_rll_rel_ind_ACCH_0() );
7315 execute( TC_rll_rel_ind_ACCH_3() );
7316 execute( TC_rll_rel_req() );
7317 execute( TC_rll_unit_data_req_DCCH() );
7318 execute( TC_rll_unit_data_req_ACCH() );
7319 execute( TC_rll_unit_data_ind_DCCH() );
7320 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007321
7322 execute( TC_chan_act_a51() );
7323 execute( TC_chan_act_a52() );
7324 execute( TC_chan_act_a53() );
7325 execute( TC_encr_cmd_a51() );
7326 execute( TC_encr_cmd_a52() );
7327 execute( TC_encr_cmd_a53() );
7328
Harald Welteee25aae2019-05-19 14:32:37 +02007329 execute( TC_err_rep_wrong_mdisc() );
7330 execute( TC_err_rep_wrong_msg_type() );
7331 execute( TC_err_rep_wrong_sequence() );
7332
Harald Weltee613f962018-04-18 22:38:16 +02007333 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007334
7335 execute( TC_tch_sign_l2_fill_frame() );
7336 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007337
7338 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007339 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007340
7341 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007342 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007343
7344 execute( TC_speech_no_rtp_tchf() );
7345 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007346}
7347
7348
7349}