blob: a2394a0b8289f008f234ba2147b9a99c924b91c9 [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);
1235
1236 f_l1_tune(L1CTL);
1237 RSL.clear;
1238
1239 /* Step 1: Activate ASYNC HO channel without MS power IE */
1240
1241 /* Activate channel on BTS side */
1242 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1243 /* don't perform immediate assignment here, as we're testing non-IA case */
1244 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001245 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001246
1247 /* Verify that no DL SACCH is being received */
1248 f_sacch_missing(?);
1249
1250 f_rsl_chan_deact();
1251 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1252
1253
1254 /* Step 2: Activate ASYNC HO channel with MS power IE */
1255
1256 /* Activate channel on BTS side */
1257 var RSL_IE_List addl_ies := {
1258 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1259 };
1260 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1261 /* don't perform immediate assignment here, as we're testing non-IA case */
1262 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001263 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001264
1265 /* Verify that DL SACCH is being received */
1266 f_sacch_present(si5);
1267
1268 f_rsl_chan_deact();
1269 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1270}
1271testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1272 var ConnHdlr vc_conn;
1273 var ConnHdlrPars pars;
1274 f_init();
1275
1276 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1277 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1278 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1279 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1280 vc_conn.done;
1281 }
1282 /* TODO: do the above in parallel, rather than sequentially? */
1283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1284}
1285
1286/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1287 * see section 4.1.4 of 3GPP TS 48.058 */
1288private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1289 var octetstring si5 := f_rnd_octstring(19);
1290 var RSL_IE_List addl_ies;
1291
1292 f_l1_tune(L1CTL);
1293 RSL.clear;
1294
1295 /* Step 1: Activate SYNC HO channel without MS power IE */
1296
1297 /* Activate channel on BTS side */
1298 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1299 /* don't perform immediate assignment here, as we're testing non-IA case */
1300 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001301 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001302
1303 /* Verify that no DL SACCH is being received */
1304 f_sacch_missing(?);
1305
1306 f_rsl_chan_deact();
1307 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1308
1309
1310 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1311
1312 /* Activate channel on BTS side */
1313 addl_ies := {
1314 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1315 };
1316 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1317 /* don't perform immediate assignment here, as we're testing non-IA case */
1318 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001319 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001320
1321 /* Verify that no DL SACCH is being received */
1322 f_sacch_missing(?);
1323
1324 f_rsl_chan_deact();
1325 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1326
1327
1328 /* Step 2b: Activate SYNC HO channel with TA IE */
1329
1330 /* Activate channel on BTS side */
1331 addl_ies := {
1332 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1333 };
1334 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1335 /* don't perform immediate assignment here, as we're testing non-IA case */
1336 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001337 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001338
1339 /* Verify that no DL SACCH is being received */
1340 f_sacch_missing(?);
1341
1342 f_rsl_chan_deact();
1343 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1344
1345
1346 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1347
1348 /* Activate channel on BTS side */
1349 addl_ies := {
1350 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1351 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1352 };
1353 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1354 /* don't perform immediate assignment here, as we're testing non-IA case */
1355 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001356 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001357
1358 /* Verify that DL SACCH is being received */
1359 f_sacch_present(si5);
1360
1361 f_rsl_chan_deact();
1362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1363}
1364testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1365 var ConnHdlr vc_conn;
1366 var ConnHdlrPars pars;
1367 f_init();
1368
1369 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1370 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1371 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1372 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1373 vc_conn.done;
1374 }
1375 /* TODO: do the above in parallel, rather than sequentially? */
1376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1377}
Harald Welte629cc6b2018-03-11 17:19:05 +01001378
1379
1380/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001381 * RACH Handling
1382 ***********************************************************************/
1383
Harald Welte8c24c2b2018-02-26 08:31:31 +01001384/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001385private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001386 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001387 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001388 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001389
Harald Welte8c24c2b2018-02-26 08:31:31 +01001390 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001391 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001392 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001393 var OCT1 ra := f_rnd_ra_emerg();
1394 if (emerg == true) {
1395 ra := f_rnd_ra_emerg();
1396 } else {
1397 ra := f_rnd_ra_cs();
1398 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001399 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1400 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001402 }
1403 fn_last := fn;
1404
1405 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001406 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001407 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001408 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001409 T.stop;
1410 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001411 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001413 }
1414 [] RSL_CCHAN.receive { repeat; }
1415 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001416 test_failed := true;
1417 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001418 }
1419 }
1420 }
Maxba06feb2019-03-05 10:52:46 +01001421 if (test_failed) {
1422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001423 }
Maxba06feb2019-03-05 10:52:46 +01001424 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001426}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001427
Philipp Maier16ade782020-07-08 21:36:00 +02001428/* Normal variant */
1429testcase TC_rach_content() runs on test_CT {
1430 f_TC_rach_content(emerg := false);
1431}
1432
1433/* Emergency call variant */
1434testcase TC_rach_content_emerg() runs on test_CT {
1435 f_TC_rach_content(emerg := true);
1436}
1437
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1439testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001440 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001442 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001443 f_l1_tune(L1CTL);
1444
1445 var GsmFrameNumber fn_last := 0;
1446 for (var integer i := 0; i < 1000; i := i+1) {
1447 var OCT1 ra := f_rnd_ra_cs();
1448 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1449 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001451 }
1452 fn_last := fn;
1453 }
1454 var integer rsl_chrqd := 0;
1455 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001456 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001457 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001458 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001460 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001461 repeat;
1462 }
1463 [] RSL_CCHAN.receive { repeat; }
1464 [] T.timeout { }
1465 }
1466 if (rsl_chrqd == 1000) {
1467 setverdict(pass);
1468 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001470 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001472}
1473
Harald Welte3453ab42019-05-24 21:19:58 +02001474private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1475 var charstring bts_str := "bts " & int2str(bts_nr);
1476 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1477}
1478
1479/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1480private template integer tr_rach_slots_per_interval := (90 .. 130);
1481
1482/* Expect 0 RACH load on an idle BTS that has just started up */
1483testcase TC_rach_load_idle_thresh0() runs on test_CT {
1484 var ASP_RSL_Unitdata rx_ud;
1485
1486 f_init_vty_bsc();
1487 /* send load indications even at 0% load */
1488 f_vty_load_ind_thresh(0);
1489 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1490 f_sleep(2.0);
1491
1492 f_init();
1493
Harald Weltee37f9a52020-10-11 20:45:23 +02001494 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1495 alt {
1496 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1497 [] RSL_CCHAN.receive { repeat }
1498 }
1499
Harald Welte3453ab42019-05-24 21:19:58 +02001500 timer T := 5.0;
1501 T.start;
1502 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001503 [] 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 +02001504 setverdict(pass);
1505 repeat;
1506 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001507 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001508 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1509 repeat;
1510 }
1511 [] RSL_CCHAN.receive {
1512 repeat;
1513 }
1514 [] T.timeout { }
1515 }
1516
1517 f_vty_load_ind_thresh(10);
1518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1519}
1520
1521/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1522testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1523 var ASP_RSL_Unitdata rx_ud;
1524
1525 f_init_vty_bsc();
1526 f_init();
1527
1528 timer T := 5.0;
1529 T.start;
1530 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001531 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001532 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1533 repeat;
1534 }
1535 [] RSL_CCHAN.receive {
1536 repeat;
1537 }
1538 [] T.timeout {
1539 setverdict(pass);
1540 }
1541 }
1542
1543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1544}
1545
1546/* Expect 0 RACH load on an idle BTS that has just started up */
1547testcase TC_rach_load_count() runs on test_CT {
1548 var ASP_RSL_Unitdata rx_ud;
1549 var integer load_access_count := 0;
1550
1551 f_init_vty_bsc();
1552 /* send load indications even at 0% load */
1553 f_vty_load_ind_thresh(0);
1554 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1555 f_sleep(2.0);
1556 f_init();
1557
1558 f_init_l1ctl();
1559 f_sleep(1.0);
1560 f_l1_tune(L1CTL);
1561
Harald Welte52ae1682020-10-11 20:45:55 +02001562 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1563 alt {
1564 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1565 [] RSL_CCHAN.receive { repeat }
1566 }
1567
Harald Welte3453ab42019-05-24 21:19:58 +02001568 var GsmFrameNumber fn_last := 0;
1569 for (var integer i := 0; i < 1000; i := i+1) {
1570 var OCT1 ra := f_rnd_ra_cs();
1571 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1572 if (fn == fn_last) {
1573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1574 }
1575 fn_last := fn;
1576 }
1577
1578 timer T := 5.0;
1579 T.start;
1580 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001581 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001582 -> value rx_ud {
1583 var RSL_IE_Body ie;
1584 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1585 load_access_count := load_access_count + ie.rach_load.access_count;
1586 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1587 setverdict(fail, "Access count cannot be < Busy count");
1588 }
1589 repeat;
1590 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001591 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001592 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1593 repeat;
1594 }
1595 [] RSL_CCHAN.receive {
1596 repeat;
1597 }
1598 [] T.timeout { }
1599 }
1600 if (load_access_count == 1000) {
1601 setverdict(pass);
1602 } else {
1603 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1604 }
1605
1606 f_vty_load_ind_thresh(10);
1607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1608}
1609
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001611 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001612 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001613 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001614 f_sleep(0.5);
1615
1616 /* Transmit RACH request + wait for confirmation */
1617 var OCT1 ra := f_rnd_ra_cs();
1618 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1619
1620 /* Check for expected result */
1621 timer T := 1.5;
1622 T.start;
1623 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001625 setverdict(pass);
1626 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001627 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001629 }
1630 [] RSL_CCHAN.receive { repeat; }
1631 [not expect_pass] T.timeout {
1632 setverdict(pass);
1633 }
1634 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001636 }
1637 }
1638}
1639
1640/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1641testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001642 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001643 f_init_l1ctl();
1644 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001645 f_sleep(1.0);
1646
1647 /* default max-ta is 63 (full range of GSM timing advance */
1648
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001649 /* We allow early arrival up to 2 symbols */
1650 f_rach_toffs(-1*256, true);
1651 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001652 f_rach_toffs(-10*256, false);
1653
1654 /* 0 / 32 / 63 bits is legal / permitted */
1655 f_rach_toffs(0, true);
1656 f_rach_toffs(32*256, true);
1657 f_rach_toffs(63*256, true);
1658
1659 /* more than 63 bits is not legal / permitted */
1660 f_rach_toffs(64*256, false);
1661 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001663}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001664
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001665private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001666 var GsmFrameNumber fn;
1667 var RSL_Message rm;
1668
1669 f_l1_tune(L1CTL);
1670 RSL.clear;
1671
1672 /* Generate a random Handover Reference */
1673 var integer ho_ref := oct2int(f_rnd_octstring(1));
1674
1675 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1676 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1677 RSL_IE_Body:{ handover_ref := ho_ref }));
1678
1679 /* Activate a channel on the BTS side (no encryption) */
1680 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1681 act_type := t_RSL_IE_ActType_HO_SYNC);
1682
1683 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1684 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001685 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001686
1687 /* Send handover Access Burst */
1688 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1689
1690 /* TODO: test mismatching Handover Reference, and missing IE */
1691
1692 /* Wait for handover detection */
1693 timer T := 3.0;
1694 T.start;
1695 alt {
1696 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1697 log("Handover RACH has been detected: ", rm);
1698 setverdict(pass);
1699 }
1700 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1702 log2str("RSL_CHAN_RQD was not expected: ", rm));
1703 }
1704 [] RSL.receive { repeat; }
1705 [] T.timeout {
1706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1707 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1708 }
1709 }
1710
1711 /* Release the channel */
1712 f_rsl_chan_deact();
1713 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1714}
1715
1716/* Test handover RACH detection */
1717testcase TC_ho_rach() runs on test_CT {
1718 var ConnHdlrPars pars;
1719 var ConnHdlr vc_conn;
1720
1721 f_init();
1722
1723 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1724 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1725 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1726 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1727 vc_conn.done;
1728 }
1729
1730 /* TODO: do the above in parallel, rather than sequentially? */
1731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1732}
1733
Harald Welte93640c62018-02-25 16:59:33 +01001734/***********************************************************************
1735 * Measurement Processing / Reporting
1736 ***********************************************************************/
1737
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001738private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001739 spare := '0'B,
1740 lpd := 0,
1741 sapi := sapi,
1742 c_r := c_r,
1743 ea := true
1744}
1745
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001746private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001747 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001748 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001749 len := 0, /* overwritten */
1750 m := false,
1751 el := 1,
1752 payload := pl
1753}
1754
1755/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001756private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001757 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001758 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001759 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001760 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 +01001761 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001762 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001763
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001764 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1765 g_pars.l1_pars.ms_power_level, false,
1766 g_pars.l1_pars.ms_actual_ta);
1767
1768 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1769 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1770
1771 log("Sending Measurement Report: ", l1h, l2);
1772 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001773 repeat;
1774 }
1775}
1776
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001777private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001778 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001779 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001780 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1781 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001782 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1783 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001784 repeat;
1785 }
1786}
1787
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001788private altstep as_l1_tch_loop() runs on ConnHdlr {
1789 var L1ctlDlMessage l1_dl;
1790 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1791 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001792
1793 /* occasionaly inject FACCH frames into the uplink */
1794 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1795 var octetstring pl := '010301'O;
1796 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1797 f_pad_oct(pl, 23, '2B'O)));
1798 } else {
1799 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1800 l1_dl.payload.traffic_ind.data));
1801 }
1802
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001803 repeat;
1804 }
1805}
1806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001807private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001808 uint6_t rxlev,
1809 uint3_t rxqual
1810}
1811
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001812private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001813 MeasElem full,
1814 MeasElem sub
1815}
1816
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001817private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001818 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001819 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001820 MeasElemFS meas_ul,
1821 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001822 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001823 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001824 uint8_t ms_actual_ta,
1825 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001826}
1827
1828/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1829private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1830 return 63 + (toffs256s/256);
1831}
1832
Harald Welted5684392018-03-10 18:22:04 +01001833private function f_max(integer a, integer b) return integer {
1834 if (a > b) {
1835 return a;
1836 } else {
1837 return b;
1838 }
1839}
1840
1841private function f_min(integer a, integer b) return integer {
1842 if (a < b) {
1843 return a;
1844 } else {
1845 return b;
1846 }
1847}
1848
1849/* compute negative tolerance val-tolerance, ensure >= min */
1850private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1851 val := val - tolerance;
1852 return f_max(val, min);
1853}
1854
1855/* compute positive tolerance val+tolerance, ensure <= max */
1856private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1857 val := val + tolerance;
1858 return f_min(val, max);
1859}
1860
1861/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1862private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1863return template integer {
1864 var template integer ret;
1865 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1866 return ret;
1867}
1868
1869
Harald Welte70767382018-02-21 12:16:40 +01001870/* build a template for matching measurement results against */
1871private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1872 var ConnL1Pars l1p := g_pars.l1_pars;
1873 var template RSL_IE_UplinkMeas ul_meas := {
1874 len := 3,
1875 rfu := '0'B,
1876 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001877 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001878 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001879 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001880 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001881 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1882 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001883 supp_meas_info := omit
1884 };
Harald Welte685d5982018-02-27 20:42:05 +01001885 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001886 ul_meas.len := (3+8);
1887 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001888 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001889 toa256_min := ?,
1890 toa256_max := ?,
1891 toa256_std_dev := ?
1892 }
Harald Welte685d5982018-02-27 20:42:05 +01001893 }
Harald Welte70767382018-02-21 12:16:40 +01001894 var template RSL_IE_BS_Power bs_power := {
1895 reserved := 0,
1896 epc := false,
1897 fpc := false,
1898 power_level := l1p.bs_power_level
1899 };
1900 var template RSL_IE_L1Info l1_info := {
1901 ms_power_lvl := l1p.ms_power_level,
1902 fpc := false,
1903 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001904 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001905 };
1906 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001907 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001908 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1909 ?, t_toffs);
1910}
1911
Philipp Maierdd841d32019-12-17 14:44:54 +01001912/* build a template for matching measurement results that do not contain any
1913 * MS related measurement (l1_info, l3_info and ms timing offset). */
1914private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1915 var ConnL1Pars l1p := g_pars.l1_pars;
1916 var template RSL_IE_UplinkMeas ul_meas := {
1917 len := 3,
1918 rfu := '0'B,
1919 dtx_d := l1p.dtx_enabled,
1920 rxlev_f_u := ?,
1921 reserved1 := '00'B,
1922 rxlev_s_u := ?,
1923 reserved2 := '00'B,
1924 rxq_f_u := ?,
1925 rxq_s_u := ?,
1926 supp_meas_info := omit
1927 };
1928 if (l1p.toa256_enabled) {
1929 ul_meas.len := (3+8);
1930 ul_meas.supp_meas_info := {
1931 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1932 toa256_min := ?,
1933 toa256_max := ?,
1934 toa256_std_dev := ?
1935 }
1936 }
1937 var template RSL_IE_BS_Power bs_power := {
1938 reserved := 0,
1939 epc := false,
1940 fpc := false,
1941 power_level := l1p.bs_power_level
1942 };
1943
1944 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1945}
1946
Harald Welte70767382018-02-21 12:16:40 +01001947/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001948private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001949 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001950 var boolean chan_est := false;
1951
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001952 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001953
1954 /* Receive osmocom specific measurement reports. This is the normal
1955 * case. Here we verify that the measurement reports we sent are
1956 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001957 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1958 /* increment counter of next to-be-expected meas rep */
1959 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1960 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001961 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001962
1963 /* The following two cases may only happen in the beginning
1964 * of the channel establishment phase. Once we have received
1965 * the "our" measurement report the first time, the channel
1966 * is established and empty or hardcoded TRXCON reports must
1967 * not occur anymore. */
1968 chan_est := true;
1969
1970 repeat;
1971 }
1972
1973 /* When the BTS has established the channel, the MS might need slightly
1974 * more time to establish the channel and actually start sending. The
1975 * result is then a measurement report that just lacks the measurement
1976 * information of the MS. This is normal and we tolerate this behavior. */
1977 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1978 /* increment counter of next to-be-expected meas rep */
1979 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1980 /* Re-start the timer expecting the next MEAS RES */
1981 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001982 repeat;
1983 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001984
1985 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1986 * measurements if the TTCN3 side does not supply measurement input in
1987 * time. In those cases TRXCON will either use a cached measurement
1988 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1989 * report the templates above will not match. We tolerate this
1990 * behavior, but only once. */
1991 [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 +01001992 /* increment counter of next to-be-expected meas rep */
1993 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1994 if (g_first_meas_res) {
1995 g_first_meas_res := false;
1996 repeat;
1997 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001999 }
Harald Welte70767382018-02-21 12:16:40 +01002000 }
2001 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002003 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002004 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002006 }
2007}
2008
Harald Weltee613f962018-04-18 22:38:16 +02002009private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2010 select (rsl_alg_id) {
2011 case (RSL_ALG_ID_A5_0) { return 0; }
2012 case (RSL_ALG_ID_A5_1) { return 1; }
2013 case (RSL_ALG_ID_A5_2) { return 2; }
2014 case (RSL_ALG_ID_A5_3) { return 3; }
2015 case (RSL_ALG_ID_A5_4) { return 4; }
2016 case (RSL_ALG_ID_A5_5) { return 5; }
2017 case (RSL_ALG_ID_A5_6) { return 6; }
2018 case (RSL_ALG_ID_A5_7) { return 7; }
2019 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2021 /* Make compiler happy by calling mtc.stop here. It is already
2022 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002023 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002024 }
2025 }
2026}
2027
2028private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2029 select (rsl_alg_id) {
2030 case (RSL_ALG_ID_A5_1) { return '000'B; }
2031 case (RSL_ALG_ID_A5_2) { return '001'B; }
2032 case (RSL_ALG_ID_A5_3) { return '010'B; }
2033 case (RSL_ALG_ID_A5_4) { return '011'B; }
2034 case (RSL_ALG_ID_A5_5) { return '100'B; }
2035 case (RSL_ALG_ID_A5_6) { return '101'B; }
2036 case (RSL_ALG_ID_A5_7) { return '110'B; }
2037 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2039 /* Make compiler happy by calling mtc.stop here. It is already
2040 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002041 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002042 }
2043 }
2044}
2045
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002046/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2047private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2048 var GsmFrameNumber fn;
2049 timer T := 8.0;
2050
2051 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2052 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2053
2054 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2055 /* Send the actual RACH */
2056 fn := f_L1CTL_RACH(L1CTL, ra);
2057
2058 T.start;
2059 alt {
2060 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2061 [] T.timeout {
2062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2063 }
2064 }
2065 T.stop
2066 return fn;
2067}
Harald Weltee613f962018-04-18 22:38:16 +02002068
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002069/* Tune to a dedicated channel: L1CTL only */
2070private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002071 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002072 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2073 7 /* TODO: mp_tsc */,
2074 mp_trx0_arfcn));
2075 } else {
2076 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2077 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002078 pars.fhp.maio_hsn.hsn,
2079 pars.fhp.maio_hsn.maio,
2080 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002081 }
2082}
2083
Harald Welte70767382018-02-21 12:16:40 +01002084/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002085private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002086 var GsmFrameNumber fn;
2087 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002088 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002089 var integer ra := 23;
2090
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002091 /* Send RACH request and wait for ChanReq */
2092 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002093
2094 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002095 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002096
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002097 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002098 if (g_pars.fhp.enabled) {
2099 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002100 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002101 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002102 }
2103
Harald Welte70767382018-02-21 12:16:40 +01002104 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002105 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 +01002106 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2107
2108 /* receive IMM.ASS on MS side */
2109 var ImmediateAssignment ia_um;
2110 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002111
2112 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2113 if (ch_desc.h != ia_um.chan_desc.h) {
2114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2115 }
2116
Harald Welte70767382018-02-21 12:16:40 +01002117 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002118 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002119 /* enable encryption, if requested */
2120 if (encr_enable) {
2121 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2122 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2123 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002124
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002125 /* Send TCH Mode Request to the L1 if needed */
2126 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2127 var L1ctlTchMode tch_mode;
2128
2129 select (g_pars.chan_mode.coding_alg_rate) {
2130 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2131 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2132 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2133 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2134 case else {
2135 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2136 " is not supported by the L1, falling back to signalling");
2137 tch_mode := L1CTL_CHAN_MODE_SIGN;
2138 }
2139 }
2140
2141 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2142 }
2143
Harald Weltefa45e9e2018-03-10 18:59:03 +01002144 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002145}
2146
2147/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002148private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002149 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002150 RSL.clear;
2151
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002152 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002153 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002154 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002155 }
Harald Welte70767382018-02-21 12:16:40 +01002156
2157 f_est_dchan();
2158
2159 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2160 * RSL measurement reports on Abis side */
2161 timer T := 8.0;
2162 T.start;
2163 alt {
2164 [] as_l1_sacch();
2165 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002166 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002167 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002168 [] L1CTL.receive { repeat; }
2169 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002170 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002171 * of any earlier errors, so if we reach this timeout, we're good */
2172 setverdict(pass);
2173 }
2174 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002176 }
2177 }
2178 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002179 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002180}
Harald Welte0472ab42018-03-12 15:02:26 +01002181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002182/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2183private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002184 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002185 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2186 timer Tup := 10.0;
2187 Tup.start;
2188 alt {
2189 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2190 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2191 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002192
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002193 if (rx_lvl != max_rx_lvl) {
2194 repeat;
2195 }
2196 Tup.stop;
2197 }
2198 [] L1CTL.receive { repeat; }
2199 [] Tup.timeout {
2200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2201 log2str("Didn't reach full power ", max_rx_lvl));
2202 }
2203 }
2204 return max_rx_lvl;
2205}
2206
2207/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2208private function f_verify_ramp_up() runs on ConnHdlr {
2209 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002210 var integer initial_rx_lvl := -1;
2211 var integer last_rx_lvl := -1;
2212 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2213
2214 timer T := 2.0;
2215 alt {
2216 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2217 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2218 log("Received rx_level=", rx_lvl);
2219 if (initial_rx_lvl == -1) {
2220 initial_rx_lvl := rx_lvl;
2221 last_rx_lvl := rx_lvl;
2222
2223 /* Expect a somehow low value during first received messages */
2224 if (initial_rx_lvl >= max_rx_lvl / 2) {
2225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2226 log2str("Detected high initial tx power during ramp up: ",
2227 initial_rx_lvl , ", full power is", max_rx_lvl));
2228 }
2229 }
2230
2231 /* received Rx level bigger than maximum allowed power by CN */
2232 if (rx_lvl > max_rx_lvl) {
2233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2234 log2str("Detected Tx power higher than full power: ",
2235 rx_lvl , " > ", max_rx_lvl));
2236 }
2237
2238 /* Make sure it never decreases, since we are rumping up */
2239 if (last_rx_lvl > rx_lvl) {
2240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2241 log2str("Detected Tx power decrease during ramp up: ",
2242 last_rx_lvl , " -> ", rx_lvl));
2243 }
2244
2245 if (rx_lvl == max_rx_lvl and not T.running) {
2246 /* We reached the maximum power, start timer and receive
2247 /* a few more to make sure we don't surpass it */
2248 log("Reached full power, wating a bit more until success");
2249 T.start;
2250 }
2251
2252 last_rx_lvl := rx_lvl;
2253 repeat;
2254 }
2255 [] L1CTL.receive { repeat; }
2256 [] T.timeout { }
2257 }
2258
2259 /* We didn't increase tx power during ramp up */
2260 if (initial_rx_lvl < last_rx_lvl) {
2261 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2262 } else {
2263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2264 log2str("No Tx power increase during whole ramp up: ",
2265 initial_rx_lvl , " -> ", last_rx_lvl));
2266 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002267}
2268
2269/* verify BTS ramps power down to rx_level 0 */
2270private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2271 var L1ctlDlMessage l1_dl;
2272 var integer last_rx_lvl := max_rx_lvl;
2273
2274 timer Tdown := 5.0;
2275 Tdown.start;
2276 alt {
2277 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2278 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2279 log("Received rx_level=", rx_lvl);
2280
2281 /* received Rx level bigger than maximum allowed power by CN */
2282 if (rx_lvl > max_rx_lvl) {
2283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2284 log2str("Detected Tx power higher than full power: ",
2285 rx_lvl , " > ", max_rx_lvl));
2286 }
2287
2288 /* Make sure it never increases, since we are rumping down */
2289 if (last_rx_lvl < rx_lvl) {
2290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2291 log2str("Detected Tx power increase during ramp up: ",
2292 last_rx_lvl , " -> ", rx_lvl));
2293 }
2294
2295 last_rx_lvl := rx_lvl;
2296 if (last_rx_lvl != 0) {
2297 repeat;
2298 }
2299 /* we reached power level 0, we are done */
2300 Tdown.stop;
2301 }
2302 [] L1CTL.receive { repeat; }
2303 [] Tdown.timeout { }
2304 }
2305
2306 /* We didn't increase tx power during ramp down */
2307 if (max_rx_lvl > last_rx_lvl) {
2308 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2309 } else {
2310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2311 log2str("No Tx power decrease during whole ramp down: ",
2312 max_rx_lvl , " -> ", last_rx_lvl));
2313 }
2314}
2315
2316/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002317private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002318 f_l1_tune(L1CTL);
2319 RSL.clear;
2320
2321 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002322
2323 setverdict(pass);
2324}
2325testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2326 var ConnHdlr vc_conn;
2327 var ConnHdlrPars pars;
2328 f_init();
2329 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2330 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2331 pcu_comp := false, trxc_comp := true);
2332 vc_conn.done;
2333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2334}
2335
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002336/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002337private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002338 f_connhdlr_init_vty_bsc();
2339
2340 f_l1_tune(L1CTL);
2341 RSL.clear;
2342
2343 /* Wait until BTS is started and at full power */
2344 var integer max_rx_lvl := f_wait_ramp_up();
2345 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2346
2347 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2348 f_verify_ramp_down(max_rx_lvl);
2349
2350 setverdict(pass);
2351}
2352testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2353 var ConnHdlr vc_conn;
2354 var ConnHdlrPars pars;
2355 f_init();
2356 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2357 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2358 pcu_comp := false, trxc_comp := true);
2359 vc_conn.done;
2360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2361}
2362
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002363/* Verify Tx power:
2364 * + ramping down during ADM state UNLOCKED->LOCKED
2365 * + ramping up during ADM state LOCKED->UNLOCKED
2366 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002367private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002368 var L1ctlDlMessage l1_dl;
2369 var integer last_rx_lvl;
2370
2371 f_connhdlr_init_vty_bsc();
2372
2373 f_l1_tune(L1CTL);
2374 RSL.clear;
2375
2376 /* Wait until BTS is started and at full power */
2377 var integer max_rx_lvl := f_wait_ramp_up();
2378 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2379
2380 log("ADM STATE UNLOCKED->LOCKED");
2381 f_vty_enter_cfg_trx(BSCVTY);
2382 f_vty_transceive(BSCVTY, "rf_locked 1");
2383 last_rx_lvl := max_rx_lvl;
2384 f_verify_ramp_down(max_rx_lvl);
2385
2386 /* Let some time after we received 0dBm, then check we don't receive BCCH
2387 * anymore because scheduler has stopped after ramping down */
2388 f_sleep(2.0);
2389 L1CTL.clear;
2390 timer Tlocked := 2.0;
2391 Tlocked.start;
2392 alt {
2393 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2395 log2str("Received data_ind during rf_locked: ", l1_dl));
2396 }
2397 [] L1CTL.receive { repeat; }
2398 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2399 }
2400
2401 log("ADM STATE LOCKED->UNLOCKED");
2402 f_vty_transceive(BSCVTY, "rf_locked 0");
2403 f_verify_ramp_up();
2404 setverdict(pass);
2405}
2406testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2407 var ConnHdlr vc_conn;
2408 var ConnHdlrPars pars;
2409 f_init();
2410 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2411 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2412 pcu_comp := false, trxc_comp := true);
2413 vc_conn.done;
2414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2415}
2416
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002417private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002418 timer T := 8.0;
2419 T.start;
2420 var RSL_Message rsl;
2421 alt {
2422 [] as_l1_sacch();
2423 [] L1CTL.receive { repeat; }
2424 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2425 if (rsl.ies[3].body.bs_power.power_level == level) {
2426 setverdict(pass)
2427 } else {
2428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2429 }
2430 }
2431 [] T.timeout {
2432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2433 }
2434 }
2435}
2436
2437/* see if the rsl meas res contains our expeced bs power level
2438bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002439private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002440 f_l1_tune(L1CTL);
2441 RSL.clear;
2442
2443 if (mp_bts_trxc_port != -1) {
2444 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2445 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2446 }
2447
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002448 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002449 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2450 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2451
2452 f_est_dchan(more_ies :={valueof(pwr)});
2453
2454 f_check_meas_bs_power_level(pwr_var);
2455
2456 f_rsl_chan_deact();
2457 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2458}
2459
2460/* see if the rsl meas res contains our expeced bs power level
2461bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002462private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002463 f_l1_tune(L1CTL);
2464 RSL.clear;
2465
2466 if (mp_bts_trxc_port != -1) {
2467 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2468 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2469 }
2470
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002471 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002472 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2473
2474 f_est_dchan();
2475
2476 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2477
2478 f_check_meas_bs_power_level(pwr_var);
2479
2480 f_rsl_chan_deact();
2481 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2482}
2483
2484testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2485 var ConnHdlr vc_conn;
2486 var ConnHdlrPars pars;
2487 f_init();
2488 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2489 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2490 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2491 pcu_comp := false, trxc_comp := true);
2492 vc_conn.done;
2493 }
2494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2495}
2496
2497testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2498 var ConnHdlr vc_conn;
2499 var ConnHdlrPars pars;
2500 f_init();
2501 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2502 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2503 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2504 pcu_comp := false, trxc_comp := true);
2505 vc_conn.done;
2506 }
2507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2508}
2509
Eric Wild61edb7e2019-06-03 12:38:31 +02002510/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2511second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2512These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002513private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002514 var uint5_t pwr_var := 7;
2515 var L1ctlDlMessage l1_dl;
2516
2517 f_trxc_fake_rssi(rxlev2dbm(10));
2518 f_l1_tune(L1CTL);
2519 RSL.clear;
2520
2521 var RSL_IE_List addl_ies;
2522 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2523
2524 addl_ies := {
2525 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2526 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2527 };
2528
2529 /* establish with power parameters */
2530 f_est_dchan(more_ies := addl_ies);
2531
2532 /* set a high value to ensure L1 power control level increases */
2533 f_trxc_fake_rssi(rxlev2dbm(20));
2534
2535 timer T2 := 6.0;
2536 T2.start;
2537 alt {
2538 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002539 /* Update sent MS power to follow what BTS requests */
2540 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2541 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002542 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002543 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002544 T2.stop;
2545 }
2546 [] L1CTL.receive { repeat; }
2547 [] T2.timeout {
2548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2549 "Power Level in L1 header has not increased sufficiently");
2550 }
2551 }
2552
2553 /* set a low value to ensure L1 power control level decreases */
2554 f_trxc_fake_rssi(rxlev2dbm(0));
2555
2556 timer T4 := 6.0;
2557 T4.start;
2558 alt {
2559 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002560 /* Update sent MS power to follow what BTS requests */
2561 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2562 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002564 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002565 T4.stop;
2566 setverdict(pass, "Power level in L1 decreased/increased as expected");
2567 }
2568 [] L1CTL.receive { repeat; }
2569 [] T4.timeout {
2570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2571 "Power Level in L1 header has not decreased sufficiently");
2572 }
2573 }
2574
2575 f_rsl_chan_deact();
2576 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2577
2578}
2579
2580/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002581private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002582 var uint5_t pwr_var := 7;
2583 var L1ctlDlMessage l1_dl;
2584
2585 /* set a low value to ensure power increases */
2586 f_trxc_fake_rssi(rxlev2dbm(10));
2587 f_l1_tune(L1CTL);
2588 RSL.clear;
2589
2590 var RSL_IE_List addl_ies;
2591 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2592
2593 addl_ies := {
2594 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2595 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2596 };
2597
2598 /* establish with power parameters */
2599 f_est_dchan(more_ies := addl_ies);
2600
2601 timer T1 := 10.0;
2602 T1.start;
2603 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002604 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2605 /* Update sent MS power to follow what BTS requests */
2606 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2607 repeat;
2608 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002609 [] L1CTL.receive { repeat; }
2610 [] T1.timeout {
2611 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2612 setverdict(fail, "Power level in L1 header should not have changed");
2613 }
2614 }
2615 }
2616
2617 f_rsl_chan_deact();
2618 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2619
2620}
2621
2622/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002623private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002624 var L1ctlDlMessage l1_dl;
2625 var uint5_t pwr_var := 15;
2626 var uint5_t pwr_max_var := f_get_max_power_from_band();
2627
2628 /* set a low value to ensure power increases */
2629 f_trxc_fake_rssi(rxlev2dbm(10));
2630 f_l1_tune(L1CTL);
2631 RSL.clear;
2632
2633 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2634 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2635
2636 /* establish with fixed power level */
2637 f_est_dchan(more_ies :={valueof(pwr)});
2638
2639 /* check our initial power level */
2640 f_wait_for_l1_power_level(pwr_var);
2641
2642 /* update power param to enable power loop
2643 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2644 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2645
2646 /* wait, then check that our power level was reduced */
2647 timer T1 := 10.0;
2648 T1.start;
2649 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002650 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2651 /* Update sent MS power to follow what BTS requests */
2652 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2653 repeat;
2654 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002655 [] L1CTL.receive { repeat; }
2656 [] T1.timeout {
2657 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2658 if( f_power_level_is_highest_dbm(rcv) ){
2659 setverdict(pass, "Power level in L1 header reduced as expected");
2660 } else {
2661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2662 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2663 }
2664 }
2665 }
2666
2667 f_rsl_chan_deact();
2668 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2669
2670}
2671
2672/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002673private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002674 var L1ctlDlMessage l1_dl;
2675
2676 /* set a high value to ensure power decreases */
2677 f_trxc_fake_rssi(rxlev2dbm(50));
2678 f_l1_tune(L1CTL);
2679 RSL.clear;
2680
2681 var uint5_t pwr_var := 5;
2682 var uint5_t pwr_target_val := 15;
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 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002695 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002696
2697 /* wait, then check that our power level was increased */
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 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2709 setverdict(pass, "Power level in L1 header increased to lowest power value");
2710 } else {
2711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2712 "Power level in L1 header NOT increased to lowest power value");
2713 }
2714 }
2715 }
2716
2717 f_rsl_chan_deact();
2718 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2719
2720}
2721
Eric Wild095024b2019-06-17 15:08:57 +02002722/* see if we change the power level without receiving power parameters, which should not happen
2723rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002724private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +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
2734 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2735 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2736
2737 /* establish with fixed power level */
2738 f_est_dchan(more_ies :={valueof(pwr)});
2739
2740 /* check our initial power level */
2741 f_wait_for_l1_power_level(pwr_var);
2742
2743 /* wait, then check that our power level did not change */
2744 timer T1 := 10.0;
2745 T1.start;
2746 alt {
2747 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2748 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2750 "BS power control should not be active unless we receive a power parameters IE!");
2751 }
2752 repeat;
2753 }
2754 [] L1CTL.receive { repeat; }
2755 [] T1.timeout { setverdict(pass); }
2756 }
2757
2758 f_rsl_chan_deact();
2759 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2760
2761}
2762
Eric Wild095024b2019-06-17 15:08:57 +02002763/* see if we change the power level without receiving power parameters, which should not happen
2764ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002765private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002766 var L1ctlDlMessage l1_dl;
2767
2768 /* set a high value to ensure power decreases */
2769 f_trxc_fake_rssi(rxlev2dbm(50));
2770 f_l1_tune(L1CTL);
2771 RSL.clear;
2772
2773 var uint5_t pwr_var := 5;
2774
2775 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2776 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2777
2778 /* establish with fixed power level */
2779 f_est_dchan(more_ies :={valueof(pwr)});
2780
2781 /* check our initial power level */
2782 f_wait_for_l1_power_level(pwr_var);
2783
2784 /* pwr control without power params IE, should NOT activate MS power control*/
2785 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2786
2787 /* wait, then check that our power level did not change */
2788 timer T1 := 10.0;
2789 T1.start;
2790 alt {
2791 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2792 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2794 "BS power control should not be active unless we receive a power parameters IE!");
2795 }
2796 repeat;
2797 }
2798 [] L1CTL.receive { repeat; }
2799 [] T1.timeout { setverdict(pass); }
2800 }
2801
2802 f_rsl_chan_deact();
2803 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2804
2805}
2806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002807private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002808 var L1ctlDlMessage l1_dl;
2809 timer T0 := 10.0;
2810 T0.start;
2811 alt {
2812 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2813 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2815 "Power level in L1 header != signaled (RSL) power level.");
2816 }
2817 }
2818 [] L1CTL.receive { repeat; }
2819 [] T0.timeout {
2820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2821 "Timeout waiting for initial power level");
2822 }
2823 }
2824 T0.stop;
2825}
2826
2827private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2828 var IntegerRecord min_dbm_level;
2829 var IntegerRecord max_dbm_level;
2830 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2831
2832 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2833 if (min_dbm_level[i] == level) {
2834 return true;
2835 }
2836 }
2837 return false;
2838}
2839
2840private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2841 var IntegerRecord min_dbm_level;
2842 var IntegerRecord max_dbm_level;
2843 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2844
2845 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2846 if (max_dbm_level[i] == level) {
2847 return true;
2848 }
2849 }
2850 return false;
2851}
2852
2853private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2854 var IntegerRecord min_dbm_level;
2855 var IntegerRecord max_dbm_level;
2856 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2857 return max_dbm_level[0];
2858}
2859
2860type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002861private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002862private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2863 // 45.005 4.1.1
2864 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2865 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2866 2, 1, 0};
2867 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2868 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2869 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2870 var IntegerRecord rv;
2871
2872 select(band){
2873 case (BtsBand_allGSM){
2874 rv := gsm_power;
2875 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2876 max_dbm_level := {2, 1, 0};
2877 }
2878 case("DCS1800"){
2879 rv := dcs_power;
2880 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2881 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2882 }
2883 case("PCS1900"){
2884 rv := pcs_power;
2885 min_dbm_level := {15};
2886 max_dbm_level := {30};
2887 }
Harald Welte194b6912020-10-11 21:01:55 +02002888 case else {
2889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2890 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002891 }
2892
2893 return rv;
2894}
2895
2896private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002897 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 +02002898}
2899
2900testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2901 var ConnHdlr vc_conn;
2902 var ConnHdlrPars pars;
2903 f_init();
2904 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2905 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2906 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2907 pars.bts0_band := f_vty_get_bts0_band();
2908 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2909 vc_conn.done;
2910 }
2911 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2913}
2914
2915testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2916 var ConnHdlr vc_conn;
2917 var ConnHdlrPars pars;
2918 f_init();
2919 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2920 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2921 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2922 pars.bts0_band := f_vty_get_bts0_band();
2923 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2924 vc_conn.done;
2925 }
2926 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2928}
2929
2930testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2931 var ConnHdlr vc_conn;
2932 var ConnHdlrPars pars;
2933 f_init();
2934 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2935 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2936 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2937 pars.bts0_band := f_vty_get_bts0_band();
2938 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2939 vc_conn.done;
2940 }
2941 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2943}
2944
2945testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2946 var ConnHdlr vc_conn;
2947 var ConnHdlrPars pars;
2948 f_init();
2949 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2950 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2951 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2952 pars.bts0_band := f_vty_get_bts0_band();
2953 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2954 vc_conn.done;
2955 }
2956 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2958}
2959
Eric Wild280ccb82019-06-17 11:11:52 +02002960testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2961 var ConnHdlr vc_conn;
2962 var ConnHdlrPars pars;
2963 f_init();
2964 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2965 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2966 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2967 pars.bts0_band := f_vty_get_bts0_band();
2968 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2969 vc_conn.done;
2970 }
2971 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2973}
2974
Eric Wild095024b2019-06-17 15:08:57 +02002975testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2976 var ConnHdlr vc_conn;
2977 var ConnHdlrPars pars;
2978 f_init();
2979 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2980 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2981 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2982 pars.bts0_band := f_vty_get_bts0_band();
2983 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2984 vc_conn.done;
2985 }
2986 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2988}
2989
Philipp Maier149c3922020-10-22 17:29:36 +02002990function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07002991 var template RSL_IE_ChannelMode ch_mode;
2992 var ConnHdlr vc_conn;
2993 var ConnHdlrPars pars;
2994 f_init();
2995 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
2996 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
2997 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02002998 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07002999 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3000 pcu_comp := false, trxc_comp := true);
3001 vc_conn.done;
3002 }
3003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3004}
Philipp Maier149c3922020-10-22 17:29:36 +02003005
3006testcase TC_meas_res_speech_tchf() runs on test_CT {
3007 f_TC_meas_res_speech_tchf(false);
3008}
3009
3010testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3011 f_TC_meas_res_speech_tchf(true);
3012}
3013
3014function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003015 var template RSL_IE_ChannelMode ch_mode;
3016 var ConnHdlr vc_conn;
3017 var ConnHdlrPars pars;
3018 f_init();
3019 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3020 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3021 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003022 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003023 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3024 pcu_comp := false, trxc_comp := true);
3025 vc_conn.done;
3026 }
3027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3028}
Philipp Maier149c3922020-10-22 17:29:36 +02003029
3030testcase TC_meas_res_speech_tchh() runs on test_CT {
3031 f_TC_meas_res_speech_tchh(false)
3032}
3033
3034testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3035 f_TC_meas_res_speech_tchh(true)
3036}
3037
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003038testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3039 var template RSL_IE_ChannelMode ch_mode;
3040 var ConnHdlr vc_conn;
3041 var ConnHdlrPars pars;
3042 f_init();
3043 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3044 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3045 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3046 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3047 pars.l1_pars.toa256_enabled := true;
3048 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3049 pcu_comp := false, trxc_comp := true);
3050 vc_conn.done;
3051 }
3052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3053}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003054
Harald Welte70767382018-02-21 12:16:40 +01003055testcase TC_meas_res_sign_tchf() runs on test_CT {
3056 var ConnHdlr vc_conn;
3057 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003058 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003059 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003060 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003061 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3062 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003063 vc_conn.done;
3064 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003066}
3067testcase TC_meas_res_sign_tchh() runs on test_CT {
3068 var ConnHdlr vc_conn;
3069 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003070 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003071 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003072 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003073 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3074 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003075 vc_conn.done;
3076 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003078}
3079testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3080 var ConnHdlr vc_conn;
3081 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003082 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003083 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3084 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003085 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3086 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003087 vc_conn.done;
3088 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003090}
3091testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3092 var ConnHdlr vc_conn;
3093 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003094 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003095 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3096 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003097 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3098 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003099 vc_conn.done;
3100 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003102}
Harald Welte685d5982018-02-27 20:42:05 +01003103testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3104 var ConnHdlr vc_conn;
3105 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003106 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003107 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3108 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003109 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003110 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003111 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3112 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003113 vc_conn.done;
3114 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003116}
3117
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003118/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3119 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003120private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003121 var L1ctlDlMessage l1_dl;
3122 var RSL_IE_MS_Power ms_power;
3123 var RSL_Message rsl;
3124 var uint5_t power_level := 0;
3125
3126 f_l1_tune(L1CTL);
3127 RSL.clear;
3128
3129 f_est_dchan();
3130
3131 ms_power.reserved := 0;
3132 ms_power.fpc_epc := false;
3133
3134 /* Send the first power control command. This will disable any BTS/TRX
3135 * internal power control and switch the MS (which is not in scope of
3136 * this test) to a constant power level. We start with a power level
3137 * of 0 */
3138 ms_power.power_level := power_level;
3139 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3140 RSL.send(rsl);
3141
3142 alt {
3143
3144 /* Pick all SACCH blocks for checking */
3145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3146
3147 /* The first byte of the L1 header contains the power level.
3148 * The reserved bits and the fpc bit is set to 0, so we may
3149 * compare directly. */
3150 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3151 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3152 }
3153
3154 /* Signal a new power level via RSL for the next turn. */
3155 if (power_level < 31) {
3156 power_level := power_level + 1;
3157 ms_power.power_level := power_level;
3158 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3159 RSL.send(rsl);
3160 repeat;
3161 }
3162
3163 }
3164
3165 /* Ignore all other blocks */
3166 [] L1CTL.receive { repeat; }
3167
3168 }
3169
3170 f_rsl_chan_deact();
3171 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3172
3173 setverdict(pass);
3174}
3175
3176testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3177 var ConnHdlr vc_conn;
3178 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003179 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003180
3181 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3182 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3183 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3184 vc_conn.done;
3185 }
3186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3187}
Harald Welte70767382018-02-21 12:16:40 +01003188
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003189/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003190TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003191private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003192 var L1ctlDlMessage l1_dl;
3193 var uint5_t ta_to_test := 16;
3194
3195
3196 f_l1_tune(L1CTL);
3197 RSL.clear;
3198
3199 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003200 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003201
3202 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3203
3204
3205 alt {
3206
3207 /* Pick all SACCH blocks for checking */
3208 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3209
3210 /* The second byte of the L1 header contains the TA. */
3211 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3212 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3213 }
3214
3215 }
3216
3217 /* Ignore all other blocks */
3218 [] L1CTL.receive { repeat; }
3219
3220 }
3221
3222 f_rsl_chan_deact();
3223 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3224
3225 setverdict(pass);
3226}
3227
3228testcase TC_rsl_chan_initial_ta() runs on test_CT {
3229 var ConnHdlr vc_conn;
3230 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003231 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003232 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003233 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3234 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003235 vc_conn.done;
3236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3237}
3238
Eric Wilde57e1a62019-05-28 13:30:55 +02003239/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003240private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003241 var L1ctlDlMessage l1_dl;
3242 var uint5_t ms_power_level := 7;
3243
3244 var RSL_IE_MS_Power ms_power;
3245 ms_power.reserved := 0;
3246 ms_power.fpc_epc := false;
3247 ms_power.power_level := ms_power_level;
3248
3249 f_l1_tune(L1CTL);
3250 RSL.clear;
3251
3252 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3253
3254 timer T := 1.0;
3255 T.start;
3256 alt {
3257 /* Pick all SACCH blocks for checking */
3258 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3259 /* The first byte of the L1 header contains the power level.. */
3260 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3261 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3262 }
3263 }
3264 /* Ignore all other blocks */
3265 [] L1CTL.receive { repeat; }
3266 [] T.timeout {
3267 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3268 }
3269 }
3270
3271 f_rsl_chan_deact();
3272 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3273 setverdict(pass);
3274}
3275
3276testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3278 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3279}
3280
Harald Welte0472ab42018-03-12 15:02:26 +01003281/* 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 +01003282private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003283 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003284 RSL.clear;
3285
3286 f_est_dchan();
3287 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003288 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003289
3290 timer T := 40.0;
3291 T.start;
3292 alt {
3293 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3294 setverdict(pass)
3295 }
3296 [] RSL.receive { repeat };
3297 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003299 }
3300 }
3301 f_rsl_chan_deact();
3302}
3303testcase TC_conn_fail_crit() runs on test_CT {
3304 var ConnHdlr vc_conn;
3305 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003306 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003307 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3308 pars.t_guard := 60.0;
3309 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3310 vc_conn.done;
3311}
3312
Harald Welte93640c62018-02-25 16:59:33 +01003313/***********************************************************************
3314 * Paging
3315 ***********************************************************************/
3316
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003317private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003318 if (tmsi == 'FFFFFFFF'O) {
3319 return true;
3320 } else {
3321 return false;
3322 }
3323}
Harald Welte70767382018-02-21 12:16:40 +01003324
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003325private type record allowedFn { integer frame_nr }
3326private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3327private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3328private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3329private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3330private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3331private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3332private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3333private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3334private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003335{
3336 var integer frame_nr_51;
3337 frame_nr_51 := frame_nr mod 51
3338
3339 var allowedFn fn_check;
3340 fn_check.frame_nr := frame_nr_51;
3341
3342 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003344 return;
3345 }
3346
3347 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3348 return;
3349 }
3350 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3351 return;
3352 }
3353 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3354 return;
3355 }
3356 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3357 return;
3358 }
3359 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3360 return;
3361 }
3362 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3363 return;
3364 }
3365 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3366 return;
3367 }
3368 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3369 return;
3370 }
3371
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003373 return;
3374}
3375
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003376private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3377 inout integer num_paging_rcv_ids,
3378 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003379runs on test_CT {
3380 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003381 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003382 repeat;
3383 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003384 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003385 var octetstring without_plen :=
3386 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3387 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003388
3389 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3390
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003391 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3392 /* Ignore empty RR Paging Request (PCH filling) messages.
3393 * TODO: does it make sense to count them? */
3394 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003395 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3396 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003397 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003398 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3399 }
3400 } else if (match(rr, tr_PAGING_REQ2)) {
3401 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3402 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3403 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3404 }
3405 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3406 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3407 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003408 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003409 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3410 }
3411 } else if (match(rr, tr_PAGING_REQ3)) {
3412 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3413 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3414 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3415 }
3416 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3417 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3418 }
3419 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3420 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3421 }
3422 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3423 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3424 }
3425 }
3426 repeat;
3427 }
3428}
3429
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003430private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003431 boolean combined_ccch,
3432 integer bs_ag_blks_res,
3433 float load_factor,
3434 boolean exp_load_ind,
3435 boolean exp_overload,
3436 boolean use_tmsi
3437}
3438
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003439private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003440 integer num_paging_sent,
3441 integer num_paging_rcv_msgs,
3442 integer num_paging_rcv_ids,
3443 integer num_overload
3444}
3445
Harald Welte68e495b2018-02-25 00:05:57 +01003446/* Helper function for paging related testing */
3447private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003448 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003449 f_init_l1ctl();
3450 f_l1_tune(L1CTL);
3451
3452 var PagingTestState st := {
3453 num_paging_sent := 0,
3454 num_paging_rcv_msgs := 0,
3455 num_paging_rcv_ids := 0,
3456 num_overload := 0
3457 };
3458
3459 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3460 var float max_pch_imsi_per_sec;
3461 if (cfg.use_tmsi) {
3462 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3463 } else {
3464 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3465 }
3466 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3467 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003468 var float time_total := 20.0;
3469 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3470 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003471
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003472 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3473 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003474
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003475 timer T_itv := 0.0;
3476 T_itv.start;
3477 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003478 alt {
3479 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003480 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003481 st.num_overload := st.num_overload + 1;
3482 repeat;
3483 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003484 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003486 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003487 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003488 log("Rx LOAD_IND");
3489 /* FIXME: analyze/verify interval + contents */
3490 repeat;
3491 }
3492 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003493 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003494 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003495 [] T_itv.timeout {
3496 /* Send paging cmds based on elapsed time */
3497 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3498 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003499 var MobileIdentityV mi;
3500
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003501 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003502 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003503 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003504 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003505 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003506 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003507
3508 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003509 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 +02003510
3511 st.num_paging_sent := st.num_paging_sent + 1;
3512 }
3513 if (st.num_paging_sent < pkt_total) {
3514 /* Wait for interval to next PAGING COMMAND */
3515 var float time_now := T_total.read;
3516 var float next_sched := int2float(st.num_paging_sent)*interval;
3517 if (next_sched > time_now) {
3518 T_itv.start(next_sched - time_now);
3519 } else {
3520 T_itv.start(0.0);
3521 }
3522 } else {
3523 /* We are done, no need to keep counting */
3524 T_total.stop;
3525 }
3526 }
3527 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003528 }
3529 }
3530
3531 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3532 timer T_wait := 18.0;
3533 T_wait.start;
3534 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003535 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003536 [] L1CTL.receive { repeat; }
3537 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003538 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3539 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003540 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003542 }
Harald Welte68e495b2018-02-25 00:05:57 +01003543 }
3544
3545 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3546 " rcvd_ids=", st.num_paging_rcv_ids);
3547 return st;
3548}
3549
3550/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3551 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3552 * - that CCCH LOAD IND (PCH) are being generated
3553 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3554testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003555 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003556 var PagingTestCfg cfg := {
3557 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003558 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003559 load_factor := 0.8,
3560 exp_load_ind := true,
3561 exp_overload := false,
3562 use_tmsi := false
3563 };
3564 var PagingTestState st := f_TC_paging(cfg);
3565 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3567 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003568 } else {
3569 setverdict(pass);
3570 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003572}
3573
3574/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3575 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3576 * - that CCCH LOAD IND (PCH) are being generated
3577 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3578testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003579 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003580 var PagingTestCfg cfg := {
3581 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003582 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003583 load_factor := 0.8,
3584 exp_load_ind := true,
3585 exp_overload := false,
3586 use_tmsi := true
3587 };
3588 var PagingTestState st := f_TC_paging(cfg);
3589 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3591 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003592 } else {
3593 setverdict(pass);
3594 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003596}
3597
3598/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3599 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3600 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3601 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3602testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003603 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003604 var PagingTestCfg cfg := {
3605 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003606 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003607 load_factor := 2.0,
3608 exp_load_ind := true,
3609 exp_overload := true,
3610 use_tmsi := false
3611 };
3612 var PagingTestState st := f_TC_paging(cfg);
3613 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3614 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003615 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003616 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003617 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 +01003618 } else {
3619 setverdict(pass);
3620 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003622}
3623
3624/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3625 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3626 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3627 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3628testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003629 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003630 var PagingTestCfg cfg := {
3631 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003632 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003633 load_factor := 2.0,
3634 exp_load_ind := true,
3635 exp_overload := true,
3636 use_tmsi := true
3637 };
3638 var PagingTestState st := f_TC_paging(cfg);
3639 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3640 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003641 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003642 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003643 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 +01003644 } else {
3645 setverdict(pass);
3646 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003648}
3649
3650
Harald Welte93640c62018-02-25 16:59:33 +01003651/***********************************************************************
3652 * Immediate Assignment / AGCH
3653 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003654private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003655 len := 0,
3656 ma := ''B
3657}
Harald Welte93640c62018-02-25 16:59:33 +01003658
Harald Weltee8d750e2018-06-10 21:41:35 +02003659private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3660 return int2str(num_tx) & " sent, "
3661 & int2str(num_rx) & " received, "
3662 & int2str(num_del) & " deleted";
3663}
3664
3665private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3666 var L1ctlDlMessage l1_dl;
3667 timer T := 10.0;
3668 var integer num_tx := 0;
3669 var integer num_rx := 0;
3670 var integer num_del := 0;
3671 var charstring res_str;
3672 var float rx_ratio;
3673
Harald Welte10474062019-05-30 16:48:17 +02003674 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003675 f_init_l1ctl();
3676 f_l1_tune(L1CTL);
3677
3678 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003679 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003680 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3681 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003682 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003683 num_tx := num_tx+1;
3684 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003685 }
3686 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003687 T.start;
3688 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003689 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003690 num_del := num_del+1;
3691 repeat;
3692 }
3693 [] RSL_CCHAN.receive {
3694 repeat;
3695 }
3696 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003697 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3698 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3699 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003700 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003701 } else {
3702 num_rx := num_rx+1;
3703 }
3704 repeat;
3705 }
3706 [] L1CTL.receive { repeat; }
3707 [] T.timeout { }
3708 }
3709 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3710 log("AGCH test: " & res_str);
3711 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003713 }
3714 rx_ratio := int2float(num_rx) / int2float(num_tx);
3715 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003716 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 +02003717 } else {
3718 setverdict(pass);
3719 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003721}
3722
Harald Weltee8d750e2018-06-10 21:41:35 +02003723/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3724testcase TC_imm_ass_1000_20ms() runs on test_CT {
3725 f_TC_imm_ass(1000, 0.02, 0.25);
3726}
3727
3728/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3729testcase TC_imm_ass_200_0ms() runs on test_CT {
3730 f_TC_imm_ass(200, 0.0, 0.05);
3731}
3732
3733/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3734testcase TC_imm_ass_200_76ms() runs on test_CT {
3735 f_TC_imm_ass(150, 0.076, 1.00);
3736}
3737
3738
3739
Harald Welte48494ca2018-02-25 16:59:50 +01003740/***********************************************************************
3741 * BCCH
3742 ***********************************************************************/
3743
3744/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003745private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003746 GsmFrameNumber frame_number,
3747 SystemInformation si
3748}
3749
3750/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003751private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003752
3753/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003754private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003755
3756/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003757private function f_si_vecslot_contains(SystemInformationVector arr,
3758 RrMessageType key,
3759 boolean bcch_ext := false)
3760return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003761 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3762 var integer fn_mod51 := arr[i].frame_number mod 51;
3763 if (not bcch_ext and fn_mod51 == 2 or
3764 bcch_ext and fn_mod51 == 6) {
3765 if (arr[i].si.header.message_type == key) {
3766 return true;
3767 }
3768 }
3769 }
3770 return false;
3771}
3772
3773/* 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 +07003774private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3775 integer tc, RrMessageType key,
3776 boolean ext_bcch := false)
3777{
Harald Welte48494ca2018-02-25 16:59:50 +01003778 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003780 }
3781}
3782
3783/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003784private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3785 RrMessageType key)
3786return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003787 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3788 if (f_si_vecslot_contains(arr[tc], key) or
3789 f_si_vecslot_contains(arr[tc], key, true)) {
3790 return true;
3791 }
3792 }
3793 return false;
3794}
3795
3796/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003797private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3798 RrMessageType key,
3799 boolean bcch_ext := false,
3800 integer n := 1, integer m := 4)
3801return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003802 var integer count := 0;
3803 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3805 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003806 }
3807 for (var integer i:= 0; i < m; i := i + 1) {
3808 var integer fn_mod51 := arr[i].frame_number mod 51;
3809 if (not bcch_ext and fn_mod51 == 2 or
3810 bcch_ext and fn_mod51 == 6) {
3811 if (arr[i].si.header.message_type == key) {
3812 count := count + 1;
3813 }
3814 }
3815 }
3816 if (count >= n) {
3817 return true;
3818 } else {
3819 return false;
3820 }
3821}
3822
3823/* 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 +07003824private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3825 integer tc, RrMessageType key,
3826 boolean ext_bcch := false,
3827 integer n, integer m)
3828{
Harald Welte48494ca2018-02-25 16:59:50 +01003829 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003831 }
3832}
3833
3834/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003835private function f_si_vecslot_contains_only(SystemInformationVector arr,
3836 RrMessageType key,
3837 boolean bcch_ext := false)
3838return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003839 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3840 var integer fn_mod51 := arr[i].frame_number mod 51;
3841 if (not bcch_ext and fn_mod51 == 2 or
3842 bcch_ext and fn_mod51 == 6) {
3843 if (arr[i].si.header.message_type != key) {
3844 return false;
3845 }
3846 }
3847 }
3848 return true;
3849}
3850
3851/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003852private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3853 integer tc, RrMessageType key,
3854 boolean ext_bcch := false)
3855{
Harald Welte48494ca2018-02-25 16:59:50 +01003856 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003858 }
3859}
3860
3861/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003862private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003863 boolean bcch_extended,
3864 boolean si1_present,
3865 boolean si2bis_present,
3866 boolean si2ter_present,
3867 boolean si2quater_present,
3868 boolean si7_present,
3869 boolean si8_present,
3870 boolean si9_present,
3871 boolean si13_present,
3872 boolean si13alt_present,
3873 boolean si15_present,
3874 boolean si16_present,
3875 boolean si17_present,
3876 boolean si2n_present,
3877 boolean si21_present,
3878 boolean si22_present
3879}
3880
3881/* 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 +07003882private function f_validate_si_scheduling(SystemInformationConfig cfg,
3883 SystemInformationVectorPerTc si_per_tc)
3884{
Harald Welte48494ca2018-02-25 16:59:50 +01003885 var integer i;
3886 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3887 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003889 }
3890 }
3891 if (cfg.si1_present) {
3892 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3893 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3894 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3895 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3896 /* make sure *ALL* contain SI1 */
3897 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3898 }
3899 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3900 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3901 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3902 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3903 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3904 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3905
3906 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3907 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3908 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3909 * consecutive occurrences of TC = 4. */
3910 if (cfg.si2bis_present and not cfg.si2ter_present) {
3911 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3912 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3913 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3914 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3915 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3916 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3917 }
3918
3919 if (cfg.si7_present or cfg.si8_present) {
3920 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3921 * if System Information type 4 does not contain all information needed for cell
3922 * selection and reselection. */
3923 if (not cfg.bcch_extended) {
3924 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3925 }
3926 if (cfg.si7_present) {
3927 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3928 }
3929 if (cfg.si8_present) {
3930 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3931 }
3932 }
3933
3934 if (cfg.si2quater_present) {
3935 /* iii) System information type 2 quater is sent if needed, as determined by the system
3936 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3937 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3938 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3939 * within any of 4 consecutive occurrences of TC = 5. */
3940 if (not (cfg.bcch_extended)) {
3941 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3942 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3943 } else {
3944 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3945 }
3946 } else {
3947 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3948 }
3949 }
3950 if (cfg.si9_present) {
3951 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3952 * in system information type 3 as defined in 3GPP TS 44.018. */
3953 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3954 }
3955 if (cfg.si13_present) {
3956 /* vii) System Information type 13 is only related to the GPRS service. System Information
3957 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3958 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3959 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3960 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3961 * within any of 4 consecutive occurrences of TC=4. */
3962 if (not cfg.bcch_extended) {
3963 log("not-bccch-extended");
3964 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3965 } else {
3966 log("bccch-extended");
3967 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3968 }
3969 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003971 }
3972 }
3973 if (cfg.si16_present or cfg.si17_present) {
3974 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3975 * should not be sent in a cell where network sharing is used (see rule xv). */
3976 if (cfg.si22_present) {
3977 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3978 }
3979 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003981 }
3982 if (not cfg.bcch_extended) {
3983 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3984 }
3985 if (cfg.si16_present) {
3986 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3987 }
3988 if (cfg.si17_present) {
3989 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3990 }
3991 }
3992
3993 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3994 * broadcast information. The frequency with which they are sent is determined by the
3995 * system operator. System Information type 9 identifies the scheduling of System
3996 * Information type 18 and 20 messages. */
3997
3998 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3999 * Information Type 19 is present, then its scheduling shall be indicated in System
4000 * Information Type 9. */
4001
4002 if (cfg.si15_present) {
4003 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4004 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4005 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4006 * 4 consecutive occurrences of TC = 1. */
4007 if (not cfg.bcch_extended) {
4008 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4009 } else {
4010 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4011 }
4012 }
4013 if (cfg.si13alt_present) {
4014 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4015 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4016 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4017 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4018 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4019 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4020 * of TC = 4. */
4021 if (cfg.si13_present) {
4022 testcase.stop("Error: Cannot have SI13alt and SI13");
4023 }
4024 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004026 }
4027 if (not cfg.bcch_extended) {
4028 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4029 } else {
4030 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4031 }
4032 }
4033 if (cfg.si2n_present) {
4034 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4035 * as determined by the system operator. In the case that the message is sent on the
4036 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4037 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4038 * consecutive occurrences of TC = 4. */
4039 if (not cfg.bcch_extended) {
4040 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4041 } else {
4042 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4043 }
4044 }
4045 if (cfg.si21_present) {
4046 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4047 * determined by the system operator. If Extended Access Barring is in use in the cell
4048 * then this message is sent at least once within any of 4 consecutive occurrences of
4049 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4050 * cell then this message shall only be sent on BCCH Ext. */
4051 if (not cfg.bcch_extended) {
4052 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4053 } else {
4054 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4055 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004057 }
4058 }
4059 }
4060 if (cfg.si22_present) {
4061 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4062 * should not be sent in a cell where SoLSA is used (see rule viii). System
4063 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4064 * =2 and TC=6. */
4065 if (cfg.si16_present or cfg.si17_present) {
4066 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4067 }
4068 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4069 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004071 }
4072 if (not cfg.bcch_extended) {
4073 testcase.stop("Error: SI22 requires BCCH Extd!");
4074 } else {
4075 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4076 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4077 }
4078 }
4079}
4080
4081/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004082private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4083return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004084 timer T := duration;
4085 var SystemInformationVectorPerTc si_per_tc;
4086 var L1ctlDlMessage l1_dl;
4087
4088 /* initialize all per-TC vectors empty */
4089 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4090 si_per_tc[i] := {};
4091 }
4092
4093 /* flush all previous L1 queued msgs */
4094 pt.clear;
4095
4096 T.start;
4097 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004098 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004099 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4100 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4101 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004102 repeat;
4103 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004104
Harald Welte48494ca2018-02-25 16:59:50 +01004105 var integer tc := f_gsm_compute_tc(sig.frame_number);
4106 log("SI received at TC=", tc, ": ", sig.si);
4107 /* append to the per-TC bucket */
4108 si_per_tc[tc] := si_per_tc[tc] & { sig };
4109 repeat;
4110 }
4111 [] pt.receive { repeat; }
4112 [] T.timeout { }
4113 }
4114
4115 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4116 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4117 }
4118 log("si_per_tc=", si_per_tc);
4119 return si_per_tc;
4120}
4121
4122/* helper function: Set given SI via RSL + validate scheduling.
4123 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004124private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004125 var SystemInformationVectorPerTc si_per_tc;
4126 f_init_l1ctl();
4127 f_l1_tune(L1CTL);
4128
4129 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004130 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004131 f_validate_si_scheduling(si_cfg, si_per_tc);
4132
4133 setverdict(pass);
4134}
4135
4136testcase TC_si_sched_default() runs on test_CT {
4137 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004138 /* 2+3+4 are mandatory and set in f_init() */
4139 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004141}
4142
4143testcase TC_si_sched_1() runs on test_CT {
4144 f_init();
4145 si_cfg.si1_present := true;
4146 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004147 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004149}
4150
4151testcase TC_si_sched_2bis() runs on test_CT {
4152 f_init();
4153 si_cfg.si2bis_present := true;
4154 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4155 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004157}
4158
4159testcase TC_si_sched_2ter() runs on test_CT {
4160 f_init();
4161 si_cfg.si2ter_present := true;
4162 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4163 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004165}
4166
4167testcase TC_si_sched_2ter_2bis() runs on test_CT {
4168 f_init();
4169 si_cfg.si2bis_present := true;
4170 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4171 si_cfg.si2ter_present := true;
4172 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4173 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004175}
4176
4177testcase TC_si_sched_2quater() runs on test_CT {
4178 f_init();
4179 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004180 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004181 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004183}
4184
4185testcase TC_si_sched_13() runs on test_CT {
4186 f_init();
4187 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004188 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004189 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004191}
4192
4193testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4194 f_init();
4195 si_cfg.si2bis_present := true;
4196 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4197 si_cfg.si2ter_present := true;
4198 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4199 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004200 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004201 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004202 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004203 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004205}
4206
4207
Harald Welte68e495b2018-02-25 00:05:57 +01004208testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004209 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004210 /* FIXME: enable / disable individual BCCH info */
4211 //ts_RSL_BCCH_INFO(si_type, info);
4212 /* expect no ERROR REPORT after either of them *
4213 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004215}
4216
Harald Welte93640c62018-02-25 16:59:33 +01004217/***********************************************************************
4218 * Low-Level Protocol Errors / ERROR REPORT
4219 ***********************************************************************/
4220
Harald Welte01d982c2018-02-25 01:31:40 +01004221private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4222 timer T := 5.0;
4223 T.start;
4224 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004225 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004226 setverdict(pass);
4227 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004228 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004230 }
4231 [] RSL_CCHAN.receive {
4232 repeat;
4233 }
4234 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004236 }
4237 }
4238}
4239
4240/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4241testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004242 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004243 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4244 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004245 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004246
4247 f_exp_err_rep(RSL_ERR_PROTO);
4248}
4249
4250/* Provoke a mandatory IE error and match on ERROR REPORT */
4251testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004252 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004253
4254 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4255 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004256 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004257
4258 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4259}
4260
4261/* Provoke an IE content error and match on ERROR REPORT */
4262testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004263 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004264 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4265 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004266 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004267
4268 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4269}
4270
Harald Welteee25aae2019-05-19 14:32:37 +02004271/* attempt to activate channel with wrong RSL Message Discriminator IE */
4272function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4273 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4274 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4275 RSL.send(rsl);
4276 f_rslem_unregister(0, g_chan_nr);
4277}
4278testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4279 var ConnHdlr vc_conn;
4280 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4281
Harald Welte10474062019-05-30 16:48:17 +02004282 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004283
4284 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4285 vc_conn.done;
4286 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4287
4288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4289}
4290
4291/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004292private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004293 var template (value) RSL_Message rsl_tx;
4294 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4295 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4296 RSL.send(rsl_tx);
4297 f_rslem_unregister(0, g_chan_nr);
4298}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004299private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004300 var template (value) RSL_Message rsl_tx;
4301 /* we first have to activate the dedicated channel */
4302 f_rsl_chan_act(g_pars.chan_mode);
4303 /* ... to then send an invalid RLL message */
4304 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4305 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4306 RSL.send(rsl_tx);
4307 f_rslem_unregister(0, g_chan_nr);
4308}
4309testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4310 var ConnHdlr vc_conn;
4311 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4312 var template (value) RSL_Message rsl_tx;
4313
Harald Welte10474062019-05-30 16:48:17 +02004314 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004315
4316 /* Common Channel with wrong message type */
4317 RSL_CCHAN.clear;
4318 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4319 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004320 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004321 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4322
4323 /* TRX Management */
4324 RSL_CCHAN.clear;
4325 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4326 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004327 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004328 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4329
4330 /* Dedicated Channel */
4331 RSL_CCHAN.clear;
4332 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4333 vc_conn.done;
4334 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4335
4336 /* RLL */
4337 RSL_CCHAN.clear;
4338 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4339 vc_conn.done;
4340 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4341}
4342
4343/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004344private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004345 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4346 f_rslem_unregister(0, g_chan_nr);
4347}
4348testcase TC_err_rep_wrong_sequence() runs on test_CT {
4349 var ConnHdlr vc_conn;
4350 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4351
Harald Welte10474062019-05-30 16:48:17 +02004352 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004353
4354 RSL_CCHAN.clear;
4355 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4356 vc_conn.done;
4357 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4358}
4359
Harald Welte93640c62018-02-25 16:59:33 +01004360/***********************************************************************
4361 * IPA CRCX/MDCX/DLCS media stream handling
4362 ***********************************************************************/
4363
Harald Weltea871a382018-02-25 02:03:14 +01004364/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004365private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004366 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4367 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004368}
4369testcase TC_ipa_dlcx_not_active() runs on test_CT {
4370 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004371 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004372 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4373 vc_conn.done;
4374}
Harald Welte68e495b2018-02-25 00:05:57 +01004375
Harald Weltea3f1df92018-02-25 12:49:55 +01004376/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004377private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004378 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4379 "IPA CRCX ACK");
4380 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4381 "IPA CRCX NACK");
4382}
4383testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4384 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004385 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004386 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4387 vc_conn.done;
4388}
4389
4390/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004391private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004392 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4393 "IPA CRCX ACK");
4394 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4395 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4396 var uint7_t rtp_pt2 := f_rnd_int(127);
4397 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4398 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4399 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4400 "IPA MDCX ACK");
4401 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4402 "IPA DLCX ACK");
4403}
4404testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4405 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004406 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004407 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4408 vc_conn.done;
4409}
4410
Harald Welte3ae11da2018-02-25 13:36:06 +01004411/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004412private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004413 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4414 "IPA CRCX ACK");
4415 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4416 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4417 var uint7_t rtp_pt2 := f_rnd_int(127);
4418 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4419 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4420 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4421 "IPA MDCX ACK");
4422 /* Second MDCX */
4423 remote_ip := f_rnd_int(c_UINT32_MAX);
4424 remote_port := f_rnd_int(c_UINT16_MAX);
4425 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4426 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4427 "IPA MDCX ACK");
4428 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4429 "IPA DLCX ACK");
4430}
4431testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4432 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004433 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004434 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4435 vc_conn.done;
4436}
4437
Harald Welte9912eb52018-02-25 13:30:15 +01004438/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004439private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004440 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4441 "IPA CRCX NACK");
4442}
4443testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4444 var ConnHdlrPars pars;
4445 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004446 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004447
4448 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4449 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4450 vc_conn.done;
4451
4452 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4453 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4454 vc_conn.done;
4455}
4456
Harald Weltea3f1df92018-02-25 12:49:55 +01004457
Harald Welte883340c2018-02-28 18:59:29 +01004458/***********************************************************************
4459 * PCU Socket related tests
4460 ***********************************************************************/
4461
Harald Welte07bd2d22019-05-25 11:03:30 +02004462/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004463friend 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 +01004464runs on test_CT {
4465 timer T := 3.0;
4466
4467 /* we don't expect any RTS.req before PDCH are active */
4468 T.start;
4469 alt {
4470 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004472 }
4473 [] PCU.receive { repeat; }
4474 [] T.timeout { }
4475 }
4476
4477 /* Send PDCH activate request for known PDCH timeslot */
4478 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4479
4480 /* we now expect RTS.req for this timeslot (only) */
4481 T.start;
4482 alt {
4483 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4484 setverdict(pass);
4485 }
4486 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4487 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004489 }
4490 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004492 }
4493 [] PCU.receive { repeat; }
4494 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004496 }
4497 [not exp_success] T.timeout {
4498 setverdict(pass);
4499 }
4500 }
4501}
4502
Harald Welte07bd2d22019-05-25 11:03:30 +02004503/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004504friend 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 +01004505runs on test_CT {
4506 timer T := 3.0;
4507
4508 /* Send PDCH activate request for known PDCH timeslot */
4509 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 +02004510 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4511 * when it will actually have been executed in the BTS */
4512 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004513 PCU.clear;
4514 /* we now expect no RTS.req for this timeslot */
4515 T.start;
4516 alt {
4517 [] 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 +02004518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004519 }
4520 [] PCU.receive { repeat; }
4521 [] T.timeout {
4522 setverdict(pass);
4523 }
4524 }
4525}
4526
Harald Weltead033dc2019-05-25 17:28:16 +02004527friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004528 f_init();
4529 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4530}
4531
Harald Welte883340c2018-02-28 18:59:29 +01004532/* PDCH activation via PCU socket; check for presence of RTS.req */
4533testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004534 f_init_pcu_test();
4535
Harald Welte883340c2018-02-28 18:59:29 +01004536 f_TC_pcu_act_req(0, 0, 7, true);
4537}
4538
4539/* PDCH activation via PCU socket on non-PDCU timeslot */
4540testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004541 f_init_pcu_test();
4542
Harald Welte883340c2018-02-28 18:59:29 +01004543 f_TC_pcu_act_req(0, 0, 1, false);
4544}
4545
4546/* PDCH activation via PCU socket on wrong BTS */
4547testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004548 f_init_pcu_test();
4549
Harald Welte883340c2018-02-28 18:59:29 +01004550 f_TC_pcu_act_req(23, 0, 7, false);
4551}
4552
4553/* PDCH activation via PCU socket on wrong TRX */
4554testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004555 f_init_pcu_test();
4556
Harald Welte883340c2018-02-28 18:59:29 +01004557 f_TC_pcu_act_req(0, 23, 7, false);
4558}
4559
4560/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4561testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004562 f_init_pcu_test();
4563
Harald Welte883340c2018-02-28 18:59:29 +01004564 /* Activate PDCH */
4565 f_TC_pcu_act_req(0, 0, 7, true);
4566 f_sleep(1.0);
4567 /* and De-Activate again */
4568 f_TC_pcu_deact_req(0, 0, 7);
4569}
4570
4571/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4572testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004573 f_init_pcu_test();
4574
Harald Welte883340c2018-02-28 18:59:29 +01004575 f_TC_pcu_deact_req(0, 0, 1);
4576}
4577
4578/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4579testcase TC_pcu_ver_si13() runs on test_CT {
4580 const octetstring si13 := '00010203040506070909'O;
4581 var PCUIF_send_data sd;
4582 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004583 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004584
4585 /* Set SI13 via RSL */
4586 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004587
Harald Welte883340c2018-02-28 18:59:29 +01004588 T.start;
4589 alt {
4590 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4591 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4592 setverdict(pass);
4593 } else {
4594 repeat;
4595 }
4596 }
4597 [] PCU.receive { repeat; }
4598 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004600 }
4601 }
4602}
4603
4604private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4605
4606/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004607friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004608 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4609runs on test_CT
4610{
4611 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4612 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4613}
4614
4615/* 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 +02004616friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4617 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004618runs on test_CT
4619{
4620 var PCUIF_send_data sd;
4621
4622 timer T := 3.0;
4623 T.start;
4624 alt {
4625 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4626 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4627 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4628 sd.data.u.rts_req.fn, sapi, data);
4629 }
4630 [] PCU.receive { repeat; }
4631 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004633 }
4634 }
4635}
4636
4637/* Send DATA.req on invalid BTS */
4638testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004639 var TfiUsfArr tua := f_TfiUsfArrInit();
4640 var octetstring data := '0000'O & f_rnd_octstring(21);
4641
4642 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004643
Harald Welte883340c2018-02-28 18:59:29 +01004644 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004645 f_TfiUsfArrSet(tua, 7, 0);
4646 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4647 f_sleep(1.0);
4648
4649 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004650}
4651
4652/* Send DATA.req on invalid TRX */
4653testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004654 var TfiUsfArr tua := f_TfiUsfArrInit();
4655 var octetstring data := '0000'O & f_rnd_octstring(21);
4656
4657 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004658
Harald Welte883340c2018-02-28 18:59:29 +01004659 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004660 f_TfiUsfArrSet(tua, 7, 0);
4661 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4662 f_sleep(1.0);
4663
4664 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004665}
4666
4667/* Send DATA.req on invalid timeslot */
4668testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004669 var TfiUsfArr tua := f_TfiUsfArrInit();
4670 var octetstring data := '0000'O & f_rnd_octstring(21);
4671
4672 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004673
Harald Welte883340c2018-02-28 18:59:29 +01004674 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004675 f_TfiUsfArrSet(tua, 7, 0);
4676 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4677 f_sleep(1.0);
4678
4679 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004680}
4681
4682/* Send DATA.req on timeslot that hasn't been activated */
4683testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004684 var TfiUsfArr tua := f_TfiUsfArrInit();
4685 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004686
Harald Welte7162a612019-05-26 12:56:09 +02004687 f_virtphy_common();
4688
4689 f_TfiUsfArrSet(tua, 7, 0);
4690 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4691 f_sleep(1.0);
4692
4693 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004694}
4695
Harald Weltead033dc2019-05-25 17:28:16 +02004696private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004697 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4698 boolean wait_rts := true)
4699runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004700 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004701 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004702
4703 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004704 if (wait_rts) {
4705 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4706 } else {
4707 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4708 }
Harald Weltead033dc2019-05-25 17:28:16 +02004709
4710 T.start;
4711 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004712 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004713 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4714 setverdict(pass);
4715 }
Harald Welte7162a612019-05-26 12:56:09 +02004716 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4717 setverdict(fail, "Received unexpected ", rx_dl);
4718 }
Harald Weltead033dc2019-05-25 17:28:16 +02004719 [] L1CTL.receive {
4720 repeat;
4721 }
Harald Welte7162a612019-05-26 12:56:09 +02004722 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004723 setverdict(fail, "Timeout waiting for ", data);
4724 }
Harald Welte7162a612019-05-26 12:56:09 +02004725 [not expect_data] T.timeout {
4726 setverdict(pass);
4727 }
Harald Weltead033dc2019-05-25 17:28:16 +02004728 }
4729}
4730
4731private function f_disable_dynamic_ts() runs on test_CT
4732{
4733 f_init_vty_bsc();
4734 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4735 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4736 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4737 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004738 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004739}
4740
4741private function f_virtphy_common() runs on test_CT {
4742 f_disable_dynamic_ts();
4743 f_init_l1ctl();
4744 f_l1_tune(L1CTL);
4745}
4746
4747testcase TC_pcu_data_req_pdtch() runs on test_CT {
4748 var TfiUsfArr tua := f_TfiUsfArrInit();
4749 var octetstring data := '0000'O & f_rnd_octstring(21);
4750
4751 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004752
Harald Welte883340c2018-02-28 18:59:29 +01004753 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004754 f_TfiUsfArrSet(tua, 7, 0);
4755 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4756 f_sleep(1.0);
4757
4758 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004759}
4760
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004761/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004762testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004763 var TfiUsfArr tua := f_TfiUsfArrInit();
4764 var octetstring data := '0000'O & f_rnd_octstring(21);
4765
4766 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004767
Harald Welte883340c2018-02-28 18:59:29 +01004768 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004769 f_TfiUsfArrSet(tua, 7, 0);
4770 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4771 f_sleep(1.0);
4772
4773 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004774}
4775
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004776private function f_TC_pcu_ptcch_ul(uint16_t ra)
4777runs on test_CT {
4778 var template PCUIF_Message pcu_rach_ind;
4779 var PCUIF_send_data sd;
4780 var GsmFrameNumber fn;
4781 timer T;
4782
4783 /* Send an Access Burst on PTCCH/U over the Um-interface */
4784 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4785 chan_nr := ts_RslChanNr_PDCH(7),
4786 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4787
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004788 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4789 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004790
4791 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4792 T.start(52.0 * 4.615 / 1000.0);
4793 alt {
4794 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4795 log("Rx an Access Burst on the PCU interface: ", sd.data);
4796 setverdict(pass);
4797 T.stop;
4798 }
4799 [] PCU.receive { repeat; }
4800 [] T.timeout {
4801 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4802 /* Keep going, that's not the end of the world */
4803 }
4804 }
4805}
4806
4807testcase TC_pcu_ptcch() runs on test_CT {
4808 var L1ctlDlMessage dl;
4809 var octetstring data;
4810 timer T;
4811
4812 f_init_pcu_test();
4813 f_init_l1ctl();
4814 f_l1_tune(L1CTL);
4815
4816 /* Activate PDCH channel on TS7 */
4817 f_TC_pcu_act_req(0, 0, 7, true);
4818
4819 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004820 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004821 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004822 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004823 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004824
4825 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4826 for (var integer i := 0; i < 16; i := i + 1) {
4827 log("Sending an Access Burst towards the L1CTL interface");
4828 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4829 }
4830
4831 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4832 data := f_rnd_octstring(23);
4833
4834 /* Verify PTCCH/D: send a random data block, make sure it's received */
4835 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4836 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4837
4838 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4839 * let's give it more time in case if we miss the beginning. */
4840 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4841 alt {
4842 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4843 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4844 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4845 frame := data)) -> value dl {
4846 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4847 setverdict(pass);
4848 T.stop;
4849 }
4850 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4851 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4852 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4853 l2_data := data)) -> value dl {
4854 log("Rx PTCCH/D data block on L1CTL: ", dl);
4855 setverdict(pass);
4856 T.stop;
4857 }
4858 [] L1CTL.receive { repeat; }
4859 [] T.timeout {
4860 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4861 }
4862 }
4863}
4864
Harald Welte883340c2018-02-28 18:59:29 +01004865/* Send AGCH from PCU; check it appears on Um side */
4866testcase TC_pcu_data_req_agch() runs on test_CT {
4867 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004868 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004869 f_init_l1ctl();
4870 f_l1_tune(L1CTL);
4871
4872 f_TC_pcu_act_req(0, 0, 7, true);
4873 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4874
4875 T.start;
4876 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004877 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004878 setverdict(pass);
4879 }
4880 [] L1CTL.receive { repeat; }
4881 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004883 }
4884 }
4885}
4886
Harald Welte928622b2019-05-26 13:22:59 +02004887/* Send AGCH from PCU; check it appears on Um side */
4888testcase TC_pcu_data_req_pch() runs on test_CT {
4889 timer T := 3.0;
4890 f_init_pcu_test();
4891 f_init_l1ctl();
4892 f_l1_tune(L1CTL);
4893
4894 f_TC_pcu_act_req(0, 0, 7, true);
4895 /* three characters prefix: last 3 digits of IMSI as ASCII */
4896 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4897
4898 T.start;
4899 alt {
4900 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4901 setverdict(pass);
4902 }
4903 [] L1CTL.receive { repeat; }
4904 [] T.timeout {
4905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4906 }
4907 }
4908}
4909
Harald Welte883340c2018-02-28 18:59:29 +01004910/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4911testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4912 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004913 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004914 f_init_l1ctl();
4915 f_l1_tune(L1CTL);
4916
4917 /* append 3 last imsi digits so BTS can compute pagng group */
4918 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4919
4920 timer T := 0.5;
4921 T.start;
4922 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004923 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004924 /* TODO: verify paging group */
4925 setverdict(pass);
4926 }
4927 [] L1CTL.receive { repeat; }
4928 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004930 }
4931 }
4932}
4933
4934/* Send RACH from Um side, expect it to show up on PCU socket */
4935testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004936 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004937 f_init_l1ctl();
4938 f_l1_tune(L1CTL);
4939
4940 var GsmFrameNumber fn_last := 0;
4941 for (var integer i := 0; i < 1000; i := i+1) {
4942 var OCT1 ra := f_rnd_ra_ps();
4943 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4944 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004946 }
4947 fn_last := fn;
4948
4949 timer T := 2.0;
4950 T.start;
4951 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004952 [] 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 +01004953 T.stop;
4954 }
4955 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004957 }
4958 [] PCU.receive { repeat; }
4959 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004961 }
4962 }
4963 }
4964 setverdict(pass);
4965}
4966
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004967/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4968 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4969testcase TC_pcu_ext_rach_content() runs on test_CT {
4970 var template PCUIF_Message pcu_rach_ind;
4971 var GsmFrameNumber fn_last := 0;
4972 var L1ctlRachSynchSeq synch_seq;
4973 var PCUIF_BurstType pcu_bt;
4974 var GsmFrameNumber fn;
4975 var BIT11 ra11;
4976
4977 f_init_pcu_test();
4978 f_init_l1ctl();
4979 f_l1_tune(L1CTL);
4980
4981 for (var integer i := 0; i < 1000; i := i+1) {
4982 /* We need to test both TS1 & TS2 */
4983 if (i rem 2 == 0) {
4984 synch_seq := RACH_SYNCH_SEQ_TS1;
4985 pcu_bt := BURST_TYPE_1;
4986 } else {
4987 synch_seq := RACH_SYNCH_SEQ_TS2;
4988 pcu_bt := BURST_TYPE_2;
4989 }
4990
4991 ra11 := f_rnd_ra11_ps();
4992 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4993 if (fn == fn_last) {
4994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4995 "Two RACH in same FN?!?");
4996 }
4997 fn_last := fn;
4998
4999 /* Compose the expected message */
5000 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005001 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005002 ra := bit2int(ra11),
5003 is_11bit := 1,
5004 burst_type := pcu_bt,
5005 fn := fn);
5006
5007 timer T := 2.0;
5008 T.start;
5009 alt {
5010 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5011 T.stop;
5012 }
5013 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5015 }
5016 [] PCU.receive { repeat; }
5017 [] T.timeout {
5018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5019 }
5020 }
5021 }
5022 setverdict(pass);
5023}
5024
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005025private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5026runs on test_CT {
5027 var template PCUIF_send_data sdt;
5028 var PCUIF_send_data sd;
5029 var int16_t lqual_cb;
5030 timer T := 1.0;
5031
5032 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5033 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5034
5035 /* Send a random PDTCH frame over Um */
5036 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5037 '0000'O & f_rnd_octstring(21)));
5038
5039 T.start;
5040 alt {
5041 /* If expected link quality is above the threshold */
5042 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5043 lqual_cb := sd.data.u.data_ind.lqual_cb;
5044 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5045
5046 /* Make sure the actual link quality matches the expected value */
5047 if (not match(lqual_cb, lqual_cb_exp)) {
5048 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5049 "expected value ", lqual_cb_exp));
5050 } else {
5051 setverdict(pass);
5052 }
5053 }
5054 /* If expected link quality is below the threshold */
5055 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5057 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5058 }
5059 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5060 [] PCU.receive { repeat; }
5061 [lqual_cb_exp < thresh] T.timeout {
5062 log("Rx nothing, as expected");
5063 setverdict(pass);
5064 }
5065 [lqual_cb_exp >= thresh] T.timeout {
5066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5067 "Timeout waiting for PCUIF_DATA.ind");
5068 }
5069 }
5070}
5071
5072/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5073testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5074 f_init_pcu_test();
5075 PCU.clear;
5076
5077 f_init_l1ctl();
5078 f_l1_tune(L1CTL);
5079
5080 /* Activate a PDCH channel on TS7 */
5081 f_TC_pcu_act_req(0, 0, 7, true);
5082
5083 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005084 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005085 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005086 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005087 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005088
5089 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5090 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5091 var TrxcMessage ret;
5092
5093 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5094 valueof(ts_TRXC_FAKE_CI(i)));
5095
5096 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5097 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5098 }
5099}
5100
Harald Welte883340c2018-02-28 18:59:29 +01005101/* Send PAGING via RSL, expect it to shw up on PCU socket */
5102testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005103 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005104
5105 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005106 var MobileIdentityLV mi_lv;
5107 var octetstring mi_lv_enc;
5108 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005109 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005110
Harald Welte883340c2018-02-28 18:59:29 +01005111 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005112 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005113 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005114 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005115 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005116
5117 /* Fancy encoding for PCUIF */
5118 mi_lv := valueof(ts_MI_LV(mi));
5119 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5120 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005121
5122 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005123 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005124 T.start;
5125 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005126 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005127 }
5128 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005130 }
5131 [] PCU.receive { repeat; }
5132 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005134 }
5135 }
5136 }
5137 setverdict(pass);
5138}
5139
Harald Welted66c9b82019-05-25 09:03:15 +02005140/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5141testcase TC_pcu_time_ind() runs on test_CT {
5142 var PCUIF_send_data pcu_sd;
5143 var integer num_time_ind := 0;
5144 var integer first_fn, last_fn;
5145 var float test_duration := 5.0;
5146 timer T;
5147
5148 f_init_pcu_test();
5149 f_TC_pcu_act_req(0, 0, 7, true);
5150
5151 PCU.clear;
5152 T.start(test_duration);
5153 alt {
5154 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5155 num_time_ind := num_time_ind + 1;
5156 if (not isbound(first_fn)) {
5157 first_fn := pcu_sd.data.u.time_ind.fn;
5158 }
5159 last_fn := pcu_sd.data.u.time_ind.fn;
5160 repeat;
5161 }
5162 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5163 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5164 repeat;
5165 }
5166 [] PCU.receive {
5167 repeat;
5168 }
5169 [] T.timeout {}
5170 }
5171 var integer fn_expired := last_fn - first_fn;
5172 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5173
5174 /* verify the number of frames expired matches our expectation */
5175 const float c_GSM_FN_DURATION_MS := 4.61538;
5176 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005177 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005178 if (not match(fn_expired, t_fn_expected)) {
5179 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5180 }
5181
5182 /* There are three TIME.ind in every fn MOD 13 */
5183 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5184 /* Add some tolerance */
5185 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5186 if (not match(num_time_ind, t_time_ind_exp)) {
5187 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5188 }
5189
5190 setverdict(pass);
5191}
5192
Harald Welte4832c862019-05-25 14:57:18 +02005193/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5194testcase TC_pcu_rts_req() runs on test_CT {
5195 var PCUIF_send_data pcu_sd;
5196 var integer first_fn, last_fn;
5197 var integer num_rts_pdtch := 0;
5198 var integer num_rts_ptcch := 0;
5199 var float test_duration := 5.0;
5200 timer T;
5201
5202 f_init_pcu_test();
5203 f_TC_pcu_act_req(0, 0, 7, true);
5204
5205 PCU.clear;
5206 T.start(test_duration);
5207 alt {
5208 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5209 -> value pcu_sd {
5210 num_rts_pdtch := num_rts_pdtch + 1;
5211 if (not isbound(first_fn)) {
5212 first_fn := pcu_sd.data.u.rts_req.fn;
5213 }
5214 last_fn := pcu_sd.data.u.rts_req.fn;
5215 repeat;
5216 }
5217 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5218 -> value pcu_sd {
5219 num_rts_ptcch := num_rts_ptcch + 1;
5220 if (not isbound(first_fn)) {
5221 first_fn := pcu_sd.data.u.rts_req.fn;
5222 }
5223 last_fn := pcu_sd.data.u.rts_req.fn;
5224 repeat;
5225 }
5226 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5227 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5228 repeat;
5229 }
5230 [] PCU.receive {
5231 repeat;
5232 }
5233 [] T.timeout {}
5234 }
5235 var integer fn_expired := last_fn - first_fn;
5236 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5237 ", num_rts_ptcch=", num_rts_ptcch);
5238
5239 /* verify the number of frames expired matches our expectation */
5240 const float c_GSM_FN_DURATION_MS := 4.61538;
5241 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005242 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005243 if (not match(fn_expired, t_fn_expected)) {
5244 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5245 }
5246
5247 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5248 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5249 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5250 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5251 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5252 t_ptcch_exp);
5253 }
5254
5255 /* We have 12 PDTCH blocks every 52-multiframe */
5256 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5257 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5258 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5259 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5260 t_pdtch_exp);
5261 }
5262
5263 setverdict(pass);
5264}
5265
Harald Welte07bd2d22019-05-25 11:03:30 +02005266/* test for generating Abis side OML ALERT from the PCU */
5267testcase TC_pcu_oml_alert() runs on test_CT {
5268 var PCUIF_send_data pcu_sd;
5269 var integer num_time_ind := 0;
5270 var integer first_fn, last_fn;
5271 var float test_duration := 5.0;
5272 timer T;
5273
5274 f_init_pcu_test();
5275 f_TC_pcu_act_req(0, 0, 7, true);
5276
5277 /* re-connect CTRL port from BTS to BSC */
5278 f_ipa_ctrl_stop();
5279 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5280
5281 /* Send that OML Alert */
5282 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5283
5284 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5285 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5286 setverdict(pass);
5287}
5288
Harald Welteeaa9a862019-05-26 23:01:08 +02005289/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5290private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5291 var PCUIF_Message first_info;
5292 var integer pcu_conn_id := -1;
5293 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5294 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5295 var OCT4 tlli := '01020304'O;
5296 var OCT1 cause := '23'O;
5297 timer T := 5.0;
5298
5299 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5300
5301 f_l1_tune(L1CTL);
5302 RSL.clear;
5303
5304 f_est_dchan();
5305 L1CTL.clear;
5306
5307 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5308
5309 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5310 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5311 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5312
5313 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5314 T.start;
5315 alt {
5316 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5317 setverdict(pass);
5318 }
5319 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5320 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5321 }
5322 [] PCU.receive {
5323 repeat;
5324 }
5325 [] T.timeout {
5326 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5327 }
5328 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005329
5330 /* release the channel */
5331 f_rsl_chan_deact();
5332 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5333 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005334}
5335testcase TC_pcu_rr_suspend() runs on test_CT {
5336 var ConnHdlrPars pars;
5337 var ConnHdlr vc_conn;
5338
5339 f_init();
5340
5341 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5342 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5343 vc_conn.done;
5344}
Harald Welte07bd2d22019-05-25 11:03:30 +02005345
Harald Weltea2e0e942019-05-27 18:12:53 +02005346/* Ensure that PCUIF socket can accept only a single connection */
5347testcase TC_pcu_socket_connect_multi() runs on test_CT {
5348 timer T := 5.0;
5349
5350 /* this (among other things) establishes the first connection to the PCUIF socket */
5351 f_init();
5352
5353 /* try to establish a second connection, expect it to fail */
5354 PCU.send(UD_connect:{mp_pcu_socket, -1});
5355 T.start;
5356 alt {
5357 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5358 setverdict(pass);
5359 }
5360 [] PCU.receive(UD_connect_result:?) {
5361 setverdict(fail, "Unexpected unix domain connect result");
5362 }
5363 [] T.timeout {
5364 setverdict(pass);
5365 }
5366 }
5367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5368}
5369
Harald Weltec8effb72019-05-27 18:23:04 +02005370/* Ensure that PCUIF socket can disconnect + reconnect */
5371testcase TC_pcu_socket_reconnect() runs on test_CT {
5372 /* this (among other things) establishes the first connection to the PCUIF socket */
5373 f_init();
5374
5375 f_sleep(1.0);
5376
5377 f_pcuif_close(PCU, g_pcu_conn_id);
5378 g_pcu_conn_id := -1;
5379
5380 f_sleep(1.0);
5381
5382 /* re-connect */
5383 PCU.clear;
5384 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5385 setverdict(pass);
5386
5387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5388}
5389
Harald Weltebe030482019-05-27 22:29:35 +02005390/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005391private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5392runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005393 var L1ctlDlMessage l1_dl;
5394 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005395 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005396 timer T := 5.0;
5397 T.start;
5398 alt {
5399 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005400 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5401 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005402 repeat;
5403 }
5404 }
5405 [] pt.receive {
5406 repeat;
5407 }
5408 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5410 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005411 }
5412 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005413 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005414}
5415
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005416/* Check if GPRS Indicator is present in RR System Information of a given type */
5417private function f_si_has_gprs_indicator(RrMessageType si_type)
5418runs on test_CT return boolean {
5419 var SystemInformation si := f_get_si(L1CTL, si_type);
5420
5421 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005422 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005423 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005424 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005425 }
5426
5427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5428 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005429}
5430
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005431/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5432private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5433runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005434 /* don't call f_init() as this would connect PCU socket */
5435 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005436
5437 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005438 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005439 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005440
5441 f_init_l1ctl();
5442 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005443 f_sleep(2.0);
5444 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005445
5446 if (f_si_has_gprs_indicator(si_type)) {
5447 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005448 } else {
5449 setverdict(pass);
5450 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005451
Harald Weltebe030482019-05-27 22:29:35 +02005452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5453}
5454
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005455testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5456 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5457}
Harald Weltebe030482019-05-27 22:29:35 +02005458
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005459testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5460 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5461}
5462
5463/* Ensure that GPRS capability is advertised after PCU socket connect */
5464private function f_TC_pcu_socket_connect(RrMessageType si_type)
5465runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005466 /* this (among other things) establishes the first connection to the PCUIF socket */
5467 f_init();
5468 f_init_l1ctl();
5469 f_l1_tune(L1CTL);
5470
5471 f_sleep(2.0);
5472 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005473
5474 if (not f_si_has_gprs_indicator(si_type)) {
5475 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005476 } else {
5477 setverdict(pass);
5478 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005479
Harald Weltebe030482019-05-27 22:29:35 +02005480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5481}
5482
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005483testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5484 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5485}
Harald Weltebe030482019-05-27 22:29:35 +02005486
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005487testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5488 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5489}
5490
5491/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5492private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5493runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005494 /* this (among other things) establishes the first connection to the PCUIF socket */
5495 f_init();
5496 f_init_l1ctl();
5497 f_l1_tune(L1CTL);
5498
5499 f_pcuif_close(PCU, g_pcu_conn_id);
5500 g_pcu_conn_id := -1;
5501
5502 f_sleep(1.0);
5503
5504 /* re-connect */
5505 PCU.clear;
5506 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5507
5508 f_sleep(2.0);
5509 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005510
5511 if (f_si_has_gprs_indicator(si_type)) {
5512 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005513 } else {
5514 setverdict(pass);
5515 }
5516
5517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5518}
5519
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005520testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5521 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5522}
5523
5524testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5525 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5526}
5527
Oliver Smithf5239c72019-08-28 10:01:25 +02005528/* 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) */
5529testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5530 var SystemInformation si3 := valueof(ts_SI3_default);
5531
5532 f_init();
5533
Harald Welte76220222020-10-11 20:32:44 +02005534 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5535 * information */
5536 timer T := 2.0;
5537 T.start;
5538 alt {
5539 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5540 [] T.timeout {}
5541 }
5542
Oliver Smithf5239c72019-08-28 10:01:25 +02005543 /* Verify cell_id */
5544 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5545 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5546 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005547 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5548 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5549 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005550 }
5551
5552 /* Verify LAC */
5553 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5554 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5555 if (lac_si3 != lac_pcu) {
5556 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5557 }
5558
5559 setverdict(pass);
5560}
Harald Welted66c9b82019-05-25 09:03:15 +02005561
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005562/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5563testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5564 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005565 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005566
5567 f_init();
5568
5569 info_ind := g_pcu_last_info.u.info_ind;
5570
5571 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5572 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5573 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5574 /* Skip inactive timeslots */
5575 continue;
5576 }
5577
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005578 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005579 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005580 else
5581 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005582
5583 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005584 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005585 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005586 hsn := fhp.maio_hsn.hsn,
5587 maio := fhp.maio_hsn.maio,
5588 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005589 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005590 } else {
5591 tr_ts := tr_PCUIF_InfoTrxTsH0;
5592 }
5593
5594 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5595 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5596 if (not match(ts, tr_ts)) {
5597 setverdict(fail, "Hopping parameters do not match: ",
5598 "received ", ts, " vs expected ", tr_ts);
5599 } else {
5600 setverdict(pass);
5601 }
5602 }
5603 }
5604}
5605
Alexander Couzens5283f552020-07-28 15:39:04 +02005606/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5607testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5608 f_init_vty_bsc();
5609 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5610 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5611
5612 f_init();
5613
5614 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5615 if (not ischosen(remote_addr.v10)) {
5616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5617 log2str("Unexpected remote_addr: ", remote_addr));
5618 }
5619
5620 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5621 setverdict(fail, "Received address family is not IPv4");
5622 }
5623
5624 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5625 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5626 }
5627
5628 setverdict(pass);
5629}
5630
5631/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5632testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5633 f_init_vty_bsc();
5634 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5635
5636 f_init();
5637
5638 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5639 if (not ischosen(remote_addr.v10)) {
5640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5641 log2str("Unexpected remote_addr: ", remote_addr));
5642 }
5643
5644 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5645 setverdict(fail, "Received address family is not IPv6");
5646 }
5647
5648 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5649 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5650 }
5651
5652 setverdict(pass);
5653}
5654
Harald Welte3d04ae62018-04-04 20:29:05 +02005655/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005656 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005657 ***********************************************************************/
5658
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005659private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5660 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005661runs on ConnHdlr {
5662 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005663
5664 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005665 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005666 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5667 repeat;
5668 }
5669 }
5670}
5671
5672private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5673runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005674 /* Expect BTS to immediately acknowledge activation as PDCH */
5675 PCU.clear;
5676 f_rsl_chan_act(g_pars.chan_mode);
5677 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005678 timer T_wait := 2.0;
5679 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005680 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005681 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005682 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005683 [] T_wait.timeout {
5684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5685 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5686 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005687 }
5688 /* try to activate this PDCH from the PCU point of view */
5689 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5690 /* FIXME: is there a response? */
5691}
5692
5693private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5694runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005695 /* Send RSL CHAN REL (deactivate) */
5696 PCU.clear;
5697 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5698 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005699 timer T_wait := 2.0;
5700 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005701 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005702 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005703 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005704 [] T_wait.timeout {
5705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5706 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5707 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005708 }
5709 /* Emulate PCU asking BTS to deactivate PDCH */
5710 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5711 alt {
5712 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5713 setverdict(pass);
5714 }
5715 [] RSL.receive { repeat; }
5716 }
5717}
5718
5719/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005720private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005721 var PCUIF_Message first_info;
5722 var integer ts_nr := g_chan_nr.tn;
5723 var integer trx_nr := 0;
5724 var integer bts_nr := 0;
5725 var integer pcu_conn_id := -1;
5726
5727 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5728
5729 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5730 f_sleep(3.0);
5731 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5732 setverdict(pass);
5733}
5734testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5735 var ConnHdlrPars pars;
5736 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005737 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005738
5739 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5740 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5741 vc_conn.done;
5742}
5743
5744/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005745private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005746 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005747 var integer pcu_conn_id := -1;
5748
5749 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5750
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005751 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5752 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5753 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005754 setverdict(pass);
5755}
5756testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5757 var ConnHdlrPars pars;
5758 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005759 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005760
5761 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5762 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5763 vc_conn.done;
5764}
5765
5766/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005767private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005768 var PCUIF_Message first_info;
5769 var integer ts_nr := g_chan_nr.tn;
5770 var integer trx_nr := 0;
5771 var integer bts_nr := 0;
5772 var integer pcu_conn_id := -1;
5773
5774 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5775
5776 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005777 /* Send a second Chan Activ and expect it to be NACKed */
5778 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5779 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005780 setverdict(pass);
5781}
5782testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5783 var ConnHdlrPars pars;
5784 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005785 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005786
5787 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5788 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5789 vc_conn.done;
5790}
5791
5792/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005793private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005794 var PCUIF_Message first_info;
5795 var integer ts_nr := g_chan_nr.tn;
5796 var integer trx_nr := 0;
5797 var integer bts_nr := 0;
5798 var integer pcu_conn_id := -1;
5799 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5800
5801 /* register for the TCH/F channel number */
5802 f_rslem_register(0, chan_nr);
5803
5804 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5805
5806 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5807 "RSL CHAN ACT");
5808 setverdict(pass);
5809}
5810testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5811 var ConnHdlrPars pars;
5812 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005813 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005814
5815 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5816 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5817 vc_conn.done;
5818}
5819
5820/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005821private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005822 var PCUIF_Message first_info;
5823 var integer ts_nr := g_chan_nr.tn;
5824 var integer trx_nr := 0;
5825 var integer bts_nr := 0;
5826 var integer pcu_conn_id := -1;
5827 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5828 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5829
5830 /* register for the TCH/H channel numbers */
5831 f_rslem_register(0, chan_nr[0]);
5832 f_rslem_register(0, chan_nr[1]);
5833
5834 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5835
5836 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5837 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5838 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5839 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5840 setverdict(pass);
5841}
5842testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5843 var ConnHdlrPars pars;
5844 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005845 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005846
5847 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5848 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5849 vc_conn.done;
5850}
5851
Harald Welte9bbbfb52018-04-05 09:33:19 +02005852/***********************************************************************
5853 * IPA Style Dynamic Timeslot Support
5854 ***********************************************************************/
5855
5856private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5857runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005858 /* Expect BTS to immediately acknowledge activation as PDCH */
5859 PCU.clear;
5860 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5861 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005862 timer T_wait := 2.0;
5863 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005864 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005865 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005866 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005867 [] T_wait.timeout {
5868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5869 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5870 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005871 }
5872 /* try to activate this PDCH from the PCU point of view */
5873 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5874 /* FIXME: is there a response? */
5875
5876 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5877}
5878
5879private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5880runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005881 /* Send RSL CHAN REL (deactivate) */
5882 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5883 PCU.clear;
5884 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005885 timer T_wait := 2.0;
5886 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005887 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005888 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005889 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005890 [] T_wait.timeout {
5891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5892 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5893 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005894 }
5895 /* Emulate PCU asking BTS to deactivate PDCH */
5896 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5897 alt {
5898 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5899 setverdict(pass);
5900 }
5901 [] RSL.receive { repeat; }
5902 }
5903}
5904
5905/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005906private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005907 var PCUIF_Message first_info;
5908 var integer ts_nr := g_chan_nr.tn;
5909 var integer trx_nr := 0;
5910 var integer bts_nr := 0;
5911 var integer pcu_conn_id := -1;
5912
5913 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5914
5915 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5916 f_sleep(3.0);
5917 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5918
5919 setverdict(pass);
5920
5921}
5922testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5923 var ConnHdlrPars pars;
5924 var ConnHdlr vc_conn;
5925 f_init();
5926
5927 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5928 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5929 vc_conn.done;
5930}
5931
5932/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005933private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005934 var PCUIF_Message first_info;
5935 var integer ts_nr := g_chan_nr.tn;
5936 var integer trx_nr := 0;
5937 var integer bts_nr := 0;
5938 var integer pcu_conn_id := -1;
5939
5940 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5941
5942 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5943 "RSL CHAN ACT");
5944 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5945 "RF CHAN REL", true);
5946 setverdict(pass);
5947}
5948testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5949 var ConnHdlrPars pars;
5950 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005951 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005952
5953 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5954 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5955 vc_conn.done;
5956}
5957
5958/* 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 +07005959private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005960 var PCUIF_Message first_info;
5961 var integer ts_nr := g_chan_nr.tn;
5962 var integer trx_nr := 0;
5963 var integer bts_nr := 0;
5964 var integer pcu_conn_id := -1;
5965
5966 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5967
5968 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5969 "RSL CHAN ACT");
5970
5971 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5972 alt {
5973 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5974 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005976 }
5977 [] RSL.receive { repeat; }
5978 }
5979
5980 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5981 "RF CHAN REL", true);
5982 setverdict(pass);
5983}
5984testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5985 var ConnHdlrPars pars;
5986 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005987 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005988
5989 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5990 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5991 vc_conn.done;
5992}
5993
5994/* 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 +07005995private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005996 var PCUIF_Message first_info;
5997 var integer ts_nr := g_chan_nr.tn;
5998 var integer trx_nr := 0;
5999 var integer bts_nr := 0;
6000 var integer pcu_conn_id := -1;
6001
6002 /* register for the TCH/F channel number */
6003 f_rslem_register(0, g_chan_nr);
6004
6005 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6006
6007 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6008
6009 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6010 "RSL CHAN ACT");
6011
6012 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6013
6014 setverdict(pass);
6015}
6016testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6017 var ConnHdlrPars pars;
6018 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006019 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006020
6021 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6022 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6023 vc_conn.done;
6024}
6025
6026
Harald Welte0472ab42018-03-12 15:02:26 +01006027/***********************************************************************
6028 * LAPDm / RLL related
6029 ***********************************************************************/
6030
6031private function f_tx_lapdm(template (value) LapdmFrame l,
6032 template (value) RslLinkId link_id) runs on ConnHdlr {
6033 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006034 var template (value) SacchL1Header l1h;
6035
6036 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006037 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006038 /* Compose dummy L1 header */
6039 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6040 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 +02006041 } else {
6042 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006043 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 +01006044 }
Harald Welte0472ab42018-03-12 15:02:26 +01006045}
6046
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006047private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006048 uint3_t sapi,
6049 RslLinkId link_id,
6050 octetstring l3,
6051 boolean exp
6052}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006053private type record of RllTestCase RllTestCases;
6054private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6055 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006056 sapi := sapi,
6057 link_id := id,
6058 l3 := l3,
6059 exp := exp
6060}
6061
6062/* execute the same callback function with a set of different parameters (tcs) on a
6063 * variety of logical channels */
6064private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6065 var ConnHdlrPars pars;
6066 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006067 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006068
6069 /* test on each of the channels we have */
6070 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6071 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6072
6073 /* test each of the test cases on the current channel */
6074 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6075 pars.spec.rll := tcs[j];
6076 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6077 vc_conn := f_start_handler(fn, pars);
6078 vc_conn.done;
6079 }
6080 }
6081
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006083}
6084
6085/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6086private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6087 var RllTestCase tc := g_pars.spec.rll;
6088 timer T := 3.0;
6089
6090 f_l1_tune(L1CTL);
6091 RSL.clear;
6092
6093 /* activate the logical channel */
6094 f_est_dchan();
6095 L1CTL.clear;
6096
6097 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6098 T.start;
6099 alt {
6100 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6101 if (tc.exp) {
6102 setverdict(pass);
6103 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006105 }
6106 }
6107 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6108 if (tc.exp) {
6109 setverdict(pass);
6110 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006112 }
6113 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006114 /* We also expect to receive the measurements */
6115 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006116 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006118 }
6119 [not tc.exp] T.timeout {
6120 setverdict(pass);
6121 }
6122 }
6123
6124 f_rsl_chan_deact();
6125 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6126 f_rslem_unregister(0, g_chan_nr);
6127}
6128testcase TC_rll_est_ind() runs on test_CT {
6129 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006130 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006131 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006132 /* normal SAPI0 establishment */
6133 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006134 /* SAPI 3 doesn't support contention resolution */
6135 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6136 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6137 /* normal SAPI3 establishment on main DCCH */
6138 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6139 /* normal SAPI3 establishment on SACCH */
6140 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6141 };
6142 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6143}
6144
6145/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6146private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6147 var RllTestCase tc := g_pars.spec.rll;
6148 var L1ctlDlMessage dl;
6149 timer T := 3.0;
6150
6151 f_l1_tune(L1CTL);
6152 RSL.clear;
6153
6154 /* activate the logical channel */
6155 f_est_dchan();
6156 L1CTL.clear;
6157
6158 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6159 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6160 T.start;
6161 alt {
6162 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6163 var LapdmFrame lapdm;
6164 var octetstring l2 := dl.payload.data_ind.payload;
6165 if (dl.dl_info.link_id.c == SACCH) {
6166 /* remove L1 header */
6167 l2 := substr(l2, 2, lengthof(l2)-2);
6168 }
6169 lapdm.ab := dec_LapdmFrameAB(l2);
6170 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6171 setverdict(pass);
6172 } else {
6173 repeat;
6174 }
6175 }
6176 [] L1CTL.receive { repeat; }
6177 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006179 }
6180 }
6181
6182 f_rsl_chan_deact();
6183 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6184 f_rslem_unregister(0, g_chan_nr);
6185}
6186testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6187 var RllTestCases tcs := {
6188 /* normal SAPI3 establishment on main DCCH */
6189 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6190 };
6191 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6192}
6193testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6194 var RllTestCases tcs := {
6195 /* normal SAPI3 establishment on SACCH */
6196 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6197 }
6198 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6199}
6200
6201/* altstep to receive a LAPDm frame matching the given template */
6202private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6203 var L1ctlDlMessage dl;
6204 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6205 var LapdmFrame lapdm;
6206 var octetstring l2 := dl.payload.data_ind.payload;
6207 if (dl.dl_info.link_id.c == SACCH) {
6208 /* remove L1 header */
6209 l2 := substr(l2, 2, lengthof(l2)-2);
6210 }
6211 if (ischosen(exp.ab)) {
6212 lapdm.ab := dec_LapdmFrameAB(l2);
6213 } else if (ischosen(exp.b4)) {
6214 lapdm.b4 := dec_LapdmFrameB4(l2);
6215 } else if (ischosen(exp.bbis)) {
6216 lapdm.bbis := dec_LapdmFrameBbis(l2);
6217 }
6218 log("Rx LAPDm ", lapdm);
6219 if (match(lapdm, exp)) {
6220 setverdict(pass);
6221 } else {
6222 repeat;
6223 }
6224 }
6225 [] L1CTL.receive { repeat; }
6226}
6227private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6228 timer T := t;
6229 T.start;
6230 alt {
6231 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006233 }
6234 [] as_l1_exp_lapdm(exp);
6235 }
6236}
6237
6238/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6239private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6240 /* send SABM from MS -> BTS */
6241 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6242 /* expect RLL EST IND on Abis */
6243 alt {
6244 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6245 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6246 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006248 }
6249 [] RSL.receive { repeat; }
6250 }
6251 /* expect UA from BTS -> MS */
6252 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6253}
6254
6255/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6256private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6257 var RllTestCase tc := g_pars.spec.rll;
6258
6259 f_l1_tune(L1CTL);
6260 RSL.clear;
6261
6262 /* activate the logical channel */
6263 f_est_dchan();
6264 L1CTL.clear;
6265
6266 /* first establish the link-layer */
6267 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6268
6269 /* then send the DISC */
6270 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6271 /* ... and expect the REL IND on the RSL side */
6272 alt {
6273 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6274 setverdict(pass);
6275 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006276 /* We also expect to receive the measurements */
6277 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006278 }
6279
6280 /* release the channel */
6281 f_rsl_chan_deact();
6282 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6283 f_rslem_unregister(0, g_chan_nr);
6284}
6285testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6286 var RllTestCases tcs := {
6287 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6288 };
6289 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6290}
6291
6292testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6293 var RllTestCases tcs := {
6294 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6295 };
6296 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6297}
6298testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6299 var RllTestCases tcs := {
6300 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6301 };
6302 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6303}
6304testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6305 var RllTestCases tcs := {
6306 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6307 };
6308 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6309}
6310
6311/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6312private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6313 var RllTestCase tc := g_pars.spec.rll;
6314 f_l1_tune(L1CTL);
6315 RSL.clear;
6316
6317 /* activate the logical channel */
6318 f_est_dchan();
6319 L1CTL.clear;
6320
6321 /* first establish the link-layer */
6322 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6323
6324 /* then send the REL REQ via RSL */
6325 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6326 /* ... and expect the DISC on the Um side */
6327 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006328 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006329 /* FIXME: send a UA in resposne to the DISC */
6330 }
6331 }
6332
6333 /* release the channel */
6334 f_rsl_chan_deact();
6335 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6336 f_rslem_unregister(0, g_chan_nr);
6337}
6338testcase TC_rll_rel_req() runs on test_CT {
6339 var RllTestCases tcs := {
6340 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6341 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6342 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6343 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6344 };
6345 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6346}
6347
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006348/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006349testcase TC_rll_data_req() runs on test_CT {
6350}
6351
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006352/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006353testcase TC_rll_data_ind() runs on test_CT {
6354}
6355
6356/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6357private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6358 var RllTestCase tc := g_pars.spec.rll;
6359
6360 f_l1_tune(L1CTL);
6361 RSL.clear;
6362
6363 f_est_dchan();
6364 L1CTL.clear;
6365
6366 /* Send UNITDATA REQ on RSL side */
6367 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6368 /* Expect it to arrive on the other side */
6369 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006370 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006371 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006372 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006373 }
6374
6375 /* release the channel */
6376 f_rsl_chan_deact();
6377 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6378 f_rslem_unregister(0, g_chan_nr);
6379}
6380testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6381 var octetstring l3 := f_rnd_octstring(15);
6382 var RllTestCases tcs := {
6383 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6384 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6385 };
6386 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6387}
6388testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6389 var octetstring l3 := f_rnd_octstring(19);
6390 var RllTestCases tcs := {
6391 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6392 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6393 };
6394 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6395}
6396
6397/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6398private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6399 var RllTestCase tc := g_pars.spec.rll;
6400
6401 f_l1_tune(L1CTL);
6402 RSL.clear;
6403
6404 f_est_dchan();
6405 L1CTL.clear;
6406
6407 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006408 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006409 /* Expdct RLL UNITDATA IND on RSL side */
6410 alt {
6411 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6412 setverdict(pass);
6413 }
6414 [] RSL.receive { repeat; }
6415 }
6416
6417 /* release the channel */
6418 f_rsl_chan_deact();
6419 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6420 f_rslem_unregister(0, g_chan_nr);
6421}
6422testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006423 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006424 var RllTestCases tcs := {
6425 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6426 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6427 };
6428 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6429}
6430testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6431 var octetstring l3 := f_rnd_octstring(18);
6432 var RllTestCases tcs := {
6433 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6434 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6435 };
6436 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6437}
6438
Harald Weltee613f962018-04-18 22:38:16 +02006439/***********************************************************************
6440 * Encryption Related
6441 ***********************************************************************/
6442
6443/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006444private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006445 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6446 if (link_id.c == SACCH) {
6447 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6448 } else {
6449 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6450 }
6451}
6452
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006453/* Expect (or not expect) other kinds of messages */
6454private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6455 [exp_any] RSL.receive { repeat; }
6456 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006458 }
6459}
6460
Harald Weltee613f962018-04-18 22:38:16 +02006461/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006462private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006463 RslLinkId link_id,
6464 octetstring l3,
6465 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006466 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006467) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006468 timer T := 3.0;
6469 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6470 T.start;
6471 /* Expect RLL UNITDATA IND on RSL side */
6472 alt {
6473 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6474 setverdict(pass);
6475 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006476 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006477 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006478 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006480 }
Harald Weltee613f962018-04-18 22:38:16 +02006481 }
6482}
6483
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006484/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6485private function f_data_mo(
6486 RslLinkId link_id,
6487 boolean p, uint3_t nr, uint3_t ns,
6488 octetstring l3,
6489 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006490 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006491) runs on ConnHdlr {
6492 timer T := 3.0;
6493 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6494 T.start;
6495 /* Expect RLL DATA IND on RSL side */
6496 alt {
6497 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6498 setverdict(pass);
6499 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006500 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006501 [] as_rsl_any_ind(exp_any);
6502 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006504 }
6505 }
6506}
6507
Harald Weltee613f962018-04-18 22:38:16 +02006508/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006509private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006510 f_l1_tune(L1CTL);
6511 f_est_dchan(true);
6512
6513 /* now we actually need to transmit some data both ways to check if the encryption works */
6514 var L1ctlDlMessage dl;
6515
Stefan Sperling603d98e2018-07-25 16:47:28 +02006516 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006517 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6518
6519 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6520 f_unitdata_mt(link_id, l3);
6521
6522 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6523 f_unitdata_mo(link_id, l3);
6524
6525 /* release the channel */
6526 f_rsl_chan_deact();
6527 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6528 f_rslem_unregister(0, g_chan_nr);
6529}
6530testcase TC_chan_act_a51() runs on test_CT {
6531 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6532 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6533 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6534}
6535testcase TC_chan_act_a52() runs on test_CT {
6536 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6537 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6538 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6539}
6540testcase TC_chan_act_a53() runs on test_CT {
6541 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6542 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6543 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6544}
6545
Eric Wildf1827a72019-05-28 17:37:35 +02006546/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6547 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 +07006548private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006549 f_l1_tune(L1CTL);
6550 f_est_dchan(true);
6551
6552 /* now we actually need to transmit some data both ways to check if the encryption works */
6553 var L1ctlDlMessage dl;
6554
6555 var octetstring l3 := f_rnd_octstring(20);
6556 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6557
6558 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6559 f_unitdata_mt(link_id, l3);
6560
6561 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6562 f_unitdata_mo(link_id, l3);
6563
6564 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006565 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006566
6567 /* modify key to break proper encryption */
6568 g_pars.encr.key := f_rnd_octstring(8);
6569 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6570 rsl.ies := rsl.ies & { ei };
6571 RSL.send(rsl);
6572
6573 timer T0 := 1.0;
6574 T0.start;
6575 /* Expect RSL MODIFY ACK */
6576 alt {
6577 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6578 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6580 }
6581 [] T0.timeout {
6582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6583 }
6584 }
6585
6586 var octetstring l3msg := f_rnd_octstring(15);
6587 timer T1 := 3.0;
6588 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6589 due to broken encryption */
6590 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6591 T1.start;
6592 alt {
6593 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6595 }
6596 [] T1.timeout {
6597 setverdict(pass);
6598 }
6599 }
6600
6601 /* release the channel */
6602 f_rsl_chan_deact();
6603 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6604 f_rslem_unregister(0, g_chan_nr);
6605}
6606testcase TC_rsl_modify_encr() runs on test_CT {
6607 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6608 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6609 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6610}
Harald Weltee613f962018-04-18 22:38:16 +02006611
6612/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006613private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006614 /* L3 payload doesn't matter, as it is passed transparently */
6615 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6616 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6617 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6618
6619 f_l1_tune(L1CTL);
6620
6621 /* first establish a dedicated channel in the clear */
6622 f_est_dchan(false);
6623
6624 /* Establish ABM */
6625 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6626
6627 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6628 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6629 /* expect the L3 to arrive still unencrypted on the MS side */
6630 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6631
6632 /* configure L1 to apply ciphering */
6633 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6634 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6635
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006636 /* send first ciphered I-frame in response and expect it on RSL */
6637 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006638
6639 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6640 * and hence enable encryption also on the downlink */
6641
6642 /* expect bi-directional communication work in encrypted mode */
6643 f_unitdata_mo(link_id, f_rnd_octstring(15));
6644 f_unitdata_mt(link_id, f_rnd_octstring(15));
6645
6646 /* release the channel */
6647 f_rsl_chan_deact();
6648 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6649 f_rslem_unregister(0, g_chan_nr);
6650}
6651testcase TC_encr_cmd_a51() runs on test_CT {
6652 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6653 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6654 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6655}
6656testcase TC_encr_cmd_a52() runs on test_CT {
6657 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6658 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6659 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6660}
6661testcase TC_encr_cmd_a53() runs on test_CT {
6662 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6663 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6664 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6665}
6666
6667private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6668 var LapdmFrame lf;
6669 var octetstring reenc;
6670
6671 /* decode the LAPDm frame */
6672 if (ischosen(exp_match.ab)) {
6673 lf.ab := dec_LapdmFrameAB(enc);
6674 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006676 }
6677
6678 /* check if decoder result matches expectation */
6679 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006681 } else {
6682 log(name, ": matched");
6683 setverdict(pass);
6684 }
6685
6686 /* test if re-encoded frame equals original input */
6687 reenc := enc_LapdmFrame(lf);
6688 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006690 } else {
6691 setverdict(pass);
6692 }
6693}
6694
6695testcase TC_lapdm_selftest() runs on test_CT {
6696 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6697 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6698 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6699 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6700 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6701 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6702 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6703}
6704
Stefan Sperling4880be42018-08-07 18:12:59 +02006705/***********************************************************************
6706 * DTX Related (see GSM 05.08, section 8.3)
6707 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006708private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006709 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006710 var GsmFrameNumber first_fn;
6711 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006712 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006713 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006714 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6715 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006716 const integer frame_dtx_tchf_mod := 104;
6717 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6718 * which operates in terms of blocks rather than frames. */
6719 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6720 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006721 timer T := 5.0;
6722
6723 f_l1_tune(L1CTL);
6724 RSL.clear;
6725 L1CTL.clear;
6726
6727 /* activate TCHF signalling channel */
6728 f_est_dchan(false);
6729
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006730 /* A template for matching dummy LAPDm func=UA frames */
6731 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6732 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6733 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6734
Stefan Sperling4880be42018-08-07 18:12:59 +02006735 T.start;
6736 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006737 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006738 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006739
6740 if (is_first_frame) {
6741 is_first_frame := false;
6742 first_fn := dl.dl_info.frame_nr;
6743 }
6744
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006745 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006746 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006747 T.stop;
6748 f_rsl_chan_deact();
6749 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006750
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006751 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6752 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006753
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006754 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006755 setverdict(fail, "Not enough fill frames received: ",
6756 nfill_frames, " out of ", expected_fill_frames);
6757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006758 } else {
6759 setverdict(pass);
6760 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006761 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006762 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6763 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6764 * we should only see the subset of frames numbers which correspond to a block boundary.
6765 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6766 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6767 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006768 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006769 repeat;
6770 }
6771 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006772 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6773 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6774 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006775 f_rsl_chan_deact();
6776 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006777 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006778 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006779 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006780 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006781 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006782
6783 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006784 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6785 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006786 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6787 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6788 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006789 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6790 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006791 case else {
6792 /* This shall not happen, just to be sure */
6793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6794 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006795 }
6796
6797 f_rsl_chan_deact();
6798 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006799
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006800 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006801 setverdict(pass);
6802 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006803 setverdict(fail, "Not enough fill frames received: ",
6804 nfill_frames, " out of ", expected_fill_frames);
6805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006806 }
6807 } else {
6808 repeat;
6809 }
6810 }
6811 }
6812 [] L1CTL.receive { repeat; }
6813 [] T.timeout {
6814 f_rsl_chan_deact();
6815 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006817 }
6818 }
6819}
6820
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006821private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006822 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006823 var ConnHdlr vc_conn;
6824 var ConnHdlrPars pars;
6825 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006826 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006827 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006828 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006829 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006830 if (dtxd) {
6831 if (i >= 4) { /* DTX is only allowed on TCH/F */
6832 break;
6833 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006834 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006835 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006836 vc_conn.done;
6837 }
6838}
6839
6840/* Verify that L2 fill frames are sent on TCH in signaling mode if
6841 * there is nothing to transmit while DTX is disabled on downlink. */
6842testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6843 f_tch_sign_l2_fill_frame(false);
6844}
6845
6846/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6847 * there is nothing to transmit while DTX is enabled on downlink. */
6848testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6849 f_tch_sign_l2_fill_frame(true);
6850}
Harald Welte0472ab42018-03-12 15:02:26 +01006851
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006852testcase TC_chopped_ipa_ping() runs on test_CT {
6853 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6854}
6855
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006856testcase TC_chopped_ipa_payload() runs on test_CT {
6857 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6858}
6859
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006860
6861/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6862 * Return value: Measurement Report to be sent (encoded octetstring). */
6863type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6864 runs on ConnHdlr return octetstring;
6865
6866private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6867runs on ConnHdlr {
6868 var L1ctlDlMessage l1_dl;
6869 var SacchL1Header l1h;
6870 var octetstring l2;
6871
6872 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6873 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6874 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6875 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6876
6877 /* Pass it to the user specified call-back function */
6878 l2 := cb.apply(l1h, num_blocks);
6879 /* Send a Measurement Report generated by the call-back */
6880 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6881 l1_dl.dl_info.link_id,
6882 l1h, l2));
6883
6884 /* Shall we keep going? */
6885 num_blocks := num_blocks - 1;
6886 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6887 if (num_blocks > 0) { repeat; }
6888 }
6889 [] L1CTL.receive { repeat; }
6890}
6891
6892private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6893runs on ConnHdlr return octetstring {
6894 /* Command the L1 to apply received parameters */
6895 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6896
6897 /* Dummy measurement report (the results are invalid) */
6898 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6899}
6900
6901private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6902runs on ConnHdlr return octetstring {
6903 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6904 setverdict(fail, "Unexpected MS Power level change: ",
6905 g_pars.l1_pars.ms_power_level, " -> ",
6906 l1h.ms_power_lvl);
6907 }
6908
6909 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6910}
6911
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006912private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6913runs on ConnHdlr return octetstring {
6914 /* UL RSSI oscillation driven by SACCH block number */
6915 if (num_blocks rem 2 == 0) {
6916 f_trxc_fake_rssi(-100);
6917 } else {
6918 f_trxc_fake_rssi(-50);
6919 }
6920
6921 /* Make sure that MS power level remains constant */
6922 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6923}
6924
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006925/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6926private function f_TC_ms_pwr_ctrl_constant(charstring id)
6927runs on ConnHdlr {
6928 var integer num_blocks := 8;
6929 timer T := int2float(num_blocks);
6930
6931 f_l1_tune(L1CTL);
6932 RSL.clear;
6933
6934 /* These IEs are needed for autonomous MS power control */
6935 var template (value) RSL_IE_List ies := {
6936 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6937 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6938 }),
6939 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6940 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6941 })
6942 };
6943
6944 /* Ensure that 'rx-current' equals 'rx-target' */
6945 f_trxc_fake_rssi(mp_uplink_power_target);
6946
6947 /* Establish a dedicated channel */
6948 f_est_dchan(more_ies := valueof(ies));
6949
6950 L1CTL.clear;
6951 T.start;
6952 alt {
6953 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6954 [] T.timeout {
6955 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6956 num_blocks, " were not handled");
6957 }
6958 }
6959}
6960testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6961 var ConnHdlr vc_conn;
6962 var ConnHdlrPars pars;
6963
6964 f_init();
6965
6966 /* Explicitly configure the Uplink power target (in dBm) */
6967 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6968
6969 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6970 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6971 log(testcasename(), ": starting on ", pars.chan_nr);
6972
6973 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6974 pars, trxc_comp := true);
6975 vc_conn.done;
6976 }
6977
6978 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6980}
6981
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006982/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
6983private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
6984runs on ConnHdlr {
6985 var integer num_blocks := 16;
6986 timer T := int2float(num_blocks);
6987
6988 f_l1_tune(L1CTL);
6989 RSL.clear;
6990
6991 /* These IEs are needed for autonomous MS power control */
6992 var template (value) RSL_IE_List ies := {
6993 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6994 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6995 }),
6996 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6997 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6998 })
6999 };
7000
7001 /* Ensure that 'rx-current' equals 'rx-target' */
7002 f_trxc_fake_rssi(mp_uplink_power_target);
7003
7004 /* Establish a dedicated channel */
7005 f_est_dchan(more_ies := valueof(ies));
7006
7007 L1CTL.clear;
7008 T.start;
7009 alt {
7010 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7011 [] T.timeout {
7012 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7013 num_blocks, " were not handled");
7014 }
7015 }
7016}
7017testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7018 var ConnHdlr vc_conn;
7019 var ConnHdlrPars pars;
7020
7021 f_init();
7022
7023 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7024 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7025 /* Explicitly configure the Uplink power range (target and delte) */
7026 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7027 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7028
7029 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7030 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7031 log(testcasename(), ": starting on ", pars.chan_nr);
7032
7033 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7034 pars, trxc_comp := true);
7035 vc_conn.done;
7036 }
7037
7038 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7040}
7041
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007042private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7043 var template L1ctlDlMessage tr_bad_frame;
7044 var L1ctlDlMessage l1_dl;
7045 timer T := 8.0;
7046
7047 f_l1_tune(L1CTL);
7048 RSL.clear;
7049
7050 f_est_dchan();
7051
7052 /* There may be a few errors right after the channel activation */
7053 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7054 L1CTL.clear;
7055
7056 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7057 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7058 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7059 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7060 tr_bad_frame.payload := ?;
7061
7062 T.start;
7063 alt {
7064 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7065 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7066 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7067 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7068 }
7069 [] as_l1_sacch();
7070 [] L1CTL.receive { repeat; }
7071 [] T.timeout {
7072 /* We're done, break the loop */
7073 setverdict(pass);
7074 }
7075 }
7076
7077 f_rsl_chan_deact();
7078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7079}
7080testcase TC_speech_no_rtp_tchf() runs on test_CT {
7081 var ConnHdlr vc_conn;
7082 var ConnHdlrPars pars;
7083
7084 f_init();
7085
7086 /* TS1, TCH/F, V1 (FR codec) */
7087 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7088 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7089 vc_conn.done;
7090}
7091testcase TC_speech_no_rtp_tchh() runs on test_CT {
7092 var ConnHdlr vc_conn;
7093 var ConnHdlrPars pars;
7094
7095 f_init();
7096
7097 /* TS5, TCH/H, V1 (HR codec) */
7098 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7099 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7100 vc_conn.done;
7101}
7102
Harald Welte0472ab42018-03-12 15:02:26 +01007103/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7104/* protocol error as per 44.006 */
7105/* link layer failure (repetition of I-frame N200 times without ACK */
7106/* repetition of SABM or DISC N200 times without ACK */
7107/* receptiom of SABM in multi-frame established state */
7108
7109
Harald Welte68e495b2018-02-25 00:05:57 +01007110/* TODO Areas:
7111
7112* channel activation
7113** with BS_Power / MS_Power, bypassing power control loop
7114** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007115** with timing advance from initial activation on
7116* mode modify
7117** encryption
7118** multirate
7119* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007120** unsupported algorithm
7121* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007122* BS Power Control
7123* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007124* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007125* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007126** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007127* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007128** DATA_IND from BTS->PCU
7129** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007130
7131*/
Harald Welte70767382018-02-21 12:16:40 +01007132
7133control {
7134 execute( TC_chan_act_stress() );
7135 execute( TC_chan_act_react() );
7136 execute( TC_chan_deact_not_active() );
7137 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007138 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007139 execute( TC_sacch_filling() );
7140 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007141 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007142 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007143 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007144 execute( TC_sacch_chan_act_ho_async() );
7145 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007146 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007147 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007148 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007149 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007150 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007151 execute( TC_rach_load_idle_thresh0() );
7152 execute( TC_rach_load_idle_below_thresh() );
7153 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007154 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007155 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007156 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007157 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007158 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007159 execute( TC_meas_res_sign_tchf() );
7160 execute( TC_meas_res_sign_tchh() );
7161 execute( TC_meas_res_sign_sdcch4() );
7162 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007163 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007164 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007165 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007166 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007167 execute( TC_rsl_bs_pwr_static_ass() );
7168 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007169 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007170 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007171 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007172 execute( TC_rsl_ms_pwr_dyn_up() );
7173 execute( TC_rsl_ms_pwr_dyn_down() );
7174 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7175 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007176 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007177 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007178 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007179 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007180 execute( TC_paging_imsi_80percent() );
7181 execute( TC_paging_tmsi_80percent() );
7182 execute( TC_paging_imsi_200percent() );
7183 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007184 execute( TC_rsl_protocol_error() );
7185 execute( TC_rsl_mand_ie_error() );
7186 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007187 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007188 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007189 execute( TC_si_sched_2bis() );
7190 execute( TC_si_sched_2ter() );
7191 execute( TC_si_sched_2ter_2bis() );
7192 execute( TC_si_sched_2quater() );
7193 execute( TC_si_sched_13() );
7194 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007195 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007196 execute( TC_ipa_crcx_twice_not_active() );
7197 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007198 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007199 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007200
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007201 if (mp_pcu_socket != "") {
7202 execute( TC_pcu_act_req() );
7203 execute( TC_pcu_act_req_wrong_ts() );
7204 execute( TC_pcu_act_req_wrong_bts() );
7205 execute( TC_pcu_act_req_wrong_trx() );
7206 execute( TC_pcu_deact_req() );
7207 execute( TC_pcu_deact_req_wrong_ts() );
7208 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007209 if (mp_l1_supports_gprs) {
7210 execute( TC_pcu_data_req_pdtch() );
7211 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007212 execute( TC_pcu_data_req_wrong_bts() );
7213 execute( TC_pcu_data_req_wrong_trx() );
7214 execute( TC_pcu_data_req_wrong_ts() );
7215 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007216 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007217 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007218 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007219 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007220 execute( TC_pcu_data_req_imm_ass_pch() );
7221 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007222 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007223 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007224 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007225 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007226 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007227 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007228 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007229 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007230 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007231 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007232 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007233 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007234 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007235 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007236 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007237 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007238 execute( TC_dyn_osmo_pdch_act_deact() );
7239 execute( TC_dyn_osmo_pdch_double_act() );
7240 execute( TC_dyn_ipa_pdch_act_deact() );
7241 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7242
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007243 if (PCUIF_Types.mp_pcuif_version >= 10) {
7244 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007245 execute( TC_pcu_socket_nsvc_ipv4() );
7246 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007247 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007248 } else {
7249 log("PCU socket path not available, skipping PCU tests");
7250 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007251
Harald Welte3d04ae62018-04-04 20:29:05 +02007252 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007253 execute( TC_dyn_osmo_pdch_tchf_act() );
7254 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007255 execute( TC_dyn_ipa_pdch_tchf_act() );
7256 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007257
7258 execute( TC_rll_est_ind() );
7259 execute( TC_rll_est_req_DCCH_3() );
7260 execute( TC_rll_est_req_ACCH_3() );
7261 execute( TC_rll_rel_ind_DCCH_0() );
7262 execute( TC_rll_rel_ind_DCCH_3() );
7263 execute( TC_rll_rel_ind_ACCH_0() );
7264 execute( TC_rll_rel_ind_ACCH_3() );
7265 execute( TC_rll_rel_req() );
7266 execute( TC_rll_unit_data_req_DCCH() );
7267 execute( TC_rll_unit_data_req_ACCH() );
7268 execute( TC_rll_unit_data_ind_DCCH() );
7269 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007270
7271 execute( TC_chan_act_a51() );
7272 execute( TC_chan_act_a52() );
7273 execute( TC_chan_act_a53() );
7274 execute( TC_encr_cmd_a51() );
7275 execute( TC_encr_cmd_a52() );
7276 execute( TC_encr_cmd_a53() );
7277
Harald Welteee25aae2019-05-19 14:32:37 +02007278 execute( TC_err_rep_wrong_mdisc() );
7279 execute( TC_err_rep_wrong_msg_type() );
7280 execute( TC_err_rep_wrong_sequence() );
7281
Harald Weltee613f962018-04-18 22:38:16 +02007282 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007283
7284 execute( TC_tch_sign_l2_fill_frame() );
7285 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007286
7287 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007288 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007289
7290 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007291 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007292
7293 execute( TC_speech_no_rtp_tchf() );
7294 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007295}
7296
7297
7298}