blob: f010c1b6ab034782f9599f8f9924134b9549f48f [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;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100109 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200110 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200111 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200112 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
113 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700114 /* how many transceivers do we expect to connect */
115 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700116 /* frequency hopping status */
117 boolean mp_freq_hop_enabled := false;
118 /* frequency hopping parameters */
119 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100120}
121
Harald Welte629cc6b2018-03-11 17:19:05 +0100122type record of RslChannelNr ChannelNrs;
123
Harald Welte70767382018-02-21 12:16:40 +0100124type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100125 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100126 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100128 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100129 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100130 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100131
132 /* L1CTL port (for classic tests) */
133 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100134
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700135 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700136 port TRXC_CODEC_PT BTS_TRXC;
137 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100138
Harald Weltef50e3ae2018-09-10 10:27:56 +0200139 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100140 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200141 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100142
Harald Welte883340c2018-02-28 18:59:29 +0100143 /* PCU Interface of BTS */
144 port PCUIF_CODEC_PT PCU;
145 var integer g_pcu_conn_id;
146 /* Last PCU INFO IND we received */
147 var PCUIF_Message g_pcu_last_info;
148
Harald Welte48494ca2018-02-25 16:59:50 +0100149 /* SI configuration */
150 var SystemInformationConfig si_cfg := {
151 bcch_extended := false,
152 si1_present := false,
153 si2bis_present := false,
154 si2ter_present := false,
155 si2quater_present := false,
156 si7_present := false,
157 si8_present := false,
158 si9_present := false,
159 si13_present := false,
160 si13alt_present := false,
161 si15_present := false,
162 si16_present := false,
163 si17_present := false,
164 si2n_present := false,
165 si21_present := false,
166 si22_present := false
167 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100168
169 /* all logical channels available on the BTS */
170 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100171 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100172}
173
174/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200175type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100176 port L1CTL_PT L1CTL;
177
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700178 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700179 port TRXC_CODEC_PT BTS_TRXC;
180 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200182 /* port to be initialized optionally to access BSC VTY */
183 port TELNETasp_PT BSCVTY;
184
Harald Welte70767382018-02-21 12:16:40 +0100185 timer g_Tguard;
186 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
187
188 var ConnHdlrPars g_pars;
189 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100190 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200191
192 /* PCU Interface of BTS */
193 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700196private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700197 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200198 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700199 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200200 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700201 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200202 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700203 timer T;
204
Harald Welte70767382018-02-21 12:16:40 +0100205 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
206 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
207
208 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
209 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
210 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
211
212 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
213 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700214
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700216 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700217 T.start(mp_ipa_up_timeout);
218 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700219 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700220 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
221 /* Make sure that all transceivers use unique stream ID */
222 if (trx_mask[enum2int(ev.sid)] == '1'B) {
223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
224 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
225 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700226
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 trx_mask[enum2int(ev.sid)] := '1'B;
228 trx_count := trx_count + 1;
229
230 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200231 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700232 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200233 /* This message (RF RESource INDication) is sent by the IUT itself */
234 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
235 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
237 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
238 }
239 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
241 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
242 }
243
244 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
245 rfind_count := rfind_count + 1;
246 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
247 if (rfind_count < mp_transceiver_num) { repeat; }
248 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
250 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
251 [] T.timeout {
252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
253 "Timeout waiting for RSL bring up");
254 }
255 }
Harald Welte70767382018-02-21 12:16:40 +0100256}
257
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700258friend type record FreqHopPars {
259 /* Whether frequency hopping is in use */
260 boolean enabled,
261 /* Mobile Allocation Index Offset / Hopping Sequence Number */
262 MaioHsn maio_hsn,
263 /* MA bitmap to be indicated in RR Immediate Assignment */
264 MobileAllocationLV ma_map,
265 /* The actual Mobile Allocation (ARFCN list) to be used */
266 L1ctlMA ma
267};
268
Harald Welte70767382018-02-21 12:16:40 +0100269type record ConnHdlrPars {
270 RslChannelNr chan_nr,
271 RSL_IE_ChannelMode chan_mode,
272 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100273 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200274 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200275 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700276 BtsBand bts0_band optional,
277
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700278 /* Frequency hopping parameters */
279 FreqHopPars fhp
280};
Harald Welte0472ab42018-03-12 15:02:26 +0100281
282/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700283private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100284 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100285}
286
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700287private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100288 max_retrans := RACH_MAX_RETRANS_7,
289 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100290 cell_barr_access := false,
291 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100292 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100293};
294
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700295private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100296 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200297 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100298 acs := '0'B,
299 neci := true,
300 rxlev_access_min := 0
301}
302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700303private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100304 mcc_mnc := '262F42'H,
305 lac := 42
306}
307
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700308private template (value) GPRSIndicator ts_GPRSIndicator_def := {
309 ra_colour := 0,
310 si13_pos := '0'B
311}
312
313private template (value) SI3RestOctets ts_SI3RestOctets_def
314modifies ts_SI3RestOctets := {
315 gprs_ind := {
316 presence := CSN1_H,
317 ind := ts_GPRSIndicator_def
318 }
319}
320
321private template (value) SI4RestOctets ts_SI4RestOctets_def
322modifies ts_SI4RestOctets := {
323 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700324 presence := CSN1_H,
325 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700326 }
327}
328
Harald Welte7484fc42018-02-24 14:09:45 +0100329/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700330private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100331 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100332 payload := {
333 si3 := {
334 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100336 ctrl_chan_desc := {
337 msc_r99 := true,
338 att := true,
339 bs_ag_blks_res := 1,
340 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100341 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100342 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
343 spare := '00'B,
344 bs_pa_mfrms := 0, /* 2 multiframes */
345 t3212 := 1 /* 6 minutes */
346 },
Harald Welte82ccef72018-02-25 16:17:33 +0100347 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100348 dn_ind := false,
349 pwrc := false,
350 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100351 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100352 },
Harald Weltef10153f2018-02-25 16:34:05 +0100353 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100354 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200355 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100356 }
357 }
358}
Harald Welte70767382018-02-21 12:16:40 +0100359
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700360private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100361 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100362 payload := {
363 si2 := {
364 bcch_freq_list := '00000000000000000000000000000000'O,
365 ncc_permitted := '11111111'B,
366 rach_control := ts_RachCtrl_default
367 }
368 }
369}
370
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100373 payload := {
374 si4 := {
375 lai := ts_LAI_default,
376 cell_sel_par := ts_CellSelPar_default,
377 rach_control := ts_RachCtrl_default,
378 cbch_chan_desc := omit,
379 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200380 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100381 }
382 }
383}
384
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700385private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100386runs on test_CT {
387 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700388 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100389}
390
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700391private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100392runs on test_CT {
393 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
394 log("Setting ", rsl_si_type, ": ", si_dec);
395 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
396}
397
Harald Welte505cf9b2018-09-15 17:47:23 +0300398friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100399 map(self:BTSVTY, system:BTSVTY);
400 f_vty_set_prompts(BTSVTY);
401 f_vty_transceive(BTSVTY, "enable");
402}
403
Harald Welte505cf9b2018-09-15 17:47:23 +0300404friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200405 map(self:BSCVTY, system:BSCVTY);
406 f_vty_set_prompts(BSCVTY, "OsmoBSC");
407 f_vty_transceive(BSCVTY, "enable");
408}
409
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200410friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
411 map(self:BSCVTY, system:BSCVTY);
412 f_vty_set_prompts(BSCVTY, "OsmoBSC");
413 f_vty_transceive(BSCVTY, "enable");
414}
415
Harald Welte883340c2018-02-28 18:59:29 +0100416/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200417private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
418 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100419 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200420 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
421 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100422 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200423 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100425 }
426}
427
Harald Weltef26de0b2018-04-04 20:28:05 +0200428private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
429 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100430 timer T := 2.0;
431 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100432 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200433 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100434 return;
435 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200436 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100437
438 T.start;
439 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200440 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100441 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100443 }
444 }
445}
446
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700447private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
448 out integer trxc_conn_id) {
449 var Result res;
450
451 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
452 "", -1, -1, { udp := {} }, {});
453 if (not ispresent(res.connId)) {
454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
455 "Could not connect to the control (TRXC) interface " &
456 "of FakeTRX, check your configuration");
457 }
458 trxc_conn_id := res.connId;
459}
460
Harald Welte70767382018-02-21 12:16:40 +0100461/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700462friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200463 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100464 g_AllChannels := {
465 /* TS 1..4: TCH/F */
466 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
467 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
468 /* TS 5: TCH/H */
469 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
470 /* TS 0: SDCCH/4 */
471 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
472 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
473 /* TS 6: SDCCH/8 */
474 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
475 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
476 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
477 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
478 };
479
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200480 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700481 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200482 g_AllChanTypes := {
483 /* TS 1..4: TCH/F */
484 valueof(ts_RslChanNr_Bm(1)),
485 /* TS 5: TCH/H */
486 valueof(ts_RslChanNr_Lm(5,1)),
487 /* TS 0: SDCCH/4 */
488 valueof(ts_RslChanNr_SDCCH4(0,2)),
489 /* TS 6: SDCCH/8 */
490 valueof(ts_RslChanNr_SDCCH8(6,4))
491 };
492 } else {
493 g_AllChanTypes := {
494 /* TS 1..4: TCH/F */
495 valueof(ts_RslChanNr_Bm(1)),
496 /* TS 0: SDCCH/4 */
497 valueof(ts_RslChanNr_SDCCH4(0,2)),
498 /* TS 6: SDCCH/8 */
499 valueof(ts_RslChanNr_SDCCH8(6,4))
500 };
501 }
Harald Welte70767382018-02-21 12:16:40 +0100502 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100503 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100504 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200505 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100506
507 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100508 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
509 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
510 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100512
Harald Weltef26de0b2018-04-04 20:28:05 +0200513 map(self:PCU, system:PCU);
514 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100515
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700516 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100517 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700518
519 /* Init TRXC interface to FakeTRX */
520 map(self:BTS_TRXC, system:BTS_TRXC);
521 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
522
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700523 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700524 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 +0700525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700526 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
527 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100528 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200529
530 /* Wait some extra time to make sure the BTS emits a stable carrier.
531 * (this is only relevant when running the tests with a physical BTS.) */
532 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100533}
534
Harald Welte68e495b2018-02-25 00:05:57 +0100535/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700536friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100537 map(self:L1CTL, system:L1CTL);
538 f_connect_reset(L1CTL);
539}
540
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700541private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100542
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700543private type record length(8) of FreqHopGroups FreqHopConfig;
544
545private type record of FreqHopGroup FreqHopGroups;
546private type record FreqHopGroup {
547 uint6_t hsn,
548 FreqHopGroupItems trx_maio
549};
550
551private type record of FreqHopGroupItem FreqHopGroupItems;
552private type record FreqHopGroupItem {
553 uint8_t trx_nr,
554 uint6_t maio
555};
556
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700557friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
558 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700559{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700560 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700561 var integer i, j;
562
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700563 fhp.enabled := false;
564
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700565 for (i := 0; i < lengthof(groups); i := i + 1) {
566 var FreqHopGroup g := groups[i];
567 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
568 var FreqHopGroupItem gi := g.trx_maio[j];
569 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700570 fhp.maio_hsn.maio := gi.maio;
571 fhp.maio_hsn.hsn := g.hsn;
572 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700573 break;
574 }
575 }
576
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700577 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700578 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700579 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
580 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
581 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700582
583 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700584 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
585 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700586 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
587 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700588 }
589
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700590 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700591 break; /* We're done */
592 }
593 }
594}
595
Harald Welte70767382018-02-21 12:16:40 +0100596/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700597friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
598 boolean pcu_comp := false,
599 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100600runs on test_CT return ConnHdlr {
601 var charstring id := testcasename();
602 var ConnHdlr vc_conn;
603
604 vc_conn := ConnHdlr.create(id);
605 /* connect to RSL Emulation main component */
606 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
607 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700608
609 /* The ConnHdlr component may want to talk to some ports directly,
610 * so we disconnect it from the test_CT and connect it to the component.
611 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200612 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 unmap(self:PCU, system:PCU);
614 map(vc_conn:PCU, system:PCU);
615 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700616 if (trxc_comp) {
617 unmap(self:BTS_TRXC, system:BTS_TRXC);
618 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
619 }
Harald Welte70767382018-02-21 12:16:40 +0100620
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700621 /* Obtain frequency hopping parameters for a given timeslot */
622 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700623 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624 }
625
Harald Welte70767382018-02-21 12:16:40 +0100626 vc_conn.start(f_handler_init(fn, id, pars));
627 return vc_conn;
628}
629
Harald Welte70767382018-02-21 12:16:40 +0100630private altstep as_Tguard() runs on ConnHdlr {
631 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100633 }
634}
635
Harald Welte990a3612019-05-27 14:02:13 +0200636friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
637 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100638}
639
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700640private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100641 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700642 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700645private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100646 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700647 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100648}
649
650/* first function started in ConnHdlr component */
651private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
652runs on ConnHdlr {
653 g_pars := pars;
654 g_chan_nr := pars.chan_nr;
655
656 map(self:L1CTL, system:L1CTL);
657 f_connect_reset(L1CTL);
658
Harald Welted48c0c72019-06-05 10:01:15 +0200659 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700660 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100661 }
Harald Welte70767382018-02-21 12:16:40 +0100662
663 g_Tguard.start(pars.t_guard);
664 activate(as_Tguard());
665
666 f_rslem_register(0, pars.chan_nr);
667
668 /* call the user-supplied test case function */
669 fn.apply(id);
670}
671
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700672private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
673 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200674runs on ConnHdlr return RSL_Message {
675 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100676 timer T := 3.0;
677 RSL.send(tx);
678 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100679 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200680 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100681 T.stop;
682 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100683 }
Harald Welte1eba3742018-02-25 12:48:14 +0100684 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100686 }
Harald Welte21240e62018-03-11 21:43:35 +0100687 [not ignore_other] as_l1_sacch();
688 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700689 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700690 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100691 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100693 }
Harald Welte21240e62018-03-11 21:43:35 +0100694 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100695 }
Harald Welteb1726c92018-03-30 11:56:38 +0200696 return rx;
697}
698
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700699friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
700 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200701runs on ConnHdlr {
702 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100703}
704
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700705friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
706 boolean encr_enable := false,
707 RSL_IE_List more_ies := {},
708 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
709runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200710 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200711 if (encr_enable) {
712 /* append encryption related IEs, if requested */
713 var RSL_IE_EncryptionInfo encr_info;
714 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
715 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
716encr_info})) };
717 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200718 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200719 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100720}
721
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700722friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100723 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 +0100724 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100725}
726
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700727/* Default Mobile Allocation to be used for frequency hopping */
728private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
729 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
730
Harald Welte2f2b2b72019-05-31 22:24:57 +0200731friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100732 template RSL_IE_ChannelMode chan_mode,
733 float t_guard := 20.0) := {
734 chan_nr := valueof(chan_nr),
735 chan_mode := valueof(chan_mode),
736 t_guard := t_guard,
737 l1_pars := {
738 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100739 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100740 meas_ul := {
741 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200742 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100743 rxqual := 0
744 },
745 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200746 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100747 rxqual := 0
748 }
749 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200750 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100751 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200752 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200753 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100754 },
Harald Weltee613f962018-04-18 22:38:16 +0200755 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200756 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700757 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700758 fhp := {
759 enabled := false,
760 maio_hsn := ts_HsnMaio(0, 0),
761 ma_map := c_MA_null,
762 ma := l1ctl_ma_def
763 }
Harald Welte70767382018-02-21 12:16:40 +0100764}
765
Harald Welte93640c62018-02-25 16:59:33 +0100766/***********************************************************************
767 * Channel Activation / Deactivation
768 ***********************************************************************/
769
Harald Welte70767382018-02-21 12:16:40 +0100770/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700771private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100772 for (var integer i := 0; i < 500; i := i+1) {
773 f_rsl_chan_act(g_pars.chan_mode);
774 f_rsl_chan_deact();
775 }
776 setverdict(pass);
777}
778testcase TC_chan_act_stress() runs on test_CT {
779 var ConnHdlr vc_conn;
780 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200781 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100782 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
783 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100785}
786
787/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700788private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100789 f_rsl_chan_act(g_pars.chan_mode);
790 /* attempt to activate the same lchan again -> expect reject */
791 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
792 alt {
793 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100795 }
796 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
797 setverdict(pass);
798 }
799 }
800 f_rsl_chan_deact();
801}
802testcase TC_chan_act_react() runs on test_CT {
803 var ConnHdlr vc_conn;
804 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100805 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100806 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
807 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100809}
810
811/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700812private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100813 timer T := 3.0;
814 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
815 T.start;
816 alt {
817 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
818 setverdict(pass);
819 }
820 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100822 }
823 }
824}
825testcase TC_chan_deact_not_active() runs on test_CT {
826 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100827 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100828 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
829 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100831}
832
833/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700834private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100835 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
836 alt {
837 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100839 }
840 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
841 setverdict(pass);
842 }
843 }
844}
845private type record WrongChanNrCase {
846 RslChannelNr chan_nr,
847 charstring description
848}
849private type record of WrongChanNrCase WrongChanNrCases;
850private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
851 chan_nr := chan_nr,
852 description := desc
853}
854
855testcase TC_chan_act_wrong_nr() runs on test_CT {
856 var ConnHdlr vc_conn;
857 var ConnHdlrPars pars;
858
Harald Welte294b0a22018-03-10 23:26:48 +0100859 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100860
861 var WrongChanNrCases wrong := {
862 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
863 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
864 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
866 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
867 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
868 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
869 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
870 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
871 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
872 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
873 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
874 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
875 };
876
877 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
878 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
879 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
880 vc_conn.done;
881 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100883}
884
Harald Weltee613f962018-04-18 22:38:16 +0200885/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200886friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200887 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200888 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200889
890 /* test on each of the channels we have */
891 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
892 pars.chan_nr := valueof(g_AllChanTypes[i]);
893
894 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
895 vc_conn := f_start_handler(fn, pars);
896 vc_conn.done;
897 }
898
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200900}
901
Harald Welte93640c62018-02-25 16:59:33 +0100902/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100903 * SACCH handling
904 ***********************************************************************/
905
906private function f_exp_sacch(boolean exp) runs on ConnHdlr {
907 timer T_sacch := 3.0;
908 T_sacch.start;
909 alt {
910 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100912 }
913 [not exp] T_sacch.timeout {
914 setverdict(pass);
915 }
916 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
917 setverdict(pass);
918 }
919 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100921 }
922 [] L1CTL.receive { repeat; }
923 [] RSL.receive { repeat; }
924 }
925}
926
927/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
928private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
929 f_l1_tune(L1CTL);
930 RSL.clear;
931
932 /* activate the logical channel */
933 f_est_dchan();
934 L1CTL.clear;
935
936 /* check that SACCH actually are received as expected */
937 f_exp_sacch(true);
938
939 /* deactivate SACCH on the logical channel */
940 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
941 f_sleep(1.0);
942 L1CTL.clear;
943
944 /* check that no SACCH are received anymore */
945 f_exp_sacch(false);
946
947 /* release the channel */
948 f_rsl_chan_deact();
949 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
950}
951testcase TC_deact_sacch() runs on test_CT {
952 var ConnHdlr vc_conn;
953 var ConnHdlrPars pars;
954 f_init();
955 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
956 //for (var integer i := 0; i < 1; i := i+1) {
957 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
958 log(testcasename(), ": Starting for ", g_AllChannels[i]);
959 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
960 vc_conn.done;
961 }
962 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100964}
965
Harald Welte55700662018-03-12 13:15:43 +0100966/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100967private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
968 var L1ctlDlMessage dl;
969 /* check that the specified SI5 value is actually sent */
970 timer T_sacch := 3.0;
971 L1CTL.clear;
972 T_sacch.start;
973 alt {
974 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
975 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
976 if (match(l3, l3_exp)) {
977 setverdict(pass);
978 } else {
979 repeat;
980 }
981 }
982 [] L1CTL.receive { repeat; }
983 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100985 }
986 }
987}
988
Harald Welte55700662018-03-12 13:15:43 +0100989/* verify that given SACCH payload is not present */
990private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
991 var L1ctlDlMessage dl;
992 /* check that the specified SI5 value is actually sent */
993 timer T_sacch := 3.0;
994 L1CTL.clear;
995 T_sacch.start;
996 alt {
997 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
998 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
999 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001001 } else {
1002 repeat;
1003 }
1004 }
1005 [] L1CTL.receive { repeat; }
1006 [] T_sacch.timeout {
1007 setverdict(pass);
1008 }
1009 }
1010}
1011
Harald Welte629cc6b2018-03-11 17:19:05 +01001012/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001013private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1014 /* Set a known default SACCH filling for SI5 */
1015 var octetstring si5 := f_rnd_octstring(19);
1016 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1017
1018 f_l1_tune(L1CTL);
1019 RSL.clear;
1020
1021 /* activate the logical channel */
1022 f_est_dchan();
1023
1024 /* check that the specified SI5 value is actually sent */
1025 f_sacch_present(si5);
1026
1027 /* release the channel */
1028 RSL.clear;
1029 f_rsl_chan_deact();
1030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1031}
1032testcase TC_sacch_filling() runs on test_CT {
1033 var ConnHdlr vc_conn;
1034 var ConnHdlrPars pars;
1035 f_init();
1036 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1037 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1038 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1039 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1040 vc_conn.done;
1041 }
1042 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001044}
1045
Harald Welte629cc6b2018-03-11 17:19:05 +01001046/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001047private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1048 /* Set a known default SACCH filling for SI5 */
1049 var octetstring si5 := f_rnd_octstring(19);
1050 var octetstring si5_diff := f_rnd_octstring(19);
1051 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1052
1053 f_l1_tune(L1CTL);
1054 RSL.clear;
1055
1056 log("Activating channel, expecting standard SI5");
1057 /* activate the logical channel */
1058 f_est_dchan();
1059 /* check that the specified SI5 value is actually sent */
1060 f_sacch_present(si5);
1061
1062 /* set channel-specific different SI5 */
1063 log("Setting channel specific SACCH INFO, expecting it");
1064 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1065 /* check that the specified lchan-specific value is now used */
1066 f_sacch_present(si5_diff);
1067
1068 /* deactivate the channel and re-activate it, this should result in default SI5 */
1069 log("De-activating and re-activating channel, expecting standard SI5");
1070 f_rsl_chan_deact();
1071 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1072 /* Verify that the TRX-wide default SACCH filling is present again */
1073 f_sacch_present(si5);
1074
1075 /* release the channel */
1076 RSL.clear;
1077 f_rsl_chan_deact();
1078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1079}
1080testcase TC_sacch_info_mod() runs on test_CT {
1081 var ConnHdlr vc_conn;
1082 var ConnHdlrPars pars;
1083 f_init();
1084 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1085 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1086 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1087 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1088 vc_conn.done;
1089 }
1090 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001092}
1093
Harald Welte075d84c2018-03-12 13:07:24 +01001094/* Test SACCH scheduling of multiple different SI message types */
1095private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1096 var octetstring si5 := f_rnd_octstring(19);
1097 var octetstring si5bis := f_rnd_octstring(19);
1098 var octetstring si5ter := f_rnd_octstring(19);
1099 var octetstring si6 := f_rnd_octstring(19);
1100
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1105
1106 f_l1_tune(L1CTL);
1107 RSL.clear;
1108
1109 /* activate the logical channel */
1110 f_est_dchan();
1111 L1CTL.clear;
1112
1113 /* check that SACCH actually are received as expected */
1114 f_sacch_present(si5);
1115 f_sacch_present(si5bis);
1116 f_sacch_present(si5ter);
1117 f_sacch_present(si6);
1118
1119 /* release the channel */
1120 f_rsl_chan_deact();
1121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1122}
1123testcase TC_sacch_multi() runs on test_CT {
1124 var ConnHdlr vc_conn;
1125 var ConnHdlrPars pars;
1126 f_init();
1127 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1128 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1129 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1130 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1131 vc_conn.done;
1132 }
1133 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001135}
1136
Harald Welte55700662018-03-12 13:15:43 +01001137/* Test if SACH information is modified as expected */
1138private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1139 var octetstring si5 := f_rnd_octstring(19);
1140 var octetstring si6 := f_rnd_octstring(19);
1141
1142 /* First, configure both SI5 and SI6 to be transmitted */
1143 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1144 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1145
1146 f_l1_tune(L1CTL);
1147 RSL.clear;
1148
1149 /* activate the logical channel */
1150 f_est_dchan();
1151 L1CTL.clear;
1152
1153 /* check that SACCH actually are received as expected */
1154 f_sacch_present(si5);
1155 f_sacch_present(si6);
1156
1157 /* disable SI6 */
1158 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1159
1160 /* check that SI5 is still transmitted */
1161 f_sacch_present(si5);
1162 /* check if SI6 is now gone */
1163 f_sacch_missing(si6);
1164
1165 /* release the channel */
1166 f_rsl_chan_deact();
1167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1168}
1169testcase TC_sacch_multi_chg() runs on test_CT {
1170 var ConnHdlr vc_conn;
1171 var ConnHdlrPars pars;
1172 f_init();
1173 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1174 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1175 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1176 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1177 vc_conn.done;
1178 }
1179 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001181}
1182
Harald Weltec8d363c2019-05-19 20:36:48 +02001183/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1184private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1185 var octetstring si5 := f_rnd_octstring(19);
1186 var octetstring si6 := f_rnd_octstring(19);
1187 var octetstring si5_specific := f_rnd_octstring(19);
1188 var octetstring si6_specific := f_rnd_octstring(19);
1189
1190 /* First, configure both SI5 and SI6 to be transmitted */
1191 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1192 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1193
1194 f_l1_tune(L1CTL);
1195 RSL.clear;
1196
1197 /* activate channel with different SACCH filling */
1198 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1199 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1200 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1201 }));
1202 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1203 RSL_IE_Body:{sacch_info := sacch_info})) };
1204 f_est_dchan(more_ies := addl_ies);
1205
1206 /* check that SACCH actually are received as expected */
1207 f_sacch_present(si5_specific);
1208 f_sacch_present(si6_specific);
1209
1210 /* release the channel */
1211 f_rsl_chan_deact();
1212 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1213}
1214testcase TC_sacch_chan_act() runs on test_CT {
1215 var ConnHdlr vc_conn;
1216 var ConnHdlrPars pars;
1217 f_init();
1218
1219 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1220 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1221 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1222 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1223 vc_conn.done;
1224 }
1225 /* TODO: do the above in parallel, rather than sequentially? */
1226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1227}
1228
Harald Welte8b01c792019-05-19 22:51:25 +02001229/* verify that SACCH DL transmission is started only if MS power IE present
1230 * see section 4.1.3 of 3GPP TS 48.058 */
1231private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1232 var octetstring si5 := f_rnd_octstring(19);
1233
1234 f_l1_tune(L1CTL);
1235 RSL.clear;
1236
1237 /* Step 1: Activate ASYNC HO channel without MS power IE */
1238
1239 /* Activate channel on BTS side */
1240 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1241 /* don't perform immediate assignment here, as we're testing non-IA case */
1242 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001243 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001244
1245 /* Verify that no DL SACCH is being received */
1246 f_sacch_missing(?);
1247
1248 f_rsl_chan_deact();
1249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1250
1251
1252 /* Step 2: Activate ASYNC HO channel with MS power IE */
1253
1254 /* Activate channel on BTS side */
1255 var RSL_IE_List addl_ies := {
1256 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1257 };
1258 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1259 /* don't perform immediate assignment here, as we're testing non-IA case */
1260 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001261 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001262
1263 /* Verify that DL SACCH is being received */
1264 f_sacch_present(si5);
1265
1266 f_rsl_chan_deact();
1267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1268}
1269testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1270 var ConnHdlr vc_conn;
1271 var ConnHdlrPars pars;
1272 f_init();
1273
1274 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1275 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1276 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1277 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1278 vc_conn.done;
1279 }
1280 /* TODO: do the above in parallel, rather than sequentially? */
1281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1282}
1283
1284/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1285 * see section 4.1.4 of 3GPP TS 48.058 */
1286private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1287 var octetstring si5 := f_rnd_octstring(19);
1288 var RSL_IE_List addl_ies;
1289
1290 f_l1_tune(L1CTL);
1291 RSL.clear;
1292
1293 /* Step 1: Activate SYNC HO channel without MS power IE */
1294
1295 /* Activate channel on BTS side */
1296 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1297 /* don't perform immediate assignment here, as we're testing non-IA case */
1298 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001299 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001300
1301 /* Verify that no DL SACCH is being received */
1302 f_sacch_missing(?);
1303
1304 f_rsl_chan_deact();
1305 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1306
1307
1308 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1309
1310 /* Activate channel on BTS side */
1311 addl_ies := {
1312 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1313 };
1314 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1315 /* don't perform immediate assignment here, as we're testing non-IA case */
1316 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001317 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001318
1319 /* Verify that no DL SACCH is being received */
1320 f_sacch_missing(?);
1321
1322 f_rsl_chan_deact();
1323 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1324
1325
1326 /* Step 2b: Activate SYNC HO channel with TA IE */
1327
1328 /* Activate channel on BTS side */
1329 addl_ies := {
1330 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1331 };
1332 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1333 /* don't perform immediate assignment here, as we're testing non-IA case */
1334 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001335 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001336
1337 /* Verify that no DL SACCH is being received */
1338 f_sacch_missing(?);
1339
1340 f_rsl_chan_deact();
1341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1342
1343
1344 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1345
1346 /* Activate channel on BTS side */
1347 addl_ies := {
1348 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1349 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1350 };
1351 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1352 /* don't perform immediate assignment here, as we're testing non-IA case */
1353 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001354 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001355
1356 /* Verify that DL SACCH is being received */
1357 f_sacch_present(si5);
1358
1359 f_rsl_chan_deact();
1360 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1361}
1362testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1363 var ConnHdlr vc_conn;
1364 var ConnHdlrPars pars;
1365 f_init();
1366
1367 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1368 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1369 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1370 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1371 vc_conn.done;
1372 }
1373 /* TODO: do the above in parallel, rather than sequentially? */
1374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1375}
Harald Welte629cc6b2018-03-11 17:19:05 +01001376
1377
1378/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001379 * RACH Handling
1380 ***********************************************************************/
1381
Harald Welte8c24c2b2018-02-26 08:31:31 +01001382/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001383private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001384 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001385 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001386 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001387
Harald Welte8c24c2b2018-02-26 08:31:31 +01001388 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001389 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001390 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001391 var OCT1 ra := f_rnd_ra_emerg();
1392 if (emerg == true) {
1393 ra := f_rnd_ra_emerg();
1394 } else {
1395 ra := f_rnd_ra_cs();
1396 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001397 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1398 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001400 }
1401 fn_last := fn;
1402
1403 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001404 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001406 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001407 T.stop;
1408 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001409 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001411 }
1412 [] RSL_CCHAN.receive { repeat; }
1413 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001414 test_failed := true;
1415 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001416 }
1417 }
1418 }
Maxba06feb2019-03-05 10:52:46 +01001419 if (test_failed) {
1420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001421 }
Maxba06feb2019-03-05 10:52:46 +01001422 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001424}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001425
Philipp Maier16ade782020-07-08 21:36:00 +02001426/* Normal variant */
1427testcase TC_rach_content() runs on test_CT {
1428 f_TC_rach_content(emerg := false);
1429}
1430
1431/* Emergency call variant */
1432testcase TC_rach_content_emerg() runs on test_CT {
1433 f_TC_rach_content(emerg := true);
1434}
1435
Harald Welte8c24c2b2018-02-26 08:31:31 +01001436/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1437testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001438 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001439 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001440 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 f_l1_tune(L1CTL);
1442
1443 var GsmFrameNumber fn_last := 0;
1444 for (var integer i := 0; i < 1000; i := i+1) {
1445 var OCT1 ra := f_rnd_ra_cs();
1446 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1447 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001449 }
1450 fn_last := fn;
1451 }
1452 var integer rsl_chrqd := 0;
1453 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001454 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001455 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001456 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001457 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001458 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 repeat;
1460 }
1461 [] RSL_CCHAN.receive { repeat; }
1462 [] T.timeout { }
1463 }
1464 if (rsl_chrqd == 1000) {
1465 setverdict(pass);
1466 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001468 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001470}
1471
Harald Welte3453ab42019-05-24 21:19:58 +02001472private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1473 var charstring bts_str := "bts " & int2str(bts_nr);
1474 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1475}
1476
1477/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1478private template integer tr_rach_slots_per_interval := (90 .. 130);
1479
1480/* Expect 0 RACH load on an idle BTS that has just started up */
1481testcase TC_rach_load_idle_thresh0() runs on test_CT {
1482 var ASP_RSL_Unitdata rx_ud;
1483
1484 f_init_vty_bsc();
1485 /* send load indications even at 0% load */
1486 f_vty_load_ind_thresh(0);
1487 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1488 f_sleep(2.0);
1489
1490 f_init();
1491
Harald Weltee37f9a52020-10-11 20:45:23 +02001492 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1493 alt {
1494 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1495 [] RSL_CCHAN.receive { repeat }
1496 }
1497
Harald Welte3453ab42019-05-24 21:19:58 +02001498 timer T := 5.0;
1499 T.start;
1500 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001501 [] 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 +02001502 setverdict(pass);
1503 repeat;
1504 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001505 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001506 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1507 repeat;
1508 }
1509 [] RSL_CCHAN.receive {
1510 repeat;
1511 }
1512 [] T.timeout { }
1513 }
1514
1515 f_vty_load_ind_thresh(10);
1516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1517}
1518
1519/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1520testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1521 var ASP_RSL_Unitdata rx_ud;
1522
1523 f_init_vty_bsc();
1524 f_init();
1525
1526 timer T := 5.0;
1527 T.start;
1528 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001529 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001530 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1531 repeat;
1532 }
1533 [] RSL_CCHAN.receive {
1534 repeat;
1535 }
1536 [] T.timeout {
1537 setverdict(pass);
1538 }
1539 }
1540
1541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1542}
1543
1544/* Expect 0 RACH load on an idle BTS that has just started up */
1545testcase TC_rach_load_count() runs on test_CT {
1546 var ASP_RSL_Unitdata rx_ud;
1547 var integer load_access_count := 0;
1548
1549 f_init_vty_bsc();
1550 /* send load indications even at 0% load */
1551 f_vty_load_ind_thresh(0);
1552 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1553 f_sleep(2.0);
1554 f_init();
1555
1556 f_init_l1ctl();
1557 f_sleep(1.0);
1558 f_l1_tune(L1CTL);
1559
Harald Welte52ae1682020-10-11 20:45:55 +02001560 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1561 alt {
1562 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1563 [] RSL_CCHAN.receive { repeat }
1564 }
1565
Harald Welte3453ab42019-05-24 21:19:58 +02001566 var GsmFrameNumber fn_last := 0;
1567 for (var integer i := 0; i < 1000; i := i+1) {
1568 var OCT1 ra := f_rnd_ra_cs();
1569 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1570 if (fn == fn_last) {
1571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1572 }
1573 fn_last := fn;
1574 }
1575
1576 timer T := 5.0;
1577 T.start;
1578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001580 -> value rx_ud {
1581 var RSL_IE_Body ie;
1582 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1583 load_access_count := load_access_count + ie.rach_load.access_count;
1584 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1585 setverdict(fail, "Access count cannot be < Busy count");
1586 }
1587 repeat;
1588 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001589 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001590 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1591 repeat;
1592 }
1593 [] RSL_CCHAN.receive {
1594 repeat;
1595 }
1596 [] T.timeout { }
1597 }
1598 if (load_access_count == 1000) {
1599 setverdict(pass);
1600 } else {
1601 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1602 }
1603
1604 f_vty_load_ind_thresh(10);
1605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1606}
1607
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001609 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001611 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001612 f_sleep(0.5);
1613
1614 /* Transmit RACH request + wait for confirmation */
1615 var OCT1 ra := f_rnd_ra_cs();
1616 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1617
1618 /* Check for expected result */
1619 timer T := 1.5;
1620 T.start;
1621 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001622 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001623 setverdict(pass);
1624 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001625 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001627 }
1628 [] RSL_CCHAN.receive { repeat; }
1629 [not expect_pass] T.timeout {
1630 setverdict(pass);
1631 }
1632 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001634 }
1635 }
1636}
1637
1638/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1639testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001640 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001641 f_init_l1ctl();
1642 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001643 f_sleep(1.0);
1644
1645 /* default max-ta is 63 (full range of GSM timing advance */
1646
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001647 /* We allow early arrival up to 2 symbols */
1648 f_rach_toffs(-1*256, true);
1649 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001650 f_rach_toffs(-10*256, false);
1651
1652 /* 0 / 32 / 63 bits is legal / permitted */
1653 f_rach_toffs(0, true);
1654 f_rach_toffs(32*256, true);
1655 f_rach_toffs(63*256, true);
1656
1657 /* more than 63 bits is not legal / permitted */
1658 f_rach_toffs(64*256, false);
1659 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001661}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001662
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001663private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001664 var GsmFrameNumber fn;
1665 var RSL_Message rm;
1666
1667 f_l1_tune(L1CTL);
1668 RSL.clear;
1669
1670 /* Generate a random Handover Reference */
1671 var integer ho_ref := oct2int(f_rnd_octstring(1));
1672
1673 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1674 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1675 RSL_IE_Body:{ handover_ref := ho_ref }));
1676
1677 /* Activate a channel on the BTS side (no encryption) */
1678 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1679 act_type := t_RSL_IE_ActType_HO_SYNC);
1680
1681 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1682 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001683 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001684
1685 /* Send handover Access Burst */
1686 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1687
1688 /* TODO: test mismatching Handover Reference, and missing IE */
1689
1690 /* Wait for handover detection */
1691 timer T := 3.0;
1692 T.start;
1693 alt {
1694 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1695 log("Handover RACH has been detected: ", rm);
1696 setverdict(pass);
1697 }
1698 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1700 log2str("RSL_CHAN_RQD was not expected: ", rm));
1701 }
1702 [] RSL.receive { repeat; }
1703 [] T.timeout {
1704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1705 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1706 }
1707 }
1708
1709 /* Release the channel */
1710 f_rsl_chan_deact();
1711 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1712}
1713
1714/* Test handover RACH detection */
1715testcase TC_ho_rach() runs on test_CT {
1716 var ConnHdlrPars pars;
1717 var ConnHdlr vc_conn;
1718
1719 f_init();
1720
1721 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1722 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1723 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1724 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1725 vc_conn.done;
1726 }
1727
1728 /* TODO: do the above in parallel, rather than sequentially? */
1729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1730}
1731
Harald Welte93640c62018-02-25 16:59:33 +01001732/***********************************************************************
1733 * Measurement Processing / Reporting
1734 ***********************************************************************/
1735
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001736private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001737 spare := '0'B,
1738 lpd := 0,
1739 sapi := sapi,
1740 c_r := c_r,
1741 ea := true
1742}
1743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001744private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001745 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001746 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001747 len := 0, /* overwritten */
1748 m := false,
1749 el := 1,
1750 payload := pl
1751}
1752
1753/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001754private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001755 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001756 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001757 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001758 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 +01001759 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001760 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001761
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001762 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1763 g_pars.l1_pars.ms_power_level, false,
1764 g_pars.l1_pars.ms_actual_ta);
1765
1766 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1767 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1768
1769 log("Sending Measurement Report: ", l1h, l2);
1770 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001771 repeat;
1772 }
1773}
1774
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001775private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001776 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001777 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001778 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1779 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001780 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1781 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001782 repeat;
1783 }
1784}
1785
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001786private altstep as_l1_tch_loop() runs on ConnHdlr {
1787 var L1ctlDlMessage l1_dl;
1788 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1789 log("TCH received: ", l1_dl.payload.traffic_ind.data);
1790 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1791 l1_dl.payload.traffic_ind.data));
1792 repeat;
1793 }
1794}
1795
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001796private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001797 uint6_t rxlev,
1798 uint3_t rxqual
1799}
1800
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001801private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001802 MeasElem full,
1803 MeasElem sub
1804}
1805
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001806private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001807 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001808 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001809 MeasElemFS meas_ul,
1810 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001811 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001812 uint5_t ms_power_level,
1813 uint8_t ms_actual_ta
1814}
1815
1816/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1817private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1818 return 63 + (toffs256s/256);
1819}
1820
Harald Welted5684392018-03-10 18:22:04 +01001821private function f_max(integer a, integer b) return integer {
1822 if (a > b) {
1823 return a;
1824 } else {
1825 return b;
1826 }
1827}
1828
1829private function f_min(integer a, integer b) return integer {
1830 if (a < b) {
1831 return a;
1832 } else {
1833 return b;
1834 }
1835}
1836
1837/* compute negative tolerance val-tolerance, ensure >= min */
1838private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1839 val := val - tolerance;
1840 return f_max(val, min);
1841}
1842
1843/* compute positive tolerance val+tolerance, ensure <= max */
1844private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1845 val := val + tolerance;
1846 return f_min(val, max);
1847}
1848
1849/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1850private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1851return template integer {
1852 var template integer ret;
1853 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1854 return ret;
1855}
1856
1857
Harald Welte70767382018-02-21 12:16:40 +01001858/* build a template for matching measurement results against */
1859private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1860 var ConnL1Pars l1p := g_pars.l1_pars;
1861 var template RSL_IE_UplinkMeas ul_meas := {
1862 len := 3,
1863 rfu := '0'B,
1864 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001865 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001866 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001867 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001868 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001869 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1870 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001871 supp_meas_info := omit
1872 };
Harald Welte685d5982018-02-27 20:42:05 +01001873 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001874 ul_meas.len := (3+8);
1875 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001876 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001877 toa256_min := ?,
1878 toa256_max := ?,
1879 toa256_std_dev := ?
1880 }
Harald Welte685d5982018-02-27 20:42:05 +01001881 }
Harald Welte70767382018-02-21 12:16:40 +01001882 var template RSL_IE_BS_Power bs_power := {
1883 reserved := 0,
1884 epc := false,
1885 fpc := false,
1886 power_level := l1p.bs_power_level
1887 };
1888 var template RSL_IE_L1Info l1_info := {
1889 ms_power_lvl := l1p.ms_power_level,
1890 fpc := false,
1891 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001892 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001893 };
1894 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001895 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001896 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1897 ?, t_toffs);
1898}
1899
Philipp Maierdd841d32019-12-17 14:44:54 +01001900/* build a template for matching measurement results that do not contain any
1901 * MS related measurement (l1_info, l3_info and ms timing offset). */
1902private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1903 var ConnL1Pars l1p := g_pars.l1_pars;
1904 var template RSL_IE_UplinkMeas ul_meas := {
1905 len := 3,
1906 rfu := '0'B,
1907 dtx_d := l1p.dtx_enabled,
1908 rxlev_f_u := ?,
1909 reserved1 := '00'B,
1910 rxlev_s_u := ?,
1911 reserved2 := '00'B,
1912 rxq_f_u := ?,
1913 rxq_s_u := ?,
1914 supp_meas_info := omit
1915 };
1916 if (l1p.toa256_enabled) {
1917 ul_meas.len := (3+8);
1918 ul_meas.supp_meas_info := {
1919 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1920 toa256_min := ?,
1921 toa256_max := ?,
1922 toa256_std_dev := ?
1923 }
1924 }
1925 var template RSL_IE_BS_Power bs_power := {
1926 reserved := 0,
1927 epc := false,
1928 fpc := false,
1929 power_level := l1p.bs_power_level
1930 };
1931
1932 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1933}
1934
Harald Welte70767382018-02-21 12:16:40 +01001935/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001936private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001937 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001938 var boolean chan_est := false;
1939
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001940 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001941
1942 /* Receive osmocom specific measurement reports. This is the normal
1943 * case. Here we verify that the measurement reports we sent are
1944 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001945 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1946 /* increment counter of next to-be-expected meas rep */
1947 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1948 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001949 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001950
1951 /* The following two cases may only happen in the beginning
1952 * of the channel establishment phase. Once we have received
1953 * the "our" measurement report the first time, the channel
1954 * is established and empty or hardcoded TRXCON reports must
1955 * not occur anymore. */
1956 chan_est := true;
1957
1958 repeat;
1959 }
1960
1961 /* When the BTS has established the channel, the MS might need slightly
1962 * more time to establish the channel and actually start sending. The
1963 * result is then a measurement report that just lacks the measurement
1964 * information of the MS. This is normal and we tolerate this behavior. */
1965 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1966 /* increment counter of next to-be-expected meas rep */
1967 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1968 /* Re-start the timer expecting the next MEAS RES */
1969 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001970 repeat;
1971 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001972
1973 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1974 * measurements if the TTCN3 side does not supply measurement input in
1975 * time. In those cases TRXCON will either use a cached measurement
1976 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1977 * report the templates above will not match. We tolerate this
1978 * behavior, but only once. */
1979 [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 +01001980 /* increment counter of next to-be-expected meas rep */
1981 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1982 if (g_first_meas_res) {
1983 g_first_meas_res := false;
1984 repeat;
1985 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001987 }
Harald Welte70767382018-02-21 12:16:40 +01001988 }
1989 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001991 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001992 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001994 }
1995}
1996
Harald Weltee613f962018-04-18 22:38:16 +02001997private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1998 select (rsl_alg_id) {
1999 case (RSL_ALG_ID_A5_0) { return 0; }
2000 case (RSL_ALG_ID_A5_1) { return 1; }
2001 case (RSL_ALG_ID_A5_2) { return 2; }
2002 case (RSL_ALG_ID_A5_3) { return 3; }
2003 case (RSL_ALG_ID_A5_4) { return 4; }
2004 case (RSL_ALG_ID_A5_5) { return 5; }
2005 case (RSL_ALG_ID_A5_6) { return 6; }
2006 case (RSL_ALG_ID_A5_7) { return 7; }
2007 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2009 /* Make compiler happy by calling mtc.stop here. It is already
2010 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002011 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002012 }
2013 }
2014}
2015
2016private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2017 select (rsl_alg_id) {
2018 case (RSL_ALG_ID_A5_1) { return '000'B; }
2019 case (RSL_ALG_ID_A5_2) { return '001'B; }
2020 case (RSL_ALG_ID_A5_3) { return '010'B; }
2021 case (RSL_ALG_ID_A5_4) { return '011'B; }
2022 case (RSL_ALG_ID_A5_5) { return '100'B; }
2023 case (RSL_ALG_ID_A5_6) { return '101'B; }
2024 case (RSL_ALG_ID_A5_7) { return '110'B; }
2025 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2027 /* Make compiler happy by calling mtc.stop here. It is already
2028 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002029 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002030 }
2031 }
2032}
2033
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002034/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2035private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2036 var GsmFrameNumber fn;
2037 timer T := 8.0;
2038
2039 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2040 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2041
2042 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2043 /* Send the actual RACH */
2044 fn := f_L1CTL_RACH(L1CTL, ra);
2045
2046 T.start;
2047 alt {
2048 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2049 [] T.timeout {
2050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2051 }
2052 }
2053 T.stop
2054 return fn;
2055}
Harald Weltee613f962018-04-18 22:38:16 +02002056
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002057/* Tune to a dedicated channel: L1CTL only */
2058private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002059 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002060 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2061 7 /* TODO: mp_tsc */,
2062 mp_trx0_arfcn));
2063 } else {
2064 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2065 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002066 pars.fhp.maio_hsn.hsn,
2067 pars.fhp.maio_hsn.maio,
2068 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002069 }
2070}
2071
Harald Welte70767382018-02-21 12:16:40 +01002072/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002073private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002074 var GsmFrameNumber fn;
2075 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002076 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002077 var integer ra := 23;
2078
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002079 /* Send RACH request and wait for ChanReq */
2080 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002081
2082 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002083 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002084
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002085 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002086 if (g_pars.fhp.enabled) {
2087 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002088 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002089 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002090 }
2091
Harald Welte70767382018-02-21 12:16:40 +01002092 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002093 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 +01002094 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2095
2096 /* receive IMM.ASS on MS side */
2097 var ImmediateAssignment ia_um;
2098 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002099
2100 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2101 if (ch_desc.h != ia_um.chan_desc.h) {
2102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2103 }
2104
Harald Welte70767382018-02-21 12:16:40 +01002105 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002106 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002107 /* enable encryption, if requested */
2108 if (encr_enable) {
2109 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2110 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2111 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002112
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002113 /* Send TCH Mode Request to the L1 if needed */
2114 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2115 var L1ctlTchMode tch_mode;
2116
2117 select (g_pars.chan_mode.coding_alg_rate) {
2118 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2119 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2120 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2121 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2122 case else {
2123 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2124 " is not supported by the L1, falling back to signalling");
2125 tch_mode := L1CTL_CHAN_MODE_SIGN;
2126 }
2127 }
2128
2129 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2130 }
2131
Harald Weltefa45e9e2018-03-10 18:59:03 +01002132 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002133}
2134
2135/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002136private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002137 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002138 RSL.clear;
2139
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002140 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002141 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002142 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002143 }
Harald Welte70767382018-02-21 12:16:40 +01002144
2145 f_est_dchan();
2146
2147 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2148 * RSL measurement reports on Abis side */
2149 timer T := 8.0;
2150 T.start;
2151 alt {
2152 [] as_l1_sacch();
2153 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002154 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002155 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002156 [] L1CTL.receive { repeat; }
2157 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002158 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002159 * of any earlier errors, so if we reach this timeout, we're good */
2160 setverdict(pass);
2161 }
2162 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002164 }
2165 }
2166 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002168}
Harald Welte0472ab42018-03-12 15:02:26 +01002169
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002170/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2171private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002172 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002173 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2174 timer Tup := 10.0;
2175 Tup.start;
2176 alt {
2177 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2178 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2179 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002180
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002181 if (rx_lvl != max_rx_lvl) {
2182 repeat;
2183 }
2184 Tup.stop;
2185 }
2186 [] L1CTL.receive { repeat; }
2187 [] Tup.timeout {
2188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2189 log2str("Didn't reach full power ", max_rx_lvl));
2190 }
2191 }
2192 return max_rx_lvl;
2193}
2194
2195/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2196private function f_verify_ramp_up() runs on ConnHdlr {
2197 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002198 var integer initial_rx_lvl := -1;
2199 var integer last_rx_lvl := -1;
2200 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2201
2202 timer T := 2.0;
2203 alt {
2204 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2205 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2206 log("Received rx_level=", rx_lvl);
2207 if (initial_rx_lvl == -1) {
2208 initial_rx_lvl := rx_lvl;
2209 last_rx_lvl := rx_lvl;
2210
2211 /* Expect a somehow low value during first received messages */
2212 if (initial_rx_lvl >= max_rx_lvl / 2) {
2213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2214 log2str("Detected high initial tx power during ramp up: ",
2215 initial_rx_lvl , ", full power is", max_rx_lvl));
2216 }
2217 }
2218
2219 /* received Rx level bigger than maximum allowed power by CN */
2220 if (rx_lvl > max_rx_lvl) {
2221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2222 log2str("Detected Tx power higher than full power: ",
2223 rx_lvl , " > ", max_rx_lvl));
2224 }
2225
2226 /* Make sure it never decreases, since we are rumping up */
2227 if (last_rx_lvl > rx_lvl) {
2228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2229 log2str("Detected Tx power decrease during ramp up: ",
2230 last_rx_lvl , " -> ", rx_lvl));
2231 }
2232
2233 if (rx_lvl == max_rx_lvl and not T.running) {
2234 /* We reached the maximum power, start timer and receive
2235 /* a few more to make sure we don't surpass it */
2236 log("Reached full power, wating a bit more until success");
2237 T.start;
2238 }
2239
2240 last_rx_lvl := rx_lvl;
2241 repeat;
2242 }
2243 [] L1CTL.receive { repeat; }
2244 [] T.timeout { }
2245 }
2246
2247 /* We didn't increase tx power during ramp up */
2248 if (initial_rx_lvl < last_rx_lvl) {
2249 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2250 } else {
2251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2252 log2str("No Tx power increase during whole ramp up: ",
2253 initial_rx_lvl , " -> ", last_rx_lvl));
2254 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002255}
2256
2257/* verify BTS ramps power down to rx_level 0 */
2258private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2259 var L1ctlDlMessage l1_dl;
2260 var integer last_rx_lvl := max_rx_lvl;
2261
2262 timer Tdown := 5.0;
2263 Tdown.start;
2264 alt {
2265 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2266 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2267 log("Received rx_level=", rx_lvl);
2268
2269 /* received Rx level bigger than maximum allowed power by CN */
2270 if (rx_lvl > max_rx_lvl) {
2271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2272 log2str("Detected Tx power higher than full power: ",
2273 rx_lvl , " > ", max_rx_lvl));
2274 }
2275
2276 /* Make sure it never increases, since we are rumping down */
2277 if (last_rx_lvl < rx_lvl) {
2278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2279 log2str("Detected Tx power increase during ramp up: ",
2280 last_rx_lvl , " -> ", rx_lvl));
2281 }
2282
2283 last_rx_lvl := rx_lvl;
2284 if (last_rx_lvl != 0) {
2285 repeat;
2286 }
2287 /* we reached power level 0, we are done */
2288 Tdown.stop;
2289 }
2290 [] L1CTL.receive { repeat; }
2291 [] Tdown.timeout { }
2292 }
2293
2294 /* We didn't increase tx power during ramp down */
2295 if (max_rx_lvl > last_rx_lvl) {
2296 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2297 } else {
2298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2299 log2str("No Tx power decrease during whole ramp down: ",
2300 max_rx_lvl , " -> ", last_rx_lvl));
2301 }
2302}
2303
2304/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002305private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002306 f_l1_tune(L1CTL);
2307 RSL.clear;
2308
2309 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002310
2311 setverdict(pass);
2312}
2313testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2314 var ConnHdlr vc_conn;
2315 var ConnHdlrPars pars;
2316 f_init();
2317 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2318 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2319 pcu_comp := false, trxc_comp := true);
2320 vc_conn.done;
2321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2322}
2323
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002324/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002325private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002326 f_connhdlr_init_vty_bsc();
2327
2328 f_l1_tune(L1CTL);
2329 RSL.clear;
2330
2331 /* Wait until BTS is started and at full power */
2332 var integer max_rx_lvl := f_wait_ramp_up();
2333 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2334
2335 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2336 f_verify_ramp_down(max_rx_lvl);
2337
2338 setverdict(pass);
2339}
2340testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2341 var ConnHdlr vc_conn;
2342 var ConnHdlrPars pars;
2343 f_init();
2344 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2345 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2346 pcu_comp := false, trxc_comp := true);
2347 vc_conn.done;
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2349}
2350
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002351/* Verify Tx power:
2352 * + ramping down during ADM state UNLOCKED->LOCKED
2353 * + ramping up during ADM state LOCKED->UNLOCKED
2354 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002355private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002356 var L1ctlDlMessage l1_dl;
2357 var integer last_rx_lvl;
2358
2359 f_connhdlr_init_vty_bsc();
2360
2361 f_l1_tune(L1CTL);
2362 RSL.clear;
2363
2364 /* Wait until BTS is started and at full power */
2365 var integer max_rx_lvl := f_wait_ramp_up();
2366 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2367
2368 log("ADM STATE UNLOCKED->LOCKED");
2369 f_vty_enter_cfg_trx(BSCVTY);
2370 f_vty_transceive(BSCVTY, "rf_locked 1");
2371 last_rx_lvl := max_rx_lvl;
2372 f_verify_ramp_down(max_rx_lvl);
2373
2374 /* Let some time after we received 0dBm, then check we don't receive BCCH
2375 * anymore because scheduler has stopped after ramping down */
2376 f_sleep(2.0);
2377 L1CTL.clear;
2378 timer Tlocked := 2.0;
2379 Tlocked.start;
2380 alt {
2381 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2383 log2str("Received data_ind during rf_locked: ", l1_dl));
2384 }
2385 [] L1CTL.receive { repeat; }
2386 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2387 }
2388
2389 log("ADM STATE LOCKED->UNLOCKED");
2390 f_vty_transceive(BSCVTY, "rf_locked 0");
2391 f_verify_ramp_up();
2392 setverdict(pass);
2393}
2394testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2395 var ConnHdlr vc_conn;
2396 var ConnHdlrPars pars;
2397 f_init();
2398 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2399 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2400 pcu_comp := false, trxc_comp := true);
2401 vc_conn.done;
2402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2403}
2404
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002405private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002406 timer T := 8.0;
2407 T.start;
2408 var RSL_Message rsl;
2409 alt {
2410 [] as_l1_sacch();
2411 [] L1CTL.receive { repeat; }
2412 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2413 if (rsl.ies[3].body.bs_power.power_level == level) {
2414 setverdict(pass)
2415 } else {
2416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2417 }
2418 }
2419 [] T.timeout {
2420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2421 }
2422 }
2423}
2424
2425/* see if the rsl meas res contains our expeced bs power level
2426bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002427private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002428 f_l1_tune(L1CTL);
2429 RSL.clear;
2430
2431 if (mp_bts_trxc_port != -1) {
2432 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2433 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2434 }
2435
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002436 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002437 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2438 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2439
2440 f_est_dchan(more_ies :={valueof(pwr)});
2441
2442 f_check_meas_bs_power_level(pwr_var);
2443
2444 f_rsl_chan_deact();
2445 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2446}
2447
2448/* see if the rsl meas res contains our expeced bs power level
2449bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002450private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002451 f_l1_tune(L1CTL);
2452 RSL.clear;
2453
2454 if (mp_bts_trxc_port != -1) {
2455 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2456 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2457 }
2458
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002459 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002460 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2461
2462 f_est_dchan();
2463
2464 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2465
2466 f_check_meas_bs_power_level(pwr_var);
2467
2468 f_rsl_chan_deact();
2469 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2470}
2471
2472testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2473 var ConnHdlr vc_conn;
2474 var ConnHdlrPars pars;
2475 f_init();
2476 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2477 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2478 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2479 pcu_comp := false, trxc_comp := true);
2480 vc_conn.done;
2481 }
2482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2483}
2484
2485testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2486 var ConnHdlr vc_conn;
2487 var ConnHdlrPars pars;
2488 f_init();
2489 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2490 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2491 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2492 pcu_comp := false, trxc_comp := true);
2493 vc_conn.done;
2494 }
2495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2496}
2497
Eric Wild61edb7e2019-06-03 12:38:31 +02002498/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2499second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2500These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002501private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002502 var uint5_t pwr_var := 7;
2503 var L1ctlDlMessage l1_dl;
2504
2505 f_trxc_fake_rssi(rxlev2dbm(10));
2506 f_l1_tune(L1CTL);
2507 RSL.clear;
2508
2509 var RSL_IE_List addl_ies;
2510 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2511
2512 addl_ies := {
2513 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2514 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2515 };
2516
2517 /* establish with power parameters */
2518 f_est_dchan(more_ies := addl_ies);
2519
2520 /* set a high value to ensure L1 power control level increases */
2521 f_trxc_fake_rssi(rxlev2dbm(20));
2522
2523 timer T2 := 6.0;
2524 T2.start;
2525 alt {
2526 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002527 /* Update sent MS power to follow what BTS requests */
2528 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2529 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002530 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002531 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002532 T2.stop;
2533 }
2534 [] L1CTL.receive { repeat; }
2535 [] T2.timeout {
2536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2537 "Power Level in L1 header has not increased sufficiently");
2538 }
2539 }
2540
2541 /* set a low value to ensure L1 power control level decreases */
2542 f_trxc_fake_rssi(rxlev2dbm(0));
2543
2544 timer T4 := 6.0;
2545 T4.start;
2546 alt {
2547 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002548 /* Update sent MS power to follow what BTS requests */
2549 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2550 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002551 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002552 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002553 T4.stop;
2554 setverdict(pass, "Power level in L1 decreased/increased as expected");
2555 }
2556 [] L1CTL.receive { repeat; }
2557 [] T4.timeout {
2558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2559 "Power Level in L1 header has not decreased sufficiently");
2560 }
2561 }
2562
2563 f_rsl_chan_deact();
2564 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2565
2566}
2567
2568/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002569private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002570 var uint5_t pwr_var := 7;
2571 var L1ctlDlMessage l1_dl;
2572
2573 /* set a low value to ensure power increases */
2574 f_trxc_fake_rssi(rxlev2dbm(10));
2575 f_l1_tune(L1CTL);
2576 RSL.clear;
2577
2578 var RSL_IE_List addl_ies;
2579 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2580
2581 addl_ies := {
2582 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2583 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2584 };
2585
2586 /* establish with power parameters */
2587 f_est_dchan(more_ies := addl_ies);
2588
2589 timer T1 := 10.0;
2590 T1.start;
2591 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002592 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2593 /* Update sent MS power to follow what BTS requests */
2594 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2595 repeat;
2596 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002597 [] L1CTL.receive { repeat; }
2598 [] T1.timeout {
2599 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2600 setverdict(fail, "Power level in L1 header should not have changed");
2601 }
2602 }
2603 }
2604
2605 f_rsl_chan_deact();
2606 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2607
2608}
2609
2610/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002611private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002612 var L1ctlDlMessage l1_dl;
2613 var uint5_t pwr_var := 15;
2614 var uint5_t pwr_max_var := f_get_max_power_from_band();
2615
2616 /* set a low value to ensure power increases */
2617 f_trxc_fake_rssi(rxlev2dbm(10));
2618 f_l1_tune(L1CTL);
2619 RSL.clear;
2620
2621 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2622 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2623
2624 /* establish with fixed power level */
2625 f_est_dchan(more_ies :={valueof(pwr)});
2626
2627 /* check our initial power level */
2628 f_wait_for_l1_power_level(pwr_var);
2629
2630 /* update power param to enable power loop
2631 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2632 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2633
2634 /* wait, then check that our power level was reduced */
2635 timer T1 := 10.0;
2636 T1.start;
2637 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002638 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2639 /* Update sent MS power to follow what BTS requests */
2640 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2641 repeat;
2642 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002643 [] L1CTL.receive { repeat; }
2644 [] T1.timeout {
2645 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2646 if( f_power_level_is_highest_dbm(rcv) ){
2647 setverdict(pass, "Power level in L1 header reduced as expected");
2648 } else {
2649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2650 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2651 }
2652 }
2653 }
2654
2655 f_rsl_chan_deact();
2656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2657
2658}
2659
2660/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002661private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002662 var L1ctlDlMessage l1_dl;
2663
2664 /* set a high value to ensure power decreases */
2665 f_trxc_fake_rssi(rxlev2dbm(50));
2666 f_l1_tune(L1CTL);
2667 RSL.clear;
2668
2669 var uint5_t pwr_var := 5;
2670 var uint5_t pwr_target_val := 15;
2671
2672 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2673 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2674
2675 /* establish with fixed power level */
2676 f_est_dchan(more_ies :={valueof(pwr)});
2677
2678 /* check our initial power level */
2679 f_wait_for_l1_power_level(pwr_var);
2680
2681 /* update power param to enable power loop
2682 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002683 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002684
2685 /* wait, then check that our power level was increased */
2686 timer T1 := 10.0;
2687 T1.start;
2688 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002689 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2690 /* Update sent MS power to follow what BTS requests */
2691 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2692 repeat;
2693 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002694 [] L1CTL.receive { repeat; }
2695 [] T1.timeout {
2696 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2697 setverdict(pass, "Power level in L1 header increased to lowest power value");
2698 } else {
2699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2700 "Power level in L1 header NOT increased to lowest power value");
2701 }
2702 }
2703 }
2704
2705 f_rsl_chan_deact();
2706 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2707
2708}
2709
Eric Wild095024b2019-06-17 15:08:57 +02002710/* see if we change the power level without receiving power parameters, which should not happen
2711rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002712private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002713 var L1ctlDlMessage l1_dl;
2714
2715 /* set a high value to ensure power decreases */
2716 f_trxc_fake_rssi(rxlev2dbm(50));
2717 f_l1_tune(L1CTL);
2718 RSL.clear;
2719
2720 var uint5_t pwr_var := 5;
2721
2722 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2723 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2724
2725 /* establish with fixed power level */
2726 f_est_dchan(more_ies :={valueof(pwr)});
2727
2728 /* check our initial power level */
2729 f_wait_for_l1_power_level(pwr_var);
2730
2731 /* wait, then check that our power level did not change */
2732 timer T1 := 10.0;
2733 T1.start;
2734 alt {
2735 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2736 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2738 "BS power control should not be active unless we receive a power parameters IE!");
2739 }
2740 repeat;
2741 }
2742 [] L1CTL.receive { repeat; }
2743 [] T1.timeout { setverdict(pass); }
2744 }
2745
2746 f_rsl_chan_deact();
2747 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2748
2749}
2750
Eric Wild095024b2019-06-17 15:08:57 +02002751/* see if we change the power level without receiving power parameters, which should not happen
2752ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002753private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002754 var L1ctlDlMessage l1_dl;
2755
2756 /* set a high value to ensure power decreases */
2757 f_trxc_fake_rssi(rxlev2dbm(50));
2758 f_l1_tune(L1CTL);
2759 RSL.clear;
2760
2761 var uint5_t pwr_var := 5;
2762
2763 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2764 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2765
2766 /* establish with fixed power level */
2767 f_est_dchan(more_ies :={valueof(pwr)});
2768
2769 /* check our initial power level */
2770 f_wait_for_l1_power_level(pwr_var);
2771
2772 /* pwr control without power params IE, should NOT activate MS power control*/
2773 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2774
2775 /* wait, then check that our power level did not change */
2776 timer T1 := 10.0;
2777 T1.start;
2778 alt {
2779 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2780 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2782 "BS power control should not be active unless we receive a power parameters IE!");
2783 }
2784 repeat;
2785 }
2786 [] L1CTL.receive { repeat; }
2787 [] T1.timeout { setverdict(pass); }
2788 }
2789
2790 f_rsl_chan_deact();
2791 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2792
2793}
2794
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002795private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002796 var L1ctlDlMessage l1_dl;
2797 timer T0 := 10.0;
2798 T0.start;
2799 alt {
2800 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2801 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2803 "Power level in L1 header != signaled (RSL) power level.");
2804 }
2805 }
2806 [] L1CTL.receive { repeat; }
2807 [] T0.timeout {
2808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2809 "Timeout waiting for initial power level");
2810 }
2811 }
2812 T0.stop;
2813}
2814
2815private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2816 var IntegerRecord min_dbm_level;
2817 var IntegerRecord max_dbm_level;
2818 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2819
2820 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2821 if (min_dbm_level[i] == level) {
2822 return true;
2823 }
2824 }
2825 return false;
2826}
2827
2828private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2829 var IntegerRecord min_dbm_level;
2830 var IntegerRecord max_dbm_level;
2831 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2832
2833 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2834 if (max_dbm_level[i] == level) {
2835 return true;
2836 }
2837 }
2838 return false;
2839}
2840
2841private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2842 var IntegerRecord min_dbm_level;
2843 var IntegerRecord max_dbm_level;
2844 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2845 return max_dbm_level[0];
2846}
2847
2848type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002849private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002850private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2851 // 45.005 4.1.1
2852 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2853 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2854 2, 1, 0};
2855 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2856 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2857 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2858 var IntegerRecord rv;
2859
2860 select(band){
2861 case (BtsBand_allGSM){
2862 rv := gsm_power;
2863 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2864 max_dbm_level := {2, 1, 0};
2865 }
2866 case("DCS1800"){
2867 rv := dcs_power;
2868 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2869 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2870 }
2871 case("PCS1900"){
2872 rv := pcs_power;
2873 min_dbm_level := {15};
2874 max_dbm_level := {30};
2875 }
Harald Welte194b6912020-10-11 21:01:55 +02002876 case else {
2877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2878 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002879 }
2880
2881 return rv;
2882}
2883
2884private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002885 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 +02002886}
2887
2888testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2889 var ConnHdlr vc_conn;
2890 var ConnHdlrPars pars;
2891 f_init();
2892 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2893 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2894 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2895 pars.bts0_band := f_vty_get_bts0_band();
2896 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2897 vc_conn.done;
2898 }
2899 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2901}
2902
2903testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2904 var ConnHdlr vc_conn;
2905 var ConnHdlrPars pars;
2906 f_init();
2907 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2908 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2909 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2910 pars.bts0_band := f_vty_get_bts0_band();
2911 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2912 vc_conn.done;
2913 }
2914 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2916}
2917
2918testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2919 var ConnHdlr vc_conn;
2920 var ConnHdlrPars pars;
2921 f_init();
2922 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2923 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2924 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2925 pars.bts0_band := f_vty_get_bts0_band();
2926 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2927 vc_conn.done;
2928 }
2929 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2931}
2932
2933testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2934 var ConnHdlr vc_conn;
2935 var ConnHdlrPars pars;
2936 f_init();
2937 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2938 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2939 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2940 pars.bts0_band := f_vty_get_bts0_band();
2941 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2942 vc_conn.done;
2943 }
2944 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2946}
2947
Eric Wild280ccb82019-06-17 11:11:52 +02002948testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2949 var ConnHdlr vc_conn;
2950 var ConnHdlrPars pars;
2951 f_init();
2952 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2953 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2954 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2955 pars.bts0_band := f_vty_get_bts0_band();
2956 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2957 vc_conn.done;
2958 }
2959 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2961}
2962
Eric Wild095024b2019-06-17 15:08:57 +02002963testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2964 var ConnHdlr vc_conn;
2965 var ConnHdlrPars pars;
2966 f_init();
2967 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2968 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2969 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2970 pars.bts0_band := f_vty_get_bts0_band();
2971 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2972 vc_conn.done;
2973 }
2974 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2976}
2977
Harald Welte70767382018-02-21 12:16:40 +01002978testcase TC_meas_res_sign_tchf() runs on test_CT {
2979 var ConnHdlr vc_conn;
2980 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002981 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002982 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2983 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002984 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2985 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002986 vc_conn.done;
2987 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002989}
2990testcase TC_meas_res_sign_tchh() runs on test_CT {
2991 var ConnHdlr vc_conn;
2992 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002993 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002994 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2995 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002996 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2997 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002998 vc_conn.done;
2999 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003001}
3002testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3003 var ConnHdlr vc_conn;
3004 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003005 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003006 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3007 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003008 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3009 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003010 vc_conn.done;
3011 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003013}
3014testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3015 var ConnHdlr vc_conn;
3016 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003017 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003018 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3019 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003020 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3021 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003022 vc_conn.done;
3023 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003025}
Harald Welte685d5982018-02-27 20:42:05 +01003026testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3027 var ConnHdlr vc_conn;
3028 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003029 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003030 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3031 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3032 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3033 pars.l1_pars.toa256_enabled := true;
3034 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3035 vc_conn.done;
3036 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003038}
3039
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003040/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3041 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003042private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003043 var L1ctlDlMessage l1_dl;
3044 var RSL_IE_MS_Power ms_power;
3045 var RSL_Message rsl;
3046 var uint5_t power_level := 0;
3047
3048 f_l1_tune(L1CTL);
3049 RSL.clear;
3050
3051 f_est_dchan();
3052
3053 ms_power.reserved := 0;
3054 ms_power.fpc_epc := false;
3055
3056 /* Send the first power control command. This will disable any BTS/TRX
3057 * internal power control and switch the MS (which is not in scope of
3058 * this test) to a constant power level. We start with a power level
3059 * of 0 */
3060 ms_power.power_level := power_level;
3061 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3062 RSL.send(rsl);
3063
3064 alt {
3065
3066 /* Pick all SACCH blocks for checking */
3067 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3068
3069 /* The first byte of the L1 header contains the power level.
3070 * The reserved bits and the fpc bit is set to 0, so we may
3071 * compare directly. */
3072 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3073 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3074 }
3075
3076 /* Signal a new power level via RSL for the next turn. */
3077 if (power_level < 31) {
3078 power_level := power_level + 1;
3079 ms_power.power_level := power_level;
3080 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3081 RSL.send(rsl);
3082 repeat;
3083 }
3084
3085 }
3086
3087 /* Ignore all other blocks */
3088 [] L1CTL.receive { repeat; }
3089
3090 }
3091
3092 f_rsl_chan_deact();
3093 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3094
3095 setverdict(pass);
3096}
3097
3098testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3099 var ConnHdlr vc_conn;
3100 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003101 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003102
3103 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3104 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3105 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3106 vc_conn.done;
3107 }
3108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3109}
Harald Welte70767382018-02-21 12:16:40 +01003110
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003111/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003112TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003113private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003114 var L1ctlDlMessage l1_dl;
3115 var uint5_t ta_to_test := 16;
3116
3117
3118 f_l1_tune(L1CTL);
3119 RSL.clear;
3120
3121 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003122 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003123
3124 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3125
3126
3127 alt {
3128
3129 /* Pick all SACCH blocks for checking */
3130 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3131
3132 /* The second byte of the L1 header contains the TA. */
3133 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3134 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3135 }
3136
3137 }
3138
3139 /* Ignore all other blocks */
3140 [] L1CTL.receive { repeat; }
3141
3142 }
3143
3144 f_rsl_chan_deact();
3145 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3146
3147 setverdict(pass);
3148}
3149
3150testcase TC_rsl_chan_initial_ta() runs on test_CT {
3151 var ConnHdlr vc_conn;
3152 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003153 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003154 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003155 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3156 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003157 vc_conn.done;
3158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3159}
3160
Eric Wilde57e1a62019-05-28 13:30:55 +02003161/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003162private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003163 var L1ctlDlMessage l1_dl;
3164 var uint5_t ms_power_level := 7;
3165
3166 var RSL_IE_MS_Power ms_power;
3167 ms_power.reserved := 0;
3168 ms_power.fpc_epc := false;
3169 ms_power.power_level := ms_power_level;
3170
3171 f_l1_tune(L1CTL);
3172 RSL.clear;
3173
3174 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3175
3176 timer T := 1.0;
3177 T.start;
3178 alt {
3179 /* Pick all SACCH blocks for checking */
3180 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3181 /* The first byte of the L1 header contains the power level.. */
3182 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3183 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3184 }
3185 }
3186 /* Ignore all other blocks */
3187 [] L1CTL.receive { repeat; }
3188 [] T.timeout {
3189 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3190 }
3191 }
3192
3193 f_rsl_chan_deact();
3194 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3195 setverdict(pass);
3196}
3197
3198testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3199 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3200 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3201}
3202
Harald Welte0472ab42018-03-12 15:02:26 +01003203/* 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 +01003204private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003205 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003206 RSL.clear;
3207
3208 f_est_dchan();
3209 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003210 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003211
3212 timer T := 40.0;
3213 T.start;
3214 alt {
3215 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3216 setverdict(pass)
3217 }
3218 [] RSL.receive { repeat };
3219 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003221 }
3222 }
3223 f_rsl_chan_deact();
3224}
3225testcase TC_conn_fail_crit() runs on test_CT {
3226 var ConnHdlr vc_conn;
3227 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003228 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003229 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3230 pars.t_guard := 60.0;
3231 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3232 vc_conn.done;
3233}
3234
Harald Welte93640c62018-02-25 16:59:33 +01003235/***********************************************************************
3236 * Paging
3237 ***********************************************************************/
3238
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003239private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003240 if (tmsi == 'FFFFFFFF'O) {
3241 return true;
3242 } else {
3243 return false;
3244 }
3245}
Harald Welte70767382018-02-21 12:16:40 +01003246
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003247private type record allowedFn { integer frame_nr }
3248private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3249private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3250private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3251private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3252private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3253private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3254private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3255private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3256private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003257{
3258 var integer frame_nr_51;
3259 frame_nr_51 := frame_nr mod 51
3260
3261 var allowedFn fn_check;
3262 fn_check.frame_nr := frame_nr_51;
3263
3264 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003266 return;
3267 }
3268
3269 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3270 return;
3271 }
3272 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3273 return;
3274 }
3275 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3276 return;
3277 }
3278 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3279 return;
3280 }
3281 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3282 return;
3283 }
3284 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3285 return;
3286 }
3287 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3288 return;
3289 }
3290 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3291 return;
3292 }
3293
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003295 return;
3296}
3297
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003298private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3299 inout integer num_paging_rcv_ids,
3300 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003301runs on test_CT {
3302 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003303 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 repeat;
3305 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003306 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003307 var octetstring without_plen :=
3308 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3309 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003310
3311 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3312
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003313 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3314 /* Ignore empty RR Paging Request (PCH filling) messages.
3315 * TODO: does it make sense to count them? */
3316 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003317 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3318 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003319 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003320 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3321 }
3322 } else if (match(rr, tr_PAGING_REQ2)) {
3323 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3324 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3325 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3326 }
3327 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3328 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3329 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003330 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003331 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3332 }
3333 } else if (match(rr, tr_PAGING_REQ3)) {
3334 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3335 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3336 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3337 }
3338 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3339 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3340 }
3341 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3342 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3343 }
3344 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3345 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3346 }
3347 }
3348 repeat;
3349 }
3350}
3351
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003352private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003353 boolean combined_ccch,
3354 integer bs_ag_blks_res,
3355 float load_factor,
3356 boolean exp_load_ind,
3357 boolean exp_overload,
3358 boolean use_tmsi
3359}
3360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003361private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003362 integer num_paging_sent,
3363 integer num_paging_rcv_msgs,
3364 integer num_paging_rcv_ids,
3365 integer num_overload
3366}
3367
Harald Welte68e495b2018-02-25 00:05:57 +01003368/* Helper function for paging related testing */
3369private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003370 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003371 f_init_l1ctl();
3372 f_l1_tune(L1CTL);
3373
3374 var PagingTestState st := {
3375 num_paging_sent := 0,
3376 num_paging_rcv_msgs := 0,
3377 num_paging_rcv_ids := 0,
3378 num_overload := 0
3379 };
3380
3381 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3382 var float max_pch_imsi_per_sec;
3383 if (cfg.use_tmsi) {
3384 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3385 } else {
3386 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3387 }
3388 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3389 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003390 var float time_total := 20.0;
3391 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3392 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003393
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003394 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3395 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003396
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003397 timer T_itv := 0.0;
3398 T_itv.start;
3399 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003400 alt {
3401 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003402 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003403 st.num_overload := st.num_overload + 1;
3404 repeat;
3405 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003406 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003408 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003409 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003410 log("Rx LOAD_IND");
3411 /* FIXME: analyze/verify interval + contents */
3412 repeat;
3413 }
3414 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003415 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003416 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003417 [] T_itv.timeout {
3418 /* Send paging cmds based on elapsed time */
3419 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3420 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003421 var MobileIdentityV mi;
3422
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003423 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003424 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003425 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003426 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003427 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003428 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003429
3430 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003431 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 +02003432
3433 st.num_paging_sent := st.num_paging_sent + 1;
3434 }
3435 if (st.num_paging_sent < pkt_total) {
3436 /* Wait for interval to next PAGING COMMAND */
3437 var float time_now := T_total.read;
3438 var float next_sched := int2float(st.num_paging_sent)*interval;
3439 if (next_sched > time_now) {
3440 T_itv.start(next_sched - time_now);
3441 } else {
3442 T_itv.start(0.0);
3443 }
3444 } else {
3445 /* We are done, no need to keep counting */
3446 T_total.stop;
3447 }
3448 }
3449 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003450 }
3451 }
3452
3453 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3454 timer T_wait := 18.0;
3455 T_wait.start;
3456 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003457 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003458 [] L1CTL.receive { repeat; }
3459 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003460 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3461 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003462 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003464 }
Harald Welte68e495b2018-02-25 00:05:57 +01003465 }
3466
3467 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3468 " rcvd_ids=", st.num_paging_rcv_ids);
3469 return st;
3470}
3471
3472/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3473 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3474 * - that CCCH LOAD IND (PCH) are being generated
3475 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3476testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003477 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003478 var PagingTestCfg cfg := {
3479 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003480 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003481 load_factor := 0.8,
3482 exp_load_ind := true,
3483 exp_overload := false,
3484 use_tmsi := false
3485 };
3486 var PagingTestState st := f_TC_paging(cfg);
3487 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3489 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003490 } else {
3491 setverdict(pass);
3492 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003494}
3495
3496/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3497 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3498 * - that CCCH LOAD IND (PCH) are being generated
3499 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3500testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003501 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003502 var PagingTestCfg cfg := {
3503 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003504 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003505 load_factor := 0.8,
3506 exp_load_ind := true,
3507 exp_overload := false,
3508 use_tmsi := true
3509 };
3510 var PagingTestState st := f_TC_paging(cfg);
3511 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3513 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003514 } else {
3515 setverdict(pass);
3516 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003518}
3519
3520/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3521 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3522 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3523 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3524testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003525 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003526 var PagingTestCfg cfg := {
3527 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003528 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003529 load_factor := 2.0,
3530 exp_load_ind := true,
3531 exp_overload := true,
3532 use_tmsi := false
3533 };
3534 var PagingTestState st := f_TC_paging(cfg);
3535 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3536 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003537 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003538 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003539 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 +01003540 } else {
3541 setverdict(pass);
3542 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003544}
3545
3546/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3547 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3548 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3549 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3550testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003551 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003552 var PagingTestCfg cfg := {
3553 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003554 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003555 load_factor := 2.0,
3556 exp_load_ind := true,
3557 exp_overload := true,
3558 use_tmsi := true
3559 };
3560 var PagingTestState st := f_TC_paging(cfg);
3561 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3562 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003563 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003564 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003565 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 +01003566 } else {
3567 setverdict(pass);
3568 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003570}
3571
3572
Harald Welte93640c62018-02-25 16:59:33 +01003573/***********************************************************************
3574 * Immediate Assignment / AGCH
3575 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003576private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003577 len := 0,
3578 ma := ''B
3579}
Harald Welte93640c62018-02-25 16:59:33 +01003580
Harald Weltee8d750e2018-06-10 21:41:35 +02003581private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3582 return int2str(num_tx) & " sent, "
3583 & int2str(num_rx) & " received, "
3584 & int2str(num_del) & " deleted";
3585}
3586
3587private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3588 var L1ctlDlMessage l1_dl;
3589 timer T := 10.0;
3590 var integer num_tx := 0;
3591 var integer num_rx := 0;
3592 var integer num_del := 0;
3593 var charstring res_str;
3594 var float rx_ratio;
3595
Harald Welte10474062019-05-30 16:48:17 +02003596 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003597 f_init_l1ctl();
3598 f_l1_tune(L1CTL);
3599
3600 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003601 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003602 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3603 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003604 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003605 num_tx := num_tx+1;
3606 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003607 }
3608 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003609 T.start;
3610 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003611 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003612 num_del := num_del+1;
3613 repeat;
3614 }
3615 [] RSL_CCHAN.receive {
3616 repeat;
3617 }
3618 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003619 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3620 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3621 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003622 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003623 } else {
3624 num_rx := num_rx+1;
3625 }
3626 repeat;
3627 }
3628 [] L1CTL.receive { repeat; }
3629 [] T.timeout { }
3630 }
3631 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3632 log("AGCH test: " & res_str);
3633 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003635 }
3636 rx_ratio := int2float(num_rx) / int2float(num_tx);
3637 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003638 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 +02003639 } else {
3640 setverdict(pass);
3641 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003643}
3644
Harald Weltee8d750e2018-06-10 21:41:35 +02003645/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3646testcase TC_imm_ass_1000_20ms() runs on test_CT {
3647 f_TC_imm_ass(1000, 0.02, 0.25);
3648}
3649
3650/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3651testcase TC_imm_ass_200_0ms() runs on test_CT {
3652 f_TC_imm_ass(200, 0.0, 0.05);
3653}
3654
3655/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3656testcase TC_imm_ass_200_76ms() runs on test_CT {
3657 f_TC_imm_ass(150, 0.076, 1.00);
3658}
3659
3660
3661
Harald Welte48494ca2018-02-25 16:59:50 +01003662/***********************************************************************
3663 * BCCH
3664 ***********************************************************************/
3665
3666/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003667private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003668 GsmFrameNumber frame_number,
3669 SystemInformation si
3670}
3671
3672/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003673private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003674
3675/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003676private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003677
3678/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003679private function f_si_vecslot_contains(SystemInformationVector arr,
3680 RrMessageType key,
3681 boolean bcch_ext := false)
3682return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003683 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3684 var integer fn_mod51 := arr[i].frame_number mod 51;
3685 if (not bcch_ext and fn_mod51 == 2 or
3686 bcch_ext and fn_mod51 == 6) {
3687 if (arr[i].si.header.message_type == key) {
3688 return true;
3689 }
3690 }
3691 }
3692 return false;
3693}
3694
3695/* 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 +07003696private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3697 integer tc, RrMessageType key,
3698 boolean ext_bcch := false)
3699{
Harald Welte48494ca2018-02-25 16:59:50 +01003700 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003702 }
3703}
3704
3705/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003706private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3707 RrMessageType key)
3708return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003709 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3710 if (f_si_vecslot_contains(arr[tc], key) or
3711 f_si_vecslot_contains(arr[tc], key, true)) {
3712 return true;
3713 }
3714 }
3715 return false;
3716}
3717
3718/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003719private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3720 RrMessageType key,
3721 boolean bcch_ext := false,
3722 integer n := 1, integer m := 4)
3723return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003724 var integer count := 0;
3725 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3727 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003728 }
3729 for (var integer i:= 0; i < m; i := i + 1) {
3730 var integer fn_mod51 := arr[i].frame_number mod 51;
3731 if (not bcch_ext and fn_mod51 == 2 or
3732 bcch_ext and fn_mod51 == 6) {
3733 if (arr[i].si.header.message_type == key) {
3734 count := count + 1;
3735 }
3736 }
3737 }
3738 if (count >= n) {
3739 return true;
3740 } else {
3741 return false;
3742 }
3743}
3744
3745/* 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 +07003746private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3747 integer tc, RrMessageType key,
3748 boolean ext_bcch := false,
3749 integer n, integer m)
3750{
Harald Welte48494ca2018-02-25 16:59:50 +01003751 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003753 }
3754}
3755
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_only(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 false;
3767 }
3768 }
3769 }
3770 return true;
3771}
3772
3773/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003774private function f_ensure_si_vec_contains_only(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_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003780 }
3781}
3782
3783/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003784private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003785 boolean bcch_extended,
3786 boolean si1_present,
3787 boolean si2bis_present,
3788 boolean si2ter_present,
3789 boolean si2quater_present,
3790 boolean si7_present,
3791 boolean si8_present,
3792 boolean si9_present,
3793 boolean si13_present,
3794 boolean si13alt_present,
3795 boolean si15_present,
3796 boolean si16_present,
3797 boolean si17_present,
3798 boolean si2n_present,
3799 boolean si21_present,
3800 boolean si22_present
3801}
3802
3803/* 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 +07003804private function f_validate_si_scheduling(SystemInformationConfig cfg,
3805 SystemInformationVectorPerTc si_per_tc)
3806{
Harald Welte48494ca2018-02-25 16:59:50 +01003807 var integer i;
3808 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3809 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003811 }
3812 }
3813 if (cfg.si1_present) {
3814 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3815 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3816 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3817 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3818 /* make sure *ALL* contain SI1 */
3819 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3820 }
3821 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3822 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3823 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3824 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3825 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3826 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3827
3828 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3829 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3830 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3831 * consecutive occurrences of TC = 4. */
3832 if (cfg.si2bis_present and not cfg.si2ter_present) {
3833 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3834 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3835 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3836 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3837 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3838 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3839 }
3840
3841 if (cfg.si7_present or cfg.si8_present) {
3842 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3843 * if System Information type 4 does not contain all information needed for cell
3844 * selection and reselection. */
3845 if (not cfg.bcch_extended) {
3846 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3847 }
3848 if (cfg.si7_present) {
3849 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3850 }
3851 if (cfg.si8_present) {
3852 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3853 }
3854 }
3855
3856 if (cfg.si2quater_present) {
3857 /* iii) System information type 2 quater is sent if needed, as determined by the system
3858 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3859 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3860 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3861 * within any of 4 consecutive occurrences of TC = 5. */
3862 if (not (cfg.bcch_extended)) {
3863 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3864 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3865 } else {
3866 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3867 }
3868 } else {
3869 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3870 }
3871 }
3872 if (cfg.si9_present) {
3873 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3874 * in system information type 3 as defined in 3GPP TS 44.018. */
3875 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3876 }
3877 if (cfg.si13_present) {
3878 /* vii) System Information type 13 is only related to the GPRS service. System Information
3879 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3880 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3881 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3882 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3883 * within any of 4 consecutive occurrences of TC=4. */
3884 if (not cfg.bcch_extended) {
3885 log("not-bccch-extended");
3886 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3887 } else {
3888 log("bccch-extended");
3889 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3890 }
3891 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003893 }
3894 }
3895 if (cfg.si16_present or cfg.si17_present) {
3896 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3897 * should not be sent in a cell where network sharing is used (see rule xv). */
3898 if (cfg.si22_present) {
3899 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3900 }
3901 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003903 }
3904 if (not cfg.bcch_extended) {
3905 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3906 }
3907 if (cfg.si16_present) {
3908 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3909 }
3910 if (cfg.si17_present) {
3911 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3912 }
3913 }
3914
3915 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3916 * broadcast information. The frequency with which they are sent is determined by the
3917 * system operator. System Information type 9 identifies the scheduling of System
3918 * Information type 18 and 20 messages. */
3919
3920 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3921 * Information Type 19 is present, then its scheduling shall be indicated in System
3922 * Information Type 9. */
3923
3924 if (cfg.si15_present) {
3925 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3926 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3927 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3928 * 4 consecutive occurrences of TC = 1. */
3929 if (not cfg.bcch_extended) {
3930 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3931 } else {
3932 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3933 }
3934 }
3935 if (cfg.si13alt_present) {
3936 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3937 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3938 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3939 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3940 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3941 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3942 * of TC = 4. */
3943 if (cfg.si13_present) {
3944 testcase.stop("Error: Cannot have SI13alt and SI13");
3945 }
3946 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003948 }
3949 if (not cfg.bcch_extended) {
3950 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3951 } else {
3952 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3953 }
3954 }
3955 if (cfg.si2n_present) {
3956 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3957 * as determined by the system operator. In the case that the message is sent on the
3958 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3959 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3960 * consecutive occurrences of TC = 4. */
3961 if (not cfg.bcch_extended) {
3962 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3963 } else {
3964 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3965 }
3966 }
3967 if (cfg.si21_present) {
3968 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3969 * determined by the system operator. If Extended Access Barring is in use in the cell
3970 * then this message is sent at least once within any of 4 consecutive occurrences of
3971 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3972 * cell then this message shall only be sent on BCCH Ext. */
3973 if (not cfg.bcch_extended) {
3974 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3975 } else {
3976 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3977 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003979 }
3980 }
3981 }
3982 if (cfg.si22_present) {
3983 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3984 * should not be sent in a cell where SoLSA is used (see rule viii). System
3985 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3986 * =2 and TC=6. */
3987 if (cfg.si16_present or cfg.si17_present) {
3988 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3989 }
3990 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3991 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003993 }
3994 if (not cfg.bcch_extended) {
3995 testcase.stop("Error: SI22 requires BCCH Extd!");
3996 } else {
3997 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3998 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3999 }
4000 }
4001}
4002
4003/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004004private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4005return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004006 timer T := duration;
4007 var SystemInformationVectorPerTc si_per_tc;
4008 var L1ctlDlMessage l1_dl;
4009
4010 /* initialize all per-TC vectors empty */
4011 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4012 si_per_tc[i] := {};
4013 }
4014
4015 /* flush all previous L1 queued msgs */
4016 pt.clear;
4017
4018 T.start;
4019 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004020 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004021 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4022 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4023 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004024 repeat;
4025 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004026
Harald Welte48494ca2018-02-25 16:59:50 +01004027 var integer tc := f_gsm_compute_tc(sig.frame_number);
4028 log("SI received at TC=", tc, ": ", sig.si);
4029 /* append to the per-TC bucket */
4030 si_per_tc[tc] := si_per_tc[tc] & { sig };
4031 repeat;
4032 }
4033 [] pt.receive { repeat; }
4034 [] T.timeout { }
4035 }
4036
4037 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4038 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4039 }
4040 log("si_per_tc=", si_per_tc);
4041 return si_per_tc;
4042}
4043
4044/* helper function: Set given SI via RSL + validate scheduling.
4045 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004046private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004047 var SystemInformationVectorPerTc si_per_tc;
4048 f_init_l1ctl();
4049 f_l1_tune(L1CTL);
4050
4051 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004052 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004053 f_validate_si_scheduling(si_cfg, si_per_tc);
4054
4055 setverdict(pass);
4056}
4057
4058testcase TC_si_sched_default() runs on test_CT {
4059 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004060 /* 2+3+4 are mandatory and set in f_init() */
4061 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004063}
4064
4065testcase TC_si_sched_1() runs on test_CT {
4066 f_init();
4067 si_cfg.si1_present := true;
4068 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004069 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004071}
4072
4073testcase TC_si_sched_2bis() runs on test_CT {
4074 f_init();
4075 si_cfg.si2bis_present := true;
4076 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4077 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004079}
4080
4081testcase TC_si_sched_2ter() runs on test_CT {
4082 f_init();
4083 si_cfg.si2ter_present := true;
4084 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4085 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004087}
4088
4089testcase TC_si_sched_2ter_2bis() runs on test_CT {
4090 f_init();
4091 si_cfg.si2bis_present := true;
4092 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4093 si_cfg.si2ter_present := true;
4094 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4095 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004097}
4098
4099testcase TC_si_sched_2quater() runs on test_CT {
4100 f_init();
4101 si_cfg.si2quater_present := true;
4102 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004103 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004105}
4106
4107testcase TC_si_sched_13() runs on test_CT {
4108 f_init();
4109 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004110 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004111 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004113}
4114
4115testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4116 f_init();
4117 si_cfg.si2bis_present := true;
4118 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4119 si_cfg.si2ter_present := true;
4120 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4121 si_cfg.si2quater_present := true;
4122 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4123 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004124 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004125 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004127}
4128
4129
Harald Welte68e495b2018-02-25 00:05:57 +01004130testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004131 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004132 /* FIXME: enable / disable individual BCCH info */
4133 //ts_RSL_BCCH_INFO(si_type, info);
4134 /* expect no ERROR REPORT after either of them *
4135 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004137}
4138
Harald Welte93640c62018-02-25 16:59:33 +01004139/***********************************************************************
4140 * Low-Level Protocol Errors / ERROR REPORT
4141 ***********************************************************************/
4142
Harald Welte01d982c2018-02-25 01:31:40 +01004143private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4144 timer T := 5.0;
4145 T.start;
4146 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004147 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004148 setverdict(pass);
4149 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004150 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004152 }
4153 [] RSL_CCHAN.receive {
4154 repeat;
4155 }
4156 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004158 }
4159 }
4160}
4161
4162/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4163testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004164 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004165 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4166 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004167 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004168
4169 f_exp_err_rep(RSL_ERR_PROTO);
4170}
4171
4172/* Provoke a mandatory IE error and match on ERROR REPORT */
4173testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004174 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004175
4176 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4177 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004178 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004179
4180 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4181}
4182
4183/* Provoke an IE content error and match on ERROR REPORT */
4184testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004185 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004186 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4187 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004188 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004189
4190 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4191}
4192
Harald Welteee25aae2019-05-19 14:32:37 +02004193/* attempt to activate channel with wrong RSL Message Discriminator IE */
4194function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4195 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4196 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4197 RSL.send(rsl);
4198 f_rslem_unregister(0, g_chan_nr);
4199}
4200testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4201 var ConnHdlr vc_conn;
4202 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4203
Harald Welte10474062019-05-30 16:48:17 +02004204 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004205
4206 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4207 vc_conn.done;
4208 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4209
4210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4211}
4212
4213/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004214private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004215 var template (value) RSL_Message rsl_tx;
4216 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4217 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4218 RSL.send(rsl_tx);
4219 f_rslem_unregister(0, g_chan_nr);
4220}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004221private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004222 var template (value) RSL_Message rsl_tx;
4223 /* we first have to activate the dedicated channel */
4224 f_rsl_chan_act(g_pars.chan_mode);
4225 /* ... to then send an invalid RLL message */
4226 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4227 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4228 RSL.send(rsl_tx);
4229 f_rslem_unregister(0, g_chan_nr);
4230}
4231testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4232 var ConnHdlr vc_conn;
4233 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4234 var template (value) RSL_Message rsl_tx;
4235
Harald Welte10474062019-05-30 16:48:17 +02004236 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004237
4238 /* Common Channel with wrong message type */
4239 RSL_CCHAN.clear;
4240 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4241 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004242 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004243 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4244
4245 /* TRX Management */
4246 RSL_CCHAN.clear;
4247 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4248 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004249 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004250 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4251
4252 /* Dedicated Channel */
4253 RSL_CCHAN.clear;
4254 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4255 vc_conn.done;
4256 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4257
4258 /* RLL */
4259 RSL_CCHAN.clear;
4260 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4261 vc_conn.done;
4262 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4263}
4264
4265/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004266private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004267 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4268 f_rslem_unregister(0, g_chan_nr);
4269}
4270testcase TC_err_rep_wrong_sequence() runs on test_CT {
4271 var ConnHdlr vc_conn;
4272 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4273
Harald Welte10474062019-05-30 16:48:17 +02004274 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004275
4276 RSL_CCHAN.clear;
4277 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4278 vc_conn.done;
4279 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4280}
4281
Harald Welte93640c62018-02-25 16:59:33 +01004282/***********************************************************************
4283 * IPA CRCX/MDCX/DLCS media stream handling
4284 ***********************************************************************/
4285
Harald Weltea871a382018-02-25 02:03:14 +01004286/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004287private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004288 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4289 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004290}
4291testcase TC_ipa_dlcx_not_active() runs on test_CT {
4292 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004293 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004294 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4295 vc_conn.done;
4296}
Harald Welte68e495b2018-02-25 00:05:57 +01004297
Harald Weltea3f1df92018-02-25 12:49:55 +01004298/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004299private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004300 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4301 "IPA CRCX ACK");
4302 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4303 "IPA CRCX NACK");
4304}
4305testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4306 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004307 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004308 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4309 vc_conn.done;
4310}
4311
4312/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004313private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004314 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4315 "IPA CRCX ACK");
4316 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4317 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4318 var uint7_t rtp_pt2 := f_rnd_int(127);
4319 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4320 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4321 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4322 "IPA MDCX ACK");
4323 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4324 "IPA DLCX ACK");
4325}
4326testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4327 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004328 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004329 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4330 vc_conn.done;
4331}
4332
Harald Welte3ae11da2018-02-25 13:36:06 +01004333/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004334private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004335 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4336 "IPA CRCX ACK");
4337 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4338 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4339 var uint7_t rtp_pt2 := f_rnd_int(127);
4340 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4341 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4342 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4343 "IPA MDCX ACK");
4344 /* Second MDCX */
4345 remote_ip := f_rnd_int(c_UINT32_MAX);
4346 remote_port := f_rnd_int(c_UINT16_MAX);
4347 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4348 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4349 "IPA MDCX ACK");
4350 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4351 "IPA DLCX ACK");
4352}
4353testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4354 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004355 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004356 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4357 vc_conn.done;
4358}
4359
Harald Welte9912eb52018-02-25 13:30:15 +01004360/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004361private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004362 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4363 "IPA CRCX NACK");
4364}
4365testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4366 var ConnHdlrPars pars;
4367 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004368 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004369
4370 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4371 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4372 vc_conn.done;
4373
4374 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4375 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4376 vc_conn.done;
4377}
4378
Harald Weltea3f1df92018-02-25 12:49:55 +01004379
Harald Welte883340c2018-02-28 18:59:29 +01004380/***********************************************************************
4381 * PCU Socket related tests
4382 ***********************************************************************/
4383
Harald Welte07bd2d22019-05-25 11:03:30 +02004384/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004385friend 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 +01004386runs on test_CT {
4387 timer T := 3.0;
4388
4389 /* we don't expect any RTS.req before PDCH are active */
4390 T.start;
4391 alt {
4392 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004394 }
4395 [] PCU.receive { repeat; }
4396 [] T.timeout { }
4397 }
4398
4399 /* Send PDCH activate request for known PDCH timeslot */
4400 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4401
4402 /* we now expect RTS.req for this timeslot (only) */
4403 T.start;
4404 alt {
4405 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4406 setverdict(pass);
4407 }
4408 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4409 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004411 }
4412 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004414 }
4415 [] PCU.receive { repeat; }
4416 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004418 }
4419 [not exp_success] T.timeout {
4420 setverdict(pass);
4421 }
4422 }
4423}
4424
Harald Welte07bd2d22019-05-25 11:03:30 +02004425/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004426friend 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 +01004427runs on test_CT {
4428 timer T := 3.0;
4429
4430 /* Send PDCH activate request for known PDCH timeslot */
4431 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 +02004432 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4433 * when it will actually have been executed in the BTS */
4434 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004435 PCU.clear;
4436 /* we now expect no RTS.req for this timeslot */
4437 T.start;
4438 alt {
4439 [] 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 +02004440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004441 }
4442 [] PCU.receive { repeat; }
4443 [] T.timeout {
4444 setverdict(pass);
4445 }
4446 }
4447}
4448
Harald Weltead033dc2019-05-25 17:28:16 +02004449friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004450 f_init();
4451 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4452}
4453
Harald Welte883340c2018-02-28 18:59:29 +01004454/* PDCH activation via PCU socket; check for presence of RTS.req */
4455testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004456 f_init_pcu_test();
4457
Harald Welte883340c2018-02-28 18:59:29 +01004458 f_TC_pcu_act_req(0, 0, 7, true);
4459}
4460
4461/* PDCH activation via PCU socket on non-PDCU timeslot */
4462testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004463 f_init_pcu_test();
4464
Harald Welte883340c2018-02-28 18:59:29 +01004465 f_TC_pcu_act_req(0, 0, 1, false);
4466}
4467
4468/* PDCH activation via PCU socket on wrong BTS */
4469testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004470 f_init_pcu_test();
4471
Harald Welte883340c2018-02-28 18:59:29 +01004472 f_TC_pcu_act_req(23, 0, 7, false);
4473}
4474
4475/* PDCH activation via PCU socket on wrong TRX */
4476testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004477 f_init_pcu_test();
4478
Harald Welte883340c2018-02-28 18:59:29 +01004479 f_TC_pcu_act_req(0, 23, 7, false);
4480}
4481
4482/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4483testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004484 f_init_pcu_test();
4485
Harald Welte883340c2018-02-28 18:59:29 +01004486 /* Activate PDCH */
4487 f_TC_pcu_act_req(0, 0, 7, true);
4488 f_sleep(1.0);
4489 /* and De-Activate again */
4490 f_TC_pcu_deact_req(0, 0, 7);
4491}
4492
4493/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4494testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004495 f_init_pcu_test();
4496
Harald Welte883340c2018-02-28 18:59:29 +01004497 f_TC_pcu_deact_req(0, 0, 1);
4498}
4499
4500/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4501testcase TC_pcu_ver_si13() runs on test_CT {
4502 const octetstring si13 := '00010203040506070909'O;
4503 var PCUIF_send_data sd;
4504 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004505 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004506
4507 /* Set SI13 via RSL */
4508 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004509
Harald Welte883340c2018-02-28 18:59:29 +01004510 T.start;
4511 alt {
4512 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4513 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4514 setverdict(pass);
4515 } else {
4516 repeat;
4517 }
4518 }
4519 [] PCU.receive { repeat; }
4520 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004522 }
4523 }
4524}
4525
4526private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4527
4528/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004529friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004530 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4531runs on test_CT
4532{
4533 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4534 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4535}
4536
4537/* 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 +02004538friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4539 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004540runs on test_CT
4541{
4542 var PCUIF_send_data sd;
4543
4544 timer T := 3.0;
4545 T.start;
4546 alt {
4547 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4548 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4549 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4550 sd.data.u.rts_req.fn, sapi, data);
4551 }
4552 [] PCU.receive { repeat; }
4553 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004555 }
4556 }
4557}
4558
4559/* Send DATA.req on invalid BTS */
4560testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004561 var TfiUsfArr tua := f_TfiUsfArrInit();
4562 var octetstring data := '0000'O & f_rnd_octstring(21);
4563
4564 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004565
Harald Welte883340c2018-02-28 18:59:29 +01004566 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004567 f_TfiUsfArrSet(tua, 7, 0);
4568 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4569 f_sleep(1.0);
4570
4571 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004572}
4573
4574/* Send DATA.req on invalid TRX */
4575testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004576 var TfiUsfArr tua := f_TfiUsfArrInit();
4577 var octetstring data := '0000'O & f_rnd_octstring(21);
4578
4579 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004580
Harald Welte883340c2018-02-28 18:59:29 +01004581 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004582 f_TfiUsfArrSet(tua, 7, 0);
4583 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4584 f_sleep(1.0);
4585
4586 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004587}
4588
4589/* Send DATA.req on invalid timeslot */
4590testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004591 var TfiUsfArr tua := f_TfiUsfArrInit();
4592 var octetstring data := '0000'O & f_rnd_octstring(21);
4593
4594 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004595
Harald Welte883340c2018-02-28 18:59:29 +01004596 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004597 f_TfiUsfArrSet(tua, 7, 0);
4598 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4599 f_sleep(1.0);
4600
4601 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004602}
4603
4604/* Send DATA.req on timeslot that hasn't been activated */
4605testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004606 var TfiUsfArr tua := f_TfiUsfArrInit();
4607 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004608
Harald Welte7162a612019-05-26 12:56:09 +02004609 f_virtphy_common();
4610
4611 f_TfiUsfArrSet(tua, 7, 0);
4612 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4613 f_sleep(1.0);
4614
4615 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004616}
4617
Harald Weltead033dc2019-05-25 17:28:16 +02004618private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004619 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4620 boolean wait_rts := true)
4621runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004622 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004623 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004624
4625 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004626 if (wait_rts) {
4627 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4628 } else {
4629 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4630 }
Harald Weltead033dc2019-05-25 17:28:16 +02004631
4632 T.start;
4633 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004634 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004635 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4636 setverdict(pass);
4637 }
Harald Welte7162a612019-05-26 12:56:09 +02004638 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4639 setverdict(fail, "Received unexpected ", rx_dl);
4640 }
Harald Weltead033dc2019-05-25 17:28:16 +02004641 [] L1CTL.receive {
4642 repeat;
4643 }
Harald Welte7162a612019-05-26 12:56:09 +02004644 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004645 setverdict(fail, "Timeout waiting for ", data);
4646 }
Harald Welte7162a612019-05-26 12:56:09 +02004647 [not expect_data] T.timeout {
4648 setverdict(pass);
4649 }
Harald Weltead033dc2019-05-25 17:28:16 +02004650 }
4651}
4652
4653private function f_disable_dynamic_ts() runs on test_CT
4654{
4655 f_init_vty_bsc();
4656 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4657 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4658 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4659 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004660 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004661}
4662
4663private function f_virtphy_common() runs on test_CT {
4664 f_disable_dynamic_ts();
4665 f_init_l1ctl();
4666 f_l1_tune(L1CTL);
4667}
4668
4669testcase TC_pcu_data_req_pdtch() runs on test_CT {
4670 var TfiUsfArr tua := f_TfiUsfArrInit();
4671 var octetstring data := '0000'O & f_rnd_octstring(21);
4672
4673 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004674
Harald Welte883340c2018-02-28 18:59:29 +01004675 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004676 f_TfiUsfArrSet(tua, 7, 0);
4677 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4678 f_sleep(1.0);
4679
4680 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004681}
4682
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004683/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004684testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004685 var TfiUsfArr tua := f_TfiUsfArrInit();
4686 var octetstring data := '0000'O & f_rnd_octstring(21);
4687
4688 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004689
Harald Welte883340c2018-02-28 18:59:29 +01004690 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004691 f_TfiUsfArrSet(tua, 7, 0);
4692 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4693 f_sleep(1.0);
4694
4695 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004696}
4697
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004698private function f_TC_pcu_ptcch_ul(uint16_t ra)
4699runs on test_CT {
4700 var template PCUIF_Message pcu_rach_ind;
4701 var PCUIF_send_data sd;
4702 var GsmFrameNumber fn;
4703 timer T;
4704
4705 /* Send an Access Burst on PTCCH/U over the Um-interface */
4706 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4707 chan_nr := ts_RslChanNr_PDCH(7),
4708 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4709
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004710 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4711 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004712
4713 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4714 T.start(52.0 * 4.615 / 1000.0);
4715 alt {
4716 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4717 log("Rx an Access Burst on the PCU interface: ", sd.data);
4718 setverdict(pass);
4719 T.stop;
4720 }
4721 [] PCU.receive { repeat; }
4722 [] T.timeout {
4723 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4724 /* Keep going, that's not the end of the world */
4725 }
4726 }
4727}
4728
4729testcase TC_pcu_ptcch() runs on test_CT {
4730 var L1ctlDlMessage dl;
4731 var octetstring data;
4732 timer T;
4733
4734 f_init_pcu_test();
4735 f_init_l1ctl();
4736 f_l1_tune(L1CTL);
4737
4738 /* Activate PDCH channel on TS7 */
4739 f_TC_pcu_act_req(0, 0, 7, true);
4740
4741 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004742 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004743 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004744 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004745 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004746
4747 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4748 for (var integer i := 0; i < 16; i := i + 1) {
4749 log("Sending an Access Burst towards the L1CTL interface");
4750 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4751 }
4752
4753 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4754 data := f_rnd_octstring(23);
4755
4756 /* Verify PTCCH/D: send a random data block, make sure it's received */
4757 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4758 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4759
4760 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4761 * let's give it more time in case if we miss the beginning. */
4762 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4763 alt {
4764 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4765 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4766 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4767 frame := data)) -> value dl {
4768 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4769 setverdict(pass);
4770 T.stop;
4771 }
4772 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4773 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4774 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4775 l2_data := data)) -> value dl {
4776 log("Rx PTCCH/D data block on L1CTL: ", dl);
4777 setverdict(pass);
4778 T.stop;
4779 }
4780 [] L1CTL.receive { repeat; }
4781 [] T.timeout {
4782 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4783 }
4784 }
4785}
4786
Harald Welte883340c2018-02-28 18:59:29 +01004787/* Send AGCH from PCU; check it appears on Um side */
4788testcase TC_pcu_data_req_agch() runs on test_CT {
4789 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004790 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004791 f_init_l1ctl();
4792 f_l1_tune(L1CTL);
4793
4794 f_TC_pcu_act_req(0, 0, 7, true);
4795 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4796
4797 T.start;
4798 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004799 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004800 setverdict(pass);
4801 }
4802 [] L1CTL.receive { repeat; }
4803 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004805 }
4806 }
4807}
4808
Harald Welte928622b2019-05-26 13:22:59 +02004809/* Send AGCH from PCU; check it appears on Um side */
4810testcase TC_pcu_data_req_pch() runs on test_CT {
4811 timer T := 3.0;
4812 f_init_pcu_test();
4813 f_init_l1ctl();
4814 f_l1_tune(L1CTL);
4815
4816 f_TC_pcu_act_req(0, 0, 7, true);
4817 /* three characters prefix: last 3 digits of IMSI as ASCII */
4818 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4819
4820 T.start;
4821 alt {
4822 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4823 setverdict(pass);
4824 }
4825 [] L1CTL.receive { repeat; }
4826 [] T.timeout {
4827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4828 }
4829 }
4830}
4831
Harald Welte883340c2018-02-28 18:59:29 +01004832/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4833testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4834 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004835 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004836 f_init_l1ctl();
4837 f_l1_tune(L1CTL);
4838
4839 /* append 3 last imsi digits so BTS can compute pagng group */
4840 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4841
4842 timer T := 0.5;
4843 T.start;
4844 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004845 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004846 /* TODO: verify paging group */
4847 setverdict(pass);
4848 }
4849 [] L1CTL.receive { repeat; }
4850 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004852 }
4853 }
4854}
4855
4856/* Send RACH from Um side, expect it to show up on PCU socket */
4857testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004858 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004859 f_init_l1ctl();
4860 f_l1_tune(L1CTL);
4861
4862 var GsmFrameNumber fn_last := 0;
4863 for (var integer i := 0; i < 1000; i := i+1) {
4864 var OCT1 ra := f_rnd_ra_ps();
4865 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4866 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004868 }
4869 fn_last := fn;
4870
4871 timer T := 2.0;
4872 T.start;
4873 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004874 [] 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 +01004875 T.stop;
4876 }
4877 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004879 }
4880 [] PCU.receive { repeat; }
4881 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004883 }
4884 }
4885 }
4886 setverdict(pass);
4887}
4888
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004889/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4890 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4891testcase TC_pcu_ext_rach_content() runs on test_CT {
4892 var template PCUIF_Message pcu_rach_ind;
4893 var GsmFrameNumber fn_last := 0;
4894 var L1ctlRachSynchSeq synch_seq;
4895 var PCUIF_BurstType pcu_bt;
4896 var GsmFrameNumber fn;
4897 var BIT11 ra11;
4898
4899 f_init_pcu_test();
4900 f_init_l1ctl();
4901 f_l1_tune(L1CTL);
4902
4903 for (var integer i := 0; i < 1000; i := i+1) {
4904 /* We need to test both TS1 & TS2 */
4905 if (i rem 2 == 0) {
4906 synch_seq := RACH_SYNCH_SEQ_TS1;
4907 pcu_bt := BURST_TYPE_1;
4908 } else {
4909 synch_seq := RACH_SYNCH_SEQ_TS2;
4910 pcu_bt := BURST_TYPE_2;
4911 }
4912
4913 ra11 := f_rnd_ra11_ps();
4914 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4915 if (fn == fn_last) {
4916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4917 "Two RACH in same FN?!?");
4918 }
4919 fn_last := fn;
4920
4921 /* Compose the expected message */
4922 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004923 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004924 ra := bit2int(ra11),
4925 is_11bit := 1,
4926 burst_type := pcu_bt,
4927 fn := fn);
4928
4929 timer T := 2.0;
4930 T.start;
4931 alt {
4932 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4933 T.stop;
4934 }
4935 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4937 }
4938 [] PCU.receive { repeat; }
4939 [] T.timeout {
4940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4941 }
4942 }
4943 }
4944 setverdict(pass);
4945}
4946
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004947private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4948runs on test_CT {
4949 var template PCUIF_send_data sdt;
4950 var PCUIF_send_data sd;
4951 var int16_t lqual_cb;
4952 timer T := 1.0;
4953
4954 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4955 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4956
4957 /* Send a random PDTCH frame over Um */
4958 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4959 '0000'O & f_rnd_octstring(21)));
4960
4961 T.start;
4962 alt {
4963 /* If expected link quality is above the threshold */
4964 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4965 lqual_cb := sd.data.u.data_ind.lqual_cb;
4966 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4967
4968 /* Make sure the actual link quality matches the expected value */
4969 if (not match(lqual_cb, lqual_cb_exp)) {
4970 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4971 "expected value ", lqual_cb_exp));
4972 } else {
4973 setverdict(pass);
4974 }
4975 }
4976 /* If expected link quality is below the threshold */
4977 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4979 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4980 }
4981 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4982 [] PCU.receive { repeat; }
4983 [lqual_cb_exp < thresh] T.timeout {
4984 log("Rx nothing, as expected");
4985 setverdict(pass);
4986 }
4987 [lqual_cb_exp >= thresh] T.timeout {
4988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4989 "Timeout waiting for PCUIF_DATA.ind");
4990 }
4991 }
4992}
4993
4994/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4995testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4996 f_init_pcu_test();
4997 PCU.clear;
4998
4999 f_init_l1ctl();
5000 f_l1_tune(L1CTL);
5001
5002 /* Activate a PDCH channel on TS7 */
5003 f_TC_pcu_act_req(0, 0, 7, true);
5004
5005 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005006 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005007 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005008 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005009 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005010
5011 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5012 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5013 var TrxcMessage ret;
5014
5015 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5016 valueof(ts_TRXC_FAKE_CI(i)));
5017
5018 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5019 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5020 }
5021}
5022
Harald Welte883340c2018-02-28 18:59:29 +01005023/* Send PAGING via RSL, expect it to shw up on PCU socket */
5024testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005025 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005026
5027 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005028 var MobileIdentityLV mi_lv;
5029 var octetstring mi_lv_enc;
5030 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005031 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005032
Harald Welte883340c2018-02-28 18:59:29 +01005033 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005034 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005035 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005036 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005037 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005038
5039 /* Fancy encoding for PCUIF */
5040 mi_lv := valueof(ts_MI_LV(mi));
5041 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5042 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005043
5044 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005045 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005046 T.start;
5047 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005048 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005049 }
5050 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005052 }
5053 [] PCU.receive { repeat; }
5054 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005056 }
5057 }
5058 }
5059 setverdict(pass);
5060}
5061
Harald Welted66c9b82019-05-25 09:03:15 +02005062/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5063testcase TC_pcu_time_ind() runs on test_CT {
5064 var PCUIF_send_data pcu_sd;
5065 var integer num_time_ind := 0;
5066 var integer first_fn, last_fn;
5067 var float test_duration := 5.0;
5068 timer T;
5069
5070 f_init_pcu_test();
5071 f_TC_pcu_act_req(0, 0, 7, true);
5072
5073 PCU.clear;
5074 T.start(test_duration);
5075 alt {
5076 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5077 num_time_ind := num_time_ind + 1;
5078 if (not isbound(first_fn)) {
5079 first_fn := pcu_sd.data.u.time_ind.fn;
5080 }
5081 last_fn := pcu_sd.data.u.time_ind.fn;
5082 repeat;
5083 }
5084 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5085 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5086 repeat;
5087 }
5088 [] PCU.receive {
5089 repeat;
5090 }
5091 [] T.timeout {}
5092 }
5093 var integer fn_expired := last_fn - first_fn;
5094 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5095
5096 /* verify the number of frames expired matches our expectation */
5097 const float c_GSM_FN_DURATION_MS := 4.61538;
5098 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005099 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005100 if (not match(fn_expired, t_fn_expected)) {
5101 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5102 }
5103
5104 /* There are three TIME.ind in every fn MOD 13 */
5105 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5106 /* Add some tolerance */
5107 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5108 if (not match(num_time_ind, t_time_ind_exp)) {
5109 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5110 }
5111
5112 setverdict(pass);
5113}
5114
Harald Welte4832c862019-05-25 14:57:18 +02005115/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5116testcase TC_pcu_rts_req() runs on test_CT {
5117 var PCUIF_send_data pcu_sd;
5118 var integer first_fn, last_fn;
5119 var integer num_rts_pdtch := 0;
5120 var integer num_rts_ptcch := 0;
5121 var float test_duration := 5.0;
5122 timer T;
5123
5124 f_init_pcu_test();
5125 f_TC_pcu_act_req(0, 0, 7, true);
5126
5127 PCU.clear;
5128 T.start(test_duration);
5129 alt {
5130 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5131 -> value pcu_sd {
5132 num_rts_pdtch := num_rts_pdtch + 1;
5133 if (not isbound(first_fn)) {
5134 first_fn := pcu_sd.data.u.rts_req.fn;
5135 }
5136 last_fn := pcu_sd.data.u.rts_req.fn;
5137 repeat;
5138 }
5139 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5140 -> value pcu_sd {
5141 num_rts_ptcch := num_rts_ptcch + 1;
5142 if (not isbound(first_fn)) {
5143 first_fn := pcu_sd.data.u.rts_req.fn;
5144 }
5145 last_fn := pcu_sd.data.u.rts_req.fn;
5146 repeat;
5147 }
5148 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5149 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5150 repeat;
5151 }
5152 [] PCU.receive {
5153 repeat;
5154 }
5155 [] T.timeout {}
5156 }
5157 var integer fn_expired := last_fn - first_fn;
5158 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5159 ", num_rts_ptcch=", num_rts_ptcch);
5160
5161 /* verify the number of frames expired matches our expectation */
5162 const float c_GSM_FN_DURATION_MS := 4.61538;
5163 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005164 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005165 if (not match(fn_expired, t_fn_expected)) {
5166 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5167 }
5168
5169 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5170 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5171 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5172 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5173 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5174 t_ptcch_exp);
5175 }
5176
5177 /* We have 12 PDTCH blocks every 52-multiframe */
5178 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5179 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5180 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5181 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5182 t_pdtch_exp);
5183 }
5184
5185 setverdict(pass);
5186}
5187
Harald Welte07bd2d22019-05-25 11:03:30 +02005188/* test for generating Abis side OML ALERT from the PCU */
5189testcase TC_pcu_oml_alert() runs on test_CT {
5190 var PCUIF_send_data pcu_sd;
5191 var integer num_time_ind := 0;
5192 var integer first_fn, last_fn;
5193 var float test_duration := 5.0;
5194 timer T;
5195
5196 f_init_pcu_test();
5197 f_TC_pcu_act_req(0, 0, 7, true);
5198
5199 /* re-connect CTRL port from BTS to BSC */
5200 f_ipa_ctrl_stop();
5201 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5202
5203 /* Send that OML Alert */
5204 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5205
5206 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5207 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5208 setverdict(pass);
5209}
5210
Harald Welteeaa9a862019-05-26 23:01:08 +02005211/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5212private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5213 var PCUIF_Message first_info;
5214 var integer pcu_conn_id := -1;
5215 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5216 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5217 var OCT4 tlli := '01020304'O;
5218 var OCT1 cause := '23'O;
5219 timer T := 5.0;
5220
5221 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5222
5223 f_l1_tune(L1CTL);
5224 RSL.clear;
5225
5226 f_est_dchan();
5227 L1CTL.clear;
5228
5229 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5230
5231 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5232 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5233 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5234
5235 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5236 T.start;
5237 alt {
5238 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5239 setverdict(pass);
5240 }
5241 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5242 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5243 }
5244 [] PCU.receive {
5245 repeat;
5246 }
5247 [] T.timeout {
5248 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5249 }
5250 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005251
5252 /* release the channel */
5253 f_rsl_chan_deact();
5254 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5255 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005256}
5257testcase TC_pcu_rr_suspend() runs on test_CT {
5258 var ConnHdlrPars pars;
5259 var ConnHdlr vc_conn;
5260
5261 f_init();
5262
5263 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5264 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5265 vc_conn.done;
5266}
Harald Welte07bd2d22019-05-25 11:03:30 +02005267
Harald Weltea2e0e942019-05-27 18:12:53 +02005268/* Ensure that PCUIF socket can accept only a single connection */
5269testcase TC_pcu_socket_connect_multi() runs on test_CT {
5270 timer T := 5.0;
5271
5272 /* this (among other things) establishes the first connection to the PCUIF socket */
5273 f_init();
5274
5275 /* try to establish a second connection, expect it to fail */
5276 PCU.send(UD_connect:{mp_pcu_socket, -1});
5277 T.start;
5278 alt {
5279 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5280 setverdict(pass);
5281 }
5282 [] PCU.receive(UD_connect_result:?) {
5283 setverdict(fail, "Unexpected unix domain connect result");
5284 }
5285 [] T.timeout {
5286 setverdict(pass);
5287 }
5288 }
5289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5290}
5291
Harald Weltec8effb72019-05-27 18:23:04 +02005292/* Ensure that PCUIF socket can disconnect + reconnect */
5293testcase TC_pcu_socket_reconnect() runs on test_CT {
5294 /* this (among other things) establishes the first connection to the PCUIF socket */
5295 f_init();
5296
5297 f_sleep(1.0);
5298
5299 f_pcuif_close(PCU, g_pcu_conn_id);
5300 g_pcu_conn_id := -1;
5301
5302 f_sleep(1.0);
5303
5304 /* re-connect */
5305 PCU.clear;
5306 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5307 setverdict(pass);
5308
5309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5310}
5311
Harald Weltebe030482019-05-27 22:29:35 +02005312/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005313private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5314runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005315 var L1ctlDlMessage l1_dl;
5316 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005317 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005318 timer T := 5.0;
5319 T.start;
5320 alt {
5321 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005322 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5323 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005324 repeat;
5325 }
5326 }
5327 [] pt.receive {
5328 repeat;
5329 }
5330 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5332 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005333 }
5334 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005335 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005336}
5337
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005338/* Check if GPRS Indicator is present in RR System Information of a given type */
5339private function f_si_has_gprs_indicator(RrMessageType si_type)
5340runs on test_CT return boolean {
5341 var SystemInformation si := f_get_si(L1CTL, si_type);
5342
5343 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005344 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005345 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005346 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005347 }
5348
5349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5350 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005351}
5352
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005353/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5354private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5355runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005356 /* don't call f_init() as this would connect PCU socket */
5357 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005358
5359 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005360 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005361 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005362
5363 f_init_l1ctl();
5364 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005365 f_sleep(2.0);
5366 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005367
5368 if (f_si_has_gprs_indicator(si_type)) {
5369 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005370 } else {
5371 setverdict(pass);
5372 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005373
Harald Weltebe030482019-05-27 22:29:35 +02005374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5375}
5376
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005377testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5378 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5379}
Harald Weltebe030482019-05-27 22:29:35 +02005380
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005381testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5382 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5383}
5384
5385/* Ensure that GPRS capability is advertised after PCU socket connect */
5386private function f_TC_pcu_socket_connect(RrMessageType si_type)
5387runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005388 /* this (among other things) establishes the first connection to the PCUIF socket */
5389 f_init();
5390 f_init_l1ctl();
5391 f_l1_tune(L1CTL);
5392
5393 f_sleep(2.0);
5394 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005395
5396 if (not f_si_has_gprs_indicator(si_type)) {
5397 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005398 } else {
5399 setverdict(pass);
5400 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005401
Harald Weltebe030482019-05-27 22:29:35 +02005402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5403}
5404
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005405testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5406 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5407}
Harald Weltebe030482019-05-27 22:29:35 +02005408
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005409testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5410 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5411}
5412
5413/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5414private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5415runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005416 /* this (among other things) establishes the first connection to the PCUIF socket */
5417 f_init();
5418 f_init_l1ctl();
5419 f_l1_tune(L1CTL);
5420
5421 f_pcuif_close(PCU, g_pcu_conn_id);
5422 g_pcu_conn_id := -1;
5423
5424 f_sleep(1.0);
5425
5426 /* re-connect */
5427 PCU.clear;
5428 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5429
5430 f_sleep(2.0);
5431 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005432
5433 if (f_si_has_gprs_indicator(si_type)) {
5434 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005435 } else {
5436 setverdict(pass);
5437 }
5438
5439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5440}
5441
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005442testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5443 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5444}
5445
5446testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5447 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5448}
5449
Oliver Smithf5239c72019-08-28 10:01:25 +02005450/* 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) */
5451testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5452 var SystemInformation si3 := valueof(ts_SI3_default);
5453
5454 f_init();
5455
Harald Welte76220222020-10-11 20:32:44 +02005456 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5457 * information */
5458 timer T := 2.0;
5459 T.start;
5460 alt {
5461 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5462 [] T.timeout {}
5463 }
5464
Oliver Smithf5239c72019-08-28 10:01:25 +02005465 /* Verify cell_id */
5466 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5467 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5468 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005469 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5470 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5471 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005472 }
5473
5474 /* Verify LAC */
5475 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5476 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5477 if (lac_si3 != lac_pcu) {
5478 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5479 }
5480
5481 setverdict(pass);
5482}
Harald Welted66c9b82019-05-25 09:03:15 +02005483
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005484/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5485testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5486 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005487 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005488
5489 f_init();
5490
5491 info_ind := g_pcu_last_info.u.info_ind;
5492
5493 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5494 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5495 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5496 /* Skip inactive timeslots */
5497 continue;
5498 }
5499
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005500 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005501 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005502 else
5503 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005504
5505 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005506 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005507 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005508 hsn := fhp.maio_hsn.hsn,
5509 maio := fhp.maio_hsn.maio,
5510 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005511 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005512 } else {
5513 tr_ts := tr_PCUIF_InfoTrxTsH0;
5514 }
5515
5516 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5517 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5518 if (not match(ts, tr_ts)) {
5519 setverdict(fail, "Hopping parameters do not match: ",
5520 "received ", ts, " vs expected ", tr_ts);
5521 } else {
5522 setverdict(pass);
5523 }
5524 }
5525 }
5526}
5527
Alexander Couzens5283f552020-07-28 15:39:04 +02005528/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5529testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5530 f_init_vty_bsc();
5531 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5532 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5533
5534 f_init();
5535
5536 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5537 if (not ischosen(remote_addr.v10)) {
5538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5539 log2str("Unexpected remote_addr: ", remote_addr));
5540 }
5541
5542 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5543 setverdict(fail, "Received address family is not IPv4");
5544 }
5545
5546 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5547 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5548 }
5549
5550 setverdict(pass);
5551}
5552
5553/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5554testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5555 f_init_vty_bsc();
5556 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5557
5558 f_init();
5559
5560 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5561 if (not ischosen(remote_addr.v10)) {
5562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5563 log2str("Unexpected remote_addr: ", remote_addr));
5564 }
5565
5566 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5567 setverdict(fail, "Received address family is not IPv6");
5568 }
5569
5570 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5571 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5572 }
5573
5574 setverdict(pass);
5575}
5576
Harald Welte3d04ae62018-04-04 20:29:05 +02005577/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005578 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005579 ***********************************************************************/
5580
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005581private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5582 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005583runs on ConnHdlr {
5584 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005585
5586 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005587 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005588 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5589 repeat;
5590 }
5591 }
5592}
5593
5594private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5595runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005596 /* Expect BTS to immediately acknowledge activation as PDCH */
5597 PCU.clear;
5598 f_rsl_chan_act(g_pars.chan_mode);
5599 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005600 timer T_wait := 2.0;
5601 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005602 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005603 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005604 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005605 [] T_wait.timeout {
5606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5607 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5608 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005609 }
5610 /* try to activate this PDCH from the PCU point of view */
5611 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5612 /* FIXME: is there a response? */
5613}
5614
5615private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5616runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005617 /* Send RSL CHAN REL (deactivate) */
5618 PCU.clear;
5619 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5620 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005621 timer T_wait := 2.0;
5622 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005623 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005624 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005625 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005626 [] T_wait.timeout {
5627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5628 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5629 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005630 }
5631 /* Emulate PCU asking BTS to deactivate PDCH */
5632 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5633 alt {
5634 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5635 setverdict(pass);
5636 }
5637 [] RSL.receive { repeat; }
5638 }
5639}
5640
5641/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005642private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005643 var PCUIF_Message first_info;
5644 var integer ts_nr := g_chan_nr.tn;
5645 var integer trx_nr := 0;
5646 var integer bts_nr := 0;
5647 var integer pcu_conn_id := -1;
5648
5649 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5650
5651 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5652 f_sleep(3.0);
5653 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5654 setverdict(pass);
5655}
5656testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5657 var ConnHdlrPars pars;
5658 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005659 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005660
5661 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5662 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5663 vc_conn.done;
5664}
5665
5666/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005667private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005668 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005669 var integer pcu_conn_id := -1;
5670
5671 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5672
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005673 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5674 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5675 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005676 setverdict(pass);
5677}
5678testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5679 var ConnHdlrPars pars;
5680 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005681 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005682
5683 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5684 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5685 vc_conn.done;
5686}
5687
5688/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005689private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005690 var PCUIF_Message first_info;
5691 var integer ts_nr := g_chan_nr.tn;
5692 var integer trx_nr := 0;
5693 var integer bts_nr := 0;
5694 var integer pcu_conn_id := -1;
5695
5696 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5697
5698 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005699 /* Send a second Chan Activ and expect it to be NACKed */
5700 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5701 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005702 setverdict(pass);
5703}
5704testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5705 var ConnHdlrPars pars;
5706 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005707 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005708
5709 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5710 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5711 vc_conn.done;
5712}
5713
5714/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005715private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005716 var PCUIF_Message first_info;
5717 var integer ts_nr := g_chan_nr.tn;
5718 var integer trx_nr := 0;
5719 var integer bts_nr := 0;
5720 var integer pcu_conn_id := -1;
5721 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5722
5723 /* register for the TCH/F channel number */
5724 f_rslem_register(0, chan_nr);
5725
5726 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5727
5728 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5729 "RSL CHAN ACT");
5730 setverdict(pass);
5731}
5732testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5733 var ConnHdlrPars pars;
5734 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005735 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005736
5737 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5738 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5739 vc_conn.done;
5740}
5741
5742/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005743private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005744 var PCUIF_Message first_info;
5745 var integer ts_nr := g_chan_nr.tn;
5746 var integer trx_nr := 0;
5747 var integer bts_nr := 0;
5748 var integer pcu_conn_id := -1;
5749 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5750 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5751
5752 /* register for the TCH/H channel numbers */
5753 f_rslem_register(0, chan_nr[0]);
5754 f_rslem_register(0, chan_nr[1]);
5755
5756 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5757
5758 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5759 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5760 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5761 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5762 setverdict(pass);
5763}
5764testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5765 var ConnHdlrPars pars;
5766 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005767 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005768
5769 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5770 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5771 vc_conn.done;
5772}
5773
Harald Welte9bbbfb52018-04-05 09:33:19 +02005774/***********************************************************************
5775 * IPA Style Dynamic Timeslot Support
5776 ***********************************************************************/
5777
5778private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5779runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005780 /* Expect BTS to immediately acknowledge activation as PDCH */
5781 PCU.clear;
5782 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5783 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005784 timer T_wait := 2.0;
5785 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005786 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005787 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005788 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005789 [] T_wait.timeout {
5790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5791 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5792 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005793 }
5794 /* try to activate this PDCH from the PCU point of view */
5795 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5796 /* FIXME: is there a response? */
5797
5798 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5799}
5800
5801private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5802runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005803 /* Send RSL CHAN REL (deactivate) */
5804 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5805 PCU.clear;
5806 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005807 timer T_wait := 2.0;
5808 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005809 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005810 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005811 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005812 [] T_wait.timeout {
5813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5814 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5815 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005816 }
5817 /* Emulate PCU asking BTS to deactivate PDCH */
5818 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5819 alt {
5820 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5821 setverdict(pass);
5822 }
5823 [] RSL.receive { repeat; }
5824 }
5825}
5826
5827/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005828private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005829 var PCUIF_Message first_info;
5830 var integer ts_nr := g_chan_nr.tn;
5831 var integer trx_nr := 0;
5832 var integer bts_nr := 0;
5833 var integer pcu_conn_id := -1;
5834
5835 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5836
5837 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5838 f_sleep(3.0);
5839 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5840
5841 setverdict(pass);
5842
5843}
5844testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5845 var ConnHdlrPars pars;
5846 var ConnHdlr vc_conn;
5847 f_init();
5848
5849 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5850 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5851 vc_conn.done;
5852}
5853
5854/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005855private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005856 var PCUIF_Message first_info;
5857 var integer ts_nr := g_chan_nr.tn;
5858 var integer trx_nr := 0;
5859 var integer bts_nr := 0;
5860 var integer pcu_conn_id := -1;
5861
5862 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5863
5864 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5865 "RSL CHAN ACT");
5866 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5867 "RF CHAN REL", true);
5868 setverdict(pass);
5869}
5870testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5871 var ConnHdlrPars pars;
5872 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005873 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005874
5875 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5876 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5877 vc_conn.done;
5878}
5879
5880/* 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 +07005881private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005882 var PCUIF_Message first_info;
5883 var integer ts_nr := g_chan_nr.tn;
5884 var integer trx_nr := 0;
5885 var integer bts_nr := 0;
5886 var integer pcu_conn_id := -1;
5887
5888 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5889
5890 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5891 "RSL CHAN ACT");
5892
5893 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5894 alt {
5895 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5896 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005898 }
5899 [] RSL.receive { repeat; }
5900 }
5901
5902 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5903 "RF CHAN REL", true);
5904 setverdict(pass);
5905}
5906testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5907 var ConnHdlrPars pars;
5908 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005909 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005910
5911 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5912 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5913 vc_conn.done;
5914}
5915
5916/* 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 +07005917private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005918 var PCUIF_Message first_info;
5919 var integer ts_nr := g_chan_nr.tn;
5920 var integer trx_nr := 0;
5921 var integer bts_nr := 0;
5922 var integer pcu_conn_id := -1;
5923
5924 /* register for the TCH/F channel number */
5925 f_rslem_register(0, g_chan_nr);
5926
5927 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5928
5929 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5930
5931 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5932 "RSL CHAN ACT");
5933
5934 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5935
5936 setverdict(pass);
5937}
5938testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5939 var ConnHdlrPars pars;
5940 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005941 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005942
5943 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5944 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5945 vc_conn.done;
5946}
5947
5948
Harald Welte0472ab42018-03-12 15:02:26 +01005949/***********************************************************************
5950 * LAPDm / RLL related
5951 ***********************************************************************/
5952
5953private function f_tx_lapdm(template (value) LapdmFrame l,
5954 template (value) RslLinkId link_id) runs on ConnHdlr {
5955 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005956 var template (value) SacchL1Header l1h;
5957
5958 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005959 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005960 /* Compose dummy L1 header */
5961 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5962 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 +02005963 } else {
5964 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005965 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 +01005966 }
Harald Welte0472ab42018-03-12 15:02:26 +01005967}
5968
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005969private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005970 uint3_t sapi,
5971 RslLinkId link_id,
5972 octetstring l3,
5973 boolean exp
5974}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005975private type record of RllTestCase RllTestCases;
5976private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5977 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005978 sapi := sapi,
5979 link_id := id,
5980 l3 := l3,
5981 exp := exp
5982}
5983
5984/* execute the same callback function with a set of different parameters (tcs) on a
5985 * variety of logical channels */
5986private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5987 var ConnHdlrPars pars;
5988 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005989 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005990
5991 /* test on each of the channels we have */
5992 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5993 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5994
5995 /* test each of the test cases on the current channel */
5996 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5997 pars.spec.rll := tcs[j];
5998 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5999 vc_conn := f_start_handler(fn, pars);
6000 vc_conn.done;
6001 }
6002 }
6003
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006005}
6006
6007/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6008private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6009 var RllTestCase tc := g_pars.spec.rll;
6010 timer T := 3.0;
6011
6012 f_l1_tune(L1CTL);
6013 RSL.clear;
6014
6015 /* activate the logical channel */
6016 f_est_dchan();
6017 L1CTL.clear;
6018
6019 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6020 T.start;
6021 alt {
6022 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6023 if (tc.exp) {
6024 setverdict(pass);
6025 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006027 }
6028 }
6029 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6030 if (tc.exp) {
6031 setverdict(pass);
6032 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006034 }
6035 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006036 /* We also expect to receive the measurements */
6037 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006038 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006040 }
6041 [not tc.exp] T.timeout {
6042 setverdict(pass);
6043 }
6044 }
6045
6046 f_rsl_chan_deact();
6047 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6048 f_rslem_unregister(0, g_chan_nr);
6049}
6050testcase TC_rll_est_ind() runs on test_CT {
6051 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006052 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006053 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006054 /* normal SAPI0 establishment */
6055 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006056 /* SAPI 3 doesn't support contention resolution */
6057 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6058 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6059 /* normal SAPI3 establishment on main DCCH */
6060 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6061 /* normal SAPI3 establishment on SACCH */
6062 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6063 };
6064 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6065}
6066
6067/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6068private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6069 var RllTestCase tc := g_pars.spec.rll;
6070 var L1ctlDlMessage dl;
6071 timer T := 3.0;
6072
6073 f_l1_tune(L1CTL);
6074 RSL.clear;
6075
6076 /* activate the logical channel */
6077 f_est_dchan();
6078 L1CTL.clear;
6079
6080 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6081 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6082 T.start;
6083 alt {
6084 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6085 var LapdmFrame lapdm;
6086 var octetstring l2 := dl.payload.data_ind.payload;
6087 if (dl.dl_info.link_id.c == SACCH) {
6088 /* remove L1 header */
6089 l2 := substr(l2, 2, lengthof(l2)-2);
6090 }
6091 lapdm.ab := dec_LapdmFrameAB(l2);
6092 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6093 setverdict(pass);
6094 } else {
6095 repeat;
6096 }
6097 }
6098 [] L1CTL.receive { repeat; }
6099 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006101 }
6102 }
6103
6104 f_rsl_chan_deact();
6105 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6106 f_rslem_unregister(0, g_chan_nr);
6107}
6108testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6109 var RllTestCases tcs := {
6110 /* normal SAPI3 establishment on main DCCH */
6111 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6112 };
6113 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6114}
6115testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6116 var RllTestCases tcs := {
6117 /* normal SAPI3 establishment on SACCH */
6118 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6119 }
6120 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6121}
6122
6123/* altstep to receive a LAPDm frame matching the given template */
6124private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6125 var L1ctlDlMessage dl;
6126 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6127 var LapdmFrame lapdm;
6128 var octetstring l2 := dl.payload.data_ind.payload;
6129 if (dl.dl_info.link_id.c == SACCH) {
6130 /* remove L1 header */
6131 l2 := substr(l2, 2, lengthof(l2)-2);
6132 }
6133 if (ischosen(exp.ab)) {
6134 lapdm.ab := dec_LapdmFrameAB(l2);
6135 } else if (ischosen(exp.b4)) {
6136 lapdm.b4 := dec_LapdmFrameB4(l2);
6137 } else if (ischosen(exp.bbis)) {
6138 lapdm.bbis := dec_LapdmFrameBbis(l2);
6139 }
6140 log("Rx LAPDm ", lapdm);
6141 if (match(lapdm, exp)) {
6142 setverdict(pass);
6143 } else {
6144 repeat;
6145 }
6146 }
6147 [] L1CTL.receive { repeat; }
6148}
6149private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6150 timer T := t;
6151 T.start;
6152 alt {
6153 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006155 }
6156 [] as_l1_exp_lapdm(exp);
6157 }
6158}
6159
6160/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6161private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6162 /* send SABM from MS -> BTS */
6163 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6164 /* expect RLL EST IND on Abis */
6165 alt {
6166 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6167 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6168 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006170 }
6171 [] RSL.receive { repeat; }
6172 }
6173 /* expect UA from BTS -> MS */
6174 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6175}
6176
6177/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6178private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6179 var RllTestCase tc := g_pars.spec.rll;
6180
6181 f_l1_tune(L1CTL);
6182 RSL.clear;
6183
6184 /* activate the logical channel */
6185 f_est_dchan();
6186 L1CTL.clear;
6187
6188 /* first establish the link-layer */
6189 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6190
6191 /* then send the DISC */
6192 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6193 /* ... and expect the REL IND on the RSL side */
6194 alt {
6195 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6196 setverdict(pass);
6197 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006198 /* We also expect to receive the measurements */
6199 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006200 }
6201
6202 /* release the channel */
6203 f_rsl_chan_deact();
6204 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6205 f_rslem_unregister(0, g_chan_nr);
6206}
6207testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6208 var RllTestCases tcs := {
6209 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6210 };
6211 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6212}
6213
6214testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6215 var RllTestCases tcs := {
6216 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6217 };
6218 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6219}
6220testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6221 var RllTestCases tcs := {
6222 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6223 };
6224 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6225}
6226testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6227 var RllTestCases tcs := {
6228 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6229 };
6230 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6231}
6232
6233/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6234private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6235 var RllTestCase tc := g_pars.spec.rll;
6236 f_l1_tune(L1CTL);
6237 RSL.clear;
6238
6239 /* activate the logical channel */
6240 f_est_dchan();
6241 L1CTL.clear;
6242
6243 /* first establish the link-layer */
6244 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6245
6246 /* then send the REL REQ via RSL */
6247 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6248 /* ... and expect the DISC on the Um side */
6249 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006250 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006251 /* FIXME: send a UA in resposne to the DISC */
6252 }
6253 }
6254
6255 /* release the channel */
6256 f_rsl_chan_deact();
6257 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6258 f_rslem_unregister(0, g_chan_nr);
6259}
6260testcase TC_rll_rel_req() runs on test_CT {
6261 var RllTestCases tcs := {
6262 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6263 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6264 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6265 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6266 };
6267 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6268}
6269
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006270/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006271testcase TC_rll_data_req() runs on test_CT {
6272}
6273
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006274/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006275testcase TC_rll_data_ind() runs on test_CT {
6276}
6277
6278/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6279private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6280 var RllTestCase tc := g_pars.spec.rll;
6281
6282 f_l1_tune(L1CTL);
6283 RSL.clear;
6284
6285 f_est_dchan();
6286 L1CTL.clear;
6287
6288 /* Send UNITDATA REQ on RSL side */
6289 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6290 /* Expect it to arrive on the other side */
6291 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006292 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006293 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006294 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006295 }
6296
6297 /* release the channel */
6298 f_rsl_chan_deact();
6299 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6300 f_rslem_unregister(0, g_chan_nr);
6301}
6302testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6303 var octetstring l3 := f_rnd_octstring(15);
6304 var RllTestCases tcs := {
6305 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6306 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6307 };
6308 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6309}
6310testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6311 var octetstring l3 := f_rnd_octstring(19);
6312 var RllTestCases tcs := {
6313 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6314 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6315 };
6316 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6317}
6318
6319/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6320private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6321 var RllTestCase tc := g_pars.spec.rll;
6322
6323 f_l1_tune(L1CTL);
6324 RSL.clear;
6325
6326 f_est_dchan();
6327 L1CTL.clear;
6328
6329 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006330 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006331 /* Expdct RLL UNITDATA IND on RSL side */
6332 alt {
6333 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6334 setverdict(pass);
6335 }
6336 [] RSL.receive { repeat; }
6337 }
6338
6339 /* release the channel */
6340 f_rsl_chan_deact();
6341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6342 f_rslem_unregister(0, g_chan_nr);
6343}
6344testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006345 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006346 var RllTestCases tcs := {
6347 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6348 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6349 };
6350 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6351}
6352testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6353 var octetstring l3 := f_rnd_octstring(18);
6354 var RllTestCases tcs := {
6355 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6356 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6357 };
6358 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6359}
6360
Harald Weltee613f962018-04-18 22:38:16 +02006361/***********************************************************************
6362 * Encryption Related
6363 ***********************************************************************/
6364
6365/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006366private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006367 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6368 if (link_id.c == SACCH) {
6369 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6370 } else {
6371 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6372 }
6373}
6374
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006375/* Expect (or not expect) other kinds of messages */
6376private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6377 [exp_any] RSL.receive { repeat; }
6378 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006380 }
6381}
6382
Harald Weltee613f962018-04-18 22:38:16 +02006383/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006384private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006385 RslLinkId link_id,
6386 octetstring l3,
6387 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006388 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006389) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006390 timer T := 3.0;
6391 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6392 T.start;
6393 /* Expect RLL UNITDATA IND on RSL side */
6394 alt {
6395 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6396 setverdict(pass);
6397 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006398 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006399 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006400 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006402 }
Harald Weltee613f962018-04-18 22:38:16 +02006403 }
6404}
6405
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006406/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6407private function f_data_mo(
6408 RslLinkId link_id,
6409 boolean p, uint3_t nr, uint3_t ns,
6410 octetstring l3,
6411 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006412 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006413) runs on ConnHdlr {
6414 timer T := 3.0;
6415 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6416 T.start;
6417 /* Expect RLL DATA IND on RSL side */
6418 alt {
6419 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6420 setverdict(pass);
6421 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006422 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006423 [] as_rsl_any_ind(exp_any);
6424 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006426 }
6427 }
6428}
6429
Harald Weltee613f962018-04-18 22:38:16 +02006430/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006431private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006432 f_l1_tune(L1CTL);
6433 f_est_dchan(true);
6434
6435 /* now we actually need to transmit some data both ways to check if the encryption works */
6436 var L1ctlDlMessage dl;
6437
Stefan Sperling603d98e2018-07-25 16:47:28 +02006438 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006439 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6440
6441 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6442 f_unitdata_mt(link_id, l3);
6443
6444 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6445 f_unitdata_mo(link_id, l3);
6446
6447 /* release the channel */
6448 f_rsl_chan_deact();
6449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6450 f_rslem_unregister(0, g_chan_nr);
6451}
6452testcase TC_chan_act_a51() runs on test_CT {
6453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6454 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6455 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6456}
6457testcase TC_chan_act_a52() runs on test_CT {
6458 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6459 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6460 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6461}
6462testcase TC_chan_act_a53() runs on test_CT {
6463 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6464 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6465 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6466}
6467
Eric Wildf1827a72019-05-28 17:37:35 +02006468/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6469 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 +07006470private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006471 f_l1_tune(L1CTL);
6472 f_est_dchan(true);
6473
6474 /* now we actually need to transmit some data both ways to check if the encryption works */
6475 var L1ctlDlMessage dl;
6476
6477 var octetstring l3 := f_rnd_octstring(20);
6478 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6479
6480 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6481 f_unitdata_mt(link_id, l3);
6482
6483 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6484 f_unitdata_mo(link_id, l3);
6485
6486 var RSL_Message rsl;
6487 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6488
6489 /* modify key to break proper encryption */
6490 g_pars.encr.key := f_rnd_octstring(8);
6491 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6492 rsl.ies := rsl.ies & { ei };
6493 RSL.send(rsl);
6494
6495 timer T0 := 1.0;
6496 T0.start;
6497 /* Expect RSL MODIFY ACK */
6498 alt {
6499 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6500 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6502 }
6503 [] T0.timeout {
6504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6505 }
6506 }
6507
6508 var octetstring l3msg := f_rnd_octstring(15);
6509 timer T1 := 3.0;
6510 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6511 due to broken encryption */
6512 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6513 T1.start;
6514 alt {
6515 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6517 }
6518 [] T1.timeout {
6519 setverdict(pass);
6520 }
6521 }
6522
6523 /* release the channel */
6524 f_rsl_chan_deact();
6525 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6526 f_rslem_unregister(0, g_chan_nr);
6527}
6528testcase TC_rsl_modify_encr() runs on test_CT {
6529 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6530 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6531 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6532}
Harald Weltee613f962018-04-18 22:38:16 +02006533
6534/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006535private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006536 /* L3 payload doesn't matter, as it is passed transparently */
6537 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6538 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6539 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6540
6541 f_l1_tune(L1CTL);
6542
6543 /* first establish a dedicated channel in the clear */
6544 f_est_dchan(false);
6545
6546 /* Establish ABM */
6547 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6548
6549 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6550 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6551 /* expect the L3 to arrive still unencrypted on the MS side */
6552 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6553
6554 /* configure L1 to apply ciphering */
6555 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6556 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6557
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006558 /* send first ciphered I-frame in response and expect it on RSL */
6559 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006560
6561 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6562 * and hence enable encryption also on the downlink */
6563
6564 /* expect bi-directional communication work in encrypted mode */
6565 f_unitdata_mo(link_id, f_rnd_octstring(15));
6566 f_unitdata_mt(link_id, f_rnd_octstring(15));
6567
6568 /* release the channel */
6569 f_rsl_chan_deact();
6570 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6571 f_rslem_unregister(0, g_chan_nr);
6572}
6573testcase TC_encr_cmd_a51() runs on test_CT {
6574 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6575 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6576 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6577}
6578testcase TC_encr_cmd_a52() runs on test_CT {
6579 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6580 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6581 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6582}
6583testcase TC_encr_cmd_a53() runs on test_CT {
6584 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6585 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6586 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6587}
6588
6589private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6590 var LapdmFrame lf;
6591 var octetstring reenc;
6592
6593 /* decode the LAPDm frame */
6594 if (ischosen(exp_match.ab)) {
6595 lf.ab := dec_LapdmFrameAB(enc);
6596 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006598 }
6599
6600 /* check if decoder result matches expectation */
6601 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006603 } else {
6604 log(name, ": matched");
6605 setverdict(pass);
6606 }
6607
6608 /* test if re-encoded frame equals original input */
6609 reenc := enc_LapdmFrame(lf);
6610 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006612 } else {
6613 setverdict(pass);
6614 }
6615}
6616
6617testcase TC_lapdm_selftest() runs on test_CT {
6618 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6619 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6620 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6621 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6622 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6623 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6624 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6625}
6626
Stefan Sperling4880be42018-08-07 18:12:59 +02006627/***********************************************************************
6628 * DTX Related (see GSM 05.08, section 8.3)
6629 ***********************************************************************/
6630
6631/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006632private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006633 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6634 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6635 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6636 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6637}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006638private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006639 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6640 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6641}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006642private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006643 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6644 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6645 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6646 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6647}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006648private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006649 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6650 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6651 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6652 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6653 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6654 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6655 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6656 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6657}
6658
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006659private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006660 var L1ctlDlMessage dl;
6661 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6662 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6663 var GsmFrameNumber first_fn;
6664 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006665 var integer nfill_frames_sacch := 0;
6666 var integer nfill_frames_nonsacch := 0;
6667 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006668 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6669 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006670 const integer frame_dtx_tchf_mod := 104;
6671 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6672 * which operates in terms of blocks rather than frames. */
6673 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6674 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006675 timer T := 5.0;
6676
6677 f_l1_tune(L1CTL);
6678 RSL.clear;
6679 L1CTL.clear;
6680
6681 /* activate TCHF signalling channel */
6682 f_est_dchan(false);
6683
6684 T.start;
6685 alt {
6686 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6687 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6688 var octetstring l2 := dl.payload.data_ind.payload;
6689
6690 if (is_first_frame) {
6691 is_first_frame := false;
6692 first_fn := dl.dl_info.frame_nr;
6693 }
6694
6695 if (dl.dl_info.link_id.c == SACCH) {
6696 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6697 if (not match(l2_fill_frame_sacch, l2)) {
6698 repeat;
6699 }
6700 } else if (not match(l2_fill_frame, l2)) {
6701 repeat;
6702 }
6703
6704 if (dtxd) {
6705 if (not f_g_chan_is_tchf()) {
6706 T.stop;
6707 f_rsl_chan_deact();
6708 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02006710 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006711 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006712 T.stop;
6713 f_rsl_chan_deact();
6714 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006715
6716 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6717 * 2 SACCH, 1 TCH/F */
6718 expected_fill_frames := 3;
6719
6720 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6721 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6722 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006724 } else {
6725 setverdict(pass);
6726 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006727 } else {
6728 if (dl.dl_info.link_id.c == SACCH) {
6729 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006730 repeat;
6731 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006732 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6733 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6734 * we should only see the subset of frames numbers which correspond to a block boundary.
6735 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6736 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6737 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6738 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6739 repeat;
6740 }
6741 }
6742 log("Received DTX TCH fill frame with bad frame number: ", fn,
6743 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6744 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6745 f_rsl_chan_deact();
6746 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006748 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006749 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006750 if (dl.dl_info.link_id.c == SACCH) {
6751 nfill_frames_sacch := nfill_frames_sacch + 1;
6752 } else {
6753 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6754 }
6755 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006756 T.stop;
6757 if (f_g_chan_is_tchf()) {
6758 /* Without DTX we can expect 25 fill frames for every 104 frames.
6759 * (24 FACCH + 1 SACCH filling) */
6760 expected_fill_frames := 25;
6761 } else if (f_g_chan_is_tchh()) {
6762 /* We can expect 2 fill frames for every 104 frames. */
6763 expected_fill_frames := 2;
6764 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6765 /* We can expect 5 fill frames for every 104 frames. */
6766 expected_fill_frames := 5;
6767 } else {
6768 f_rsl_chan_deact();
6769 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006771 }
6772
6773 f_rsl_chan_deact();
6774 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006775
6776 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006777 setverdict(pass);
6778 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006779 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6780 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006782 }
6783 } else {
6784 repeat;
6785 }
6786 }
6787 }
6788 [] L1CTL.receive { repeat; }
6789 [] T.timeout {
6790 f_rsl_chan_deact();
6791 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006793 }
6794 }
6795}
6796
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006797private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006798 f_test_l2_fill_frames(false);
6799}
6800
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006801private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006802 f_test_l2_fill_frames(true);
6803}
6804
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006805private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006806 var ConnHdlr vc_conn;
6807 var ConnHdlrPars pars;
6808 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006809 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006810 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6811 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6812 if (dtxd) {
6813 if (i >= 4) { /* DTX is only allowed on TCH/F */
6814 break;
6815 }
6816 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6817 } else {
6818 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6819 }
6820 vc_conn.done;
6821 }
6822}
6823
6824/* Verify that L2 fill frames are sent on TCH in signaling mode if
6825 * there is nothing to transmit while DTX is disabled on downlink. */
6826testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6827 f_tch_sign_l2_fill_frame(false);
6828}
6829
6830/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6831 * there is nothing to transmit while DTX is enabled on downlink. */
6832testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6833 f_tch_sign_l2_fill_frame(true);
6834}
Harald Welte0472ab42018-03-12 15:02:26 +01006835
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006836testcase TC_chopped_ipa_ping() runs on test_CT {
6837 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6838}
6839
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006840testcase TC_chopped_ipa_payload() runs on test_CT {
6841 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6842}
6843
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006844
6845/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6846 * Return value: Measurement Report to be sent (encoded octetstring). */
6847type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6848 runs on ConnHdlr return octetstring;
6849
6850private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6851runs on ConnHdlr {
6852 var L1ctlDlMessage l1_dl;
6853 var SacchL1Header l1h;
6854 var octetstring l2;
6855
6856 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6857 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6858 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6859 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6860
6861 /* Pass it to the user specified call-back function */
6862 l2 := cb.apply(l1h, num_blocks);
6863 /* Send a Measurement Report generated by the call-back */
6864 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6865 l1_dl.dl_info.link_id,
6866 l1h, l2));
6867
6868 /* Shall we keep going? */
6869 num_blocks := num_blocks - 1;
6870 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6871 if (num_blocks > 0) { repeat; }
6872 }
6873 [] L1CTL.receive { repeat; }
6874}
6875
6876private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6877runs on ConnHdlr return octetstring {
6878 /* Command the L1 to apply received parameters */
6879 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6880
6881 /* Dummy measurement report (the results are invalid) */
6882 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6883}
6884
6885private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6886runs on ConnHdlr return octetstring {
6887 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6888 setverdict(fail, "Unexpected MS Power level change: ",
6889 g_pars.l1_pars.ms_power_level, " -> ",
6890 l1h.ms_power_lvl);
6891 }
6892
6893 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6894}
6895
6896/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6897private function f_TC_ms_pwr_ctrl_constant(charstring id)
6898runs on ConnHdlr {
6899 var integer num_blocks := 8;
6900 timer T := int2float(num_blocks);
6901
6902 f_l1_tune(L1CTL);
6903 RSL.clear;
6904
6905 /* These IEs are needed for autonomous MS power control */
6906 var template (value) RSL_IE_List ies := {
6907 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6908 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6909 }),
6910 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6911 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6912 })
6913 };
6914
6915 /* Ensure that 'rx-current' equals 'rx-target' */
6916 f_trxc_fake_rssi(mp_uplink_power_target);
6917
6918 /* Establish a dedicated channel */
6919 f_est_dchan(more_ies := valueof(ies));
6920
6921 L1CTL.clear;
6922 T.start;
6923 alt {
6924 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6925 [] T.timeout {
6926 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6927 num_blocks, " were not handled");
6928 }
6929 }
6930}
6931testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6932 var ConnHdlr vc_conn;
6933 var ConnHdlrPars pars;
6934
6935 f_init();
6936
6937 /* Explicitly configure the Uplink power target (in dBm) */
6938 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6939
6940 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6941 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6942 log(testcasename(), ": starting on ", pars.chan_nr);
6943
6944 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6945 pars, trxc_comp := true);
6946 vc_conn.done;
6947 }
6948
6949 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6951}
6952
Harald Welte0472ab42018-03-12 15:02:26 +01006953/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6954/* protocol error as per 44.006 */
6955/* link layer failure (repetition of I-frame N200 times without ACK */
6956/* repetition of SABM or DISC N200 times without ACK */
6957/* receptiom of SABM in multi-frame established state */
6958
6959
Harald Welte68e495b2018-02-25 00:05:57 +01006960/* TODO Areas:
6961
6962* channel activation
6963** with BS_Power / MS_Power, bypassing power control loop
6964** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006965** with timing advance from initial activation on
6966* mode modify
6967** encryption
6968** multirate
6969* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006970** unsupported algorithm
6971* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006972* BS Power Control
6973* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006974* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006975* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006976** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006977* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006978** DATA_IND from BTS->PCU
6979** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006980
6981*/
Harald Welte70767382018-02-21 12:16:40 +01006982
6983control {
6984 execute( TC_chan_act_stress() );
6985 execute( TC_chan_act_react() );
6986 execute( TC_chan_deact_not_active() );
6987 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006988 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006989 execute( TC_sacch_filling() );
6990 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006991 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006992 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006993 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006994 execute( TC_sacch_chan_act_ho_async() );
6995 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006996 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006997 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006998 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006999 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007000 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007001 execute( TC_rach_load_idle_thresh0() );
7002 execute( TC_rach_load_idle_below_thresh() );
7003 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01007004 execute( TC_meas_res_sign_tchf() );
7005 execute( TC_meas_res_sign_tchh() );
7006 execute( TC_meas_res_sign_sdcch4() );
7007 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007008 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007009 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007010 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007011 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007012 execute( TC_rsl_bs_pwr_static_ass() );
7013 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007014 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007015 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007016 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007017 execute( TC_rsl_ms_pwr_dyn_up() );
7018 execute( TC_rsl_ms_pwr_dyn_down() );
7019 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7020 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007021 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007022 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007023 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007024 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007025 execute( TC_paging_imsi_80percent() );
7026 execute( TC_paging_tmsi_80percent() );
7027 execute( TC_paging_imsi_200percent() );
7028 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007029 execute( TC_rsl_protocol_error() );
7030 execute( TC_rsl_mand_ie_error() );
7031 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007032 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007033 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007034 execute( TC_si_sched_2bis() );
7035 execute( TC_si_sched_2ter() );
7036 execute( TC_si_sched_2ter_2bis() );
7037 execute( TC_si_sched_2quater() );
7038 execute( TC_si_sched_13() );
7039 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007040 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007041 execute( TC_ipa_crcx_twice_not_active() );
7042 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007043 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007044 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007045
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007046 if (mp_pcu_socket != "") {
7047 execute( TC_pcu_act_req() );
7048 execute( TC_pcu_act_req_wrong_ts() );
7049 execute( TC_pcu_act_req_wrong_bts() );
7050 execute( TC_pcu_act_req_wrong_trx() );
7051 execute( TC_pcu_deact_req() );
7052 execute( TC_pcu_deact_req_wrong_ts() );
7053 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007054 if (mp_l1_supports_gprs) {
7055 execute( TC_pcu_data_req_pdtch() );
7056 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007057 execute( TC_pcu_data_req_wrong_bts() );
7058 execute( TC_pcu_data_req_wrong_trx() );
7059 execute( TC_pcu_data_req_wrong_ts() );
7060 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007061 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007062 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007063 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007064 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007065 execute( TC_pcu_data_req_imm_ass_pch() );
7066 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007067 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007068 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007069 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007070 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007071 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007072 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007073 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007074 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007075 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007076 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007077 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007078 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007079 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007080 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007081 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007082 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007083 execute( TC_dyn_osmo_pdch_act_deact() );
7084 execute( TC_dyn_osmo_pdch_double_act() );
7085 execute( TC_dyn_ipa_pdch_act_deact() );
7086 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7087
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007088 if (PCUIF_Types.mp_pcuif_version >= 10) {
7089 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007090 execute( TC_pcu_socket_nsvc_ipv4() );
7091 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007092 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007093 } else {
7094 log("PCU socket path not available, skipping PCU tests");
7095 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007096
Harald Welte3d04ae62018-04-04 20:29:05 +02007097 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007098 execute( TC_dyn_osmo_pdch_tchf_act() );
7099 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007100 execute( TC_dyn_ipa_pdch_tchf_act() );
7101 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007102
7103 execute( TC_rll_est_ind() );
7104 execute( TC_rll_est_req_DCCH_3() );
7105 execute( TC_rll_est_req_ACCH_3() );
7106 execute( TC_rll_rel_ind_DCCH_0() );
7107 execute( TC_rll_rel_ind_DCCH_3() );
7108 execute( TC_rll_rel_ind_ACCH_0() );
7109 execute( TC_rll_rel_ind_ACCH_3() );
7110 execute( TC_rll_rel_req() );
7111 execute( TC_rll_unit_data_req_DCCH() );
7112 execute( TC_rll_unit_data_req_ACCH() );
7113 execute( TC_rll_unit_data_ind_DCCH() );
7114 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007115
7116 execute( TC_chan_act_a51() );
7117 execute( TC_chan_act_a52() );
7118 execute( TC_chan_act_a53() );
7119 execute( TC_encr_cmd_a51() );
7120 execute( TC_encr_cmd_a52() );
7121 execute( TC_encr_cmd_a53() );
7122
Harald Welteee25aae2019-05-19 14:32:37 +02007123 execute( TC_err_rep_wrong_mdisc() );
7124 execute( TC_err_rep_wrong_msg_type() );
7125 execute( TC_err_rep_wrong_sequence() );
7126
Harald Weltee613f962018-04-18 22:38:16 +02007127 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007128
7129 execute( TC_tch_sign_l2_fill_frame() );
7130 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007131
7132 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007133 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007134
7135 execute( TC_ms_pwr_ctrl_constant() );
Harald Welte70767382018-02-21 12:16:40 +01007136}
7137
7138
7139}