blob: 89d1d2c1bb2c03c73da5c803647f9b47e66ade6f [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();
689 [not ignore_other] as_l1_dcch();
690 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100692 }
Harald Welte21240e62018-03-11 21:43:35 +0100693 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welteb1726c92018-03-30 11:56:38 +0200695 return rx;
696}
697
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700698friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
699 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200700runs on ConnHdlr {
701 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100702}
703
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700704friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
705 boolean encr_enable := false,
706 RSL_IE_List more_ies := {},
707 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
708runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200709 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200710 if (encr_enable) {
711 /* append encryption related IEs, if requested */
712 var RSL_IE_EncryptionInfo encr_info;
713 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
714 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
715encr_info})) };
716 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200717 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200718 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100719}
720
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700721friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100722 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 +0100723 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100724}
725
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700726/* Default Mobile Allocation to be used for frequency hopping */
727private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
728 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
729
Harald Welte2f2b2b72019-05-31 22:24:57 +0200730friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100731 template RSL_IE_ChannelMode chan_mode,
732 float t_guard := 20.0) := {
733 chan_nr := valueof(chan_nr),
734 chan_mode := valueof(chan_mode),
735 t_guard := t_guard,
736 l1_pars := {
737 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100738 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100739 meas_ul := {
740 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200741 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100742 rxqual := 0
743 },
744 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200745 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100746 rxqual := 0
747 }
748 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200749 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100750 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200751 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200752 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100753 },
Harald Weltee613f962018-04-18 22:38:16 +0200754 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200755 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700756 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700757 fhp := {
758 enabled := false,
759 maio_hsn := ts_HsnMaio(0, 0),
760 ma_map := c_MA_null,
761 ma := l1ctl_ma_def
762 }
Harald Welte70767382018-02-21 12:16:40 +0100763}
764
Harald Welte93640c62018-02-25 16:59:33 +0100765/***********************************************************************
766 * Channel Activation / Deactivation
767 ***********************************************************************/
768
Harald Welte70767382018-02-21 12:16:40 +0100769/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700770private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100771 for (var integer i := 0; i < 500; i := i+1) {
772 f_rsl_chan_act(g_pars.chan_mode);
773 f_rsl_chan_deact();
774 }
775 setverdict(pass);
776}
777testcase TC_chan_act_stress() runs on test_CT {
778 var ConnHdlr vc_conn;
779 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200780 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100781 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
782 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100784}
785
786/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700787private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100788 f_rsl_chan_act(g_pars.chan_mode);
789 /* attempt to activate the same lchan again -> expect reject */
790 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
791 alt {
792 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100794 }
795 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
796 setverdict(pass);
797 }
798 }
799 f_rsl_chan_deact();
800}
801testcase TC_chan_act_react() runs on test_CT {
802 var ConnHdlr vc_conn;
803 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100804 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100805 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
806 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100808}
809
810/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700811private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100812 timer T := 3.0;
813 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
814 T.start;
815 alt {
816 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
817 setverdict(pass);
818 }
819 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100821 }
822 }
823}
824testcase TC_chan_deact_not_active() runs on test_CT {
825 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100826 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100827 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
828 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100830}
831
832/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700833private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100834 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
835 alt {
836 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100838 }
839 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
840 setverdict(pass);
841 }
842 }
843}
844private type record WrongChanNrCase {
845 RslChannelNr chan_nr,
846 charstring description
847}
848private type record of WrongChanNrCase WrongChanNrCases;
849private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
850 chan_nr := chan_nr,
851 description := desc
852}
853
854testcase TC_chan_act_wrong_nr() runs on test_CT {
855 var ConnHdlr vc_conn;
856 var ConnHdlrPars pars;
857
Harald Welte294b0a22018-03-10 23:26:48 +0100858 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100859
860 var WrongChanNrCases wrong := {
861 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
862 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
863 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
864 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
866 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
867 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
868 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
869 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
870 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
871 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
872 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
873 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
874 };
875
876 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
877 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
878 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
879 vc_conn.done;
880 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100882}
883
Harald Weltee613f962018-04-18 22:38:16 +0200884/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200885friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200886 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200887 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200888
889 /* test on each of the channels we have */
890 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
891 pars.chan_nr := valueof(g_AllChanTypes[i]);
892
893 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
894 vc_conn := f_start_handler(fn, pars);
895 vc_conn.done;
896 }
897
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200899}
900
Harald Welte93640c62018-02-25 16:59:33 +0100901/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100902 * SACCH handling
903 ***********************************************************************/
904
905private function f_exp_sacch(boolean exp) runs on ConnHdlr {
906 timer T_sacch := 3.0;
907 T_sacch.start;
908 alt {
909 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100911 }
912 [not exp] T_sacch.timeout {
913 setverdict(pass);
914 }
915 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
916 setverdict(pass);
917 }
918 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100920 }
921 [] L1CTL.receive { repeat; }
922 [] RSL.receive { repeat; }
923 }
924}
925
926/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
927private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
928 f_l1_tune(L1CTL);
929 RSL.clear;
930
931 /* activate the logical channel */
932 f_est_dchan();
933 L1CTL.clear;
934
935 /* check that SACCH actually are received as expected */
936 f_exp_sacch(true);
937
938 /* deactivate SACCH on the logical channel */
939 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
940 f_sleep(1.0);
941 L1CTL.clear;
942
943 /* check that no SACCH are received anymore */
944 f_exp_sacch(false);
945
946 /* release the channel */
947 f_rsl_chan_deact();
948 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
949}
950testcase TC_deact_sacch() runs on test_CT {
951 var ConnHdlr vc_conn;
952 var ConnHdlrPars pars;
953 f_init();
954 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
955 //for (var integer i := 0; i < 1; i := i+1) {
956 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
957 log(testcasename(), ": Starting for ", g_AllChannels[i]);
958 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
959 vc_conn.done;
960 }
961 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100963}
964
Harald Welte55700662018-03-12 13:15:43 +0100965/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100966private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
967 var L1ctlDlMessage dl;
968 /* check that the specified SI5 value is actually sent */
969 timer T_sacch := 3.0;
970 L1CTL.clear;
971 T_sacch.start;
972 alt {
973 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
974 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
975 if (match(l3, l3_exp)) {
976 setverdict(pass);
977 } else {
978 repeat;
979 }
980 }
981 [] L1CTL.receive { repeat; }
982 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100984 }
985 }
986}
987
Harald Welte55700662018-03-12 13:15:43 +0100988/* verify that given SACCH payload is not present */
989private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
990 var L1ctlDlMessage dl;
991 /* check that the specified SI5 value is actually sent */
992 timer T_sacch := 3.0;
993 L1CTL.clear;
994 T_sacch.start;
995 alt {
996 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
997 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
998 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001000 } else {
1001 repeat;
1002 }
1003 }
1004 [] L1CTL.receive { repeat; }
1005 [] T_sacch.timeout {
1006 setverdict(pass);
1007 }
1008 }
1009}
1010
Harald Welte629cc6b2018-03-11 17:19:05 +01001011/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001012private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1013 /* Set a known default SACCH filling for SI5 */
1014 var octetstring si5 := f_rnd_octstring(19);
1015 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1016
1017 f_l1_tune(L1CTL);
1018 RSL.clear;
1019
1020 /* activate the logical channel */
1021 f_est_dchan();
1022
1023 /* check that the specified SI5 value is actually sent */
1024 f_sacch_present(si5);
1025
1026 /* release the channel */
1027 RSL.clear;
1028 f_rsl_chan_deact();
1029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1030}
1031testcase TC_sacch_filling() runs on test_CT {
1032 var ConnHdlr vc_conn;
1033 var ConnHdlrPars pars;
1034 f_init();
1035 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1036 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1037 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1038 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1039 vc_conn.done;
1040 }
1041 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001043}
1044
Harald Welte629cc6b2018-03-11 17:19:05 +01001045/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001046private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1047 /* Set a known default SACCH filling for SI5 */
1048 var octetstring si5 := f_rnd_octstring(19);
1049 var octetstring si5_diff := f_rnd_octstring(19);
1050 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1051
1052 f_l1_tune(L1CTL);
1053 RSL.clear;
1054
1055 log("Activating channel, expecting standard SI5");
1056 /* activate the logical channel */
1057 f_est_dchan();
1058 /* check that the specified SI5 value is actually sent */
1059 f_sacch_present(si5);
1060
1061 /* set channel-specific different SI5 */
1062 log("Setting channel specific SACCH INFO, expecting it");
1063 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1064 /* check that the specified lchan-specific value is now used */
1065 f_sacch_present(si5_diff);
1066
1067 /* deactivate the channel and re-activate it, this should result in default SI5 */
1068 log("De-activating and re-activating channel, expecting standard SI5");
1069 f_rsl_chan_deact();
1070 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1071 /* Verify that the TRX-wide default SACCH filling is present again */
1072 f_sacch_present(si5);
1073
1074 /* release the channel */
1075 RSL.clear;
1076 f_rsl_chan_deact();
1077 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1078}
1079testcase TC_sacch_info_mod() runs on test_CT {
1080 var ConnHdlr vc_conn;
1081 var ConnHdlrPars pars;
1082 f_init();
1083 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1084 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1085 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1086 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1087 vc_conn.done;
1088 }
1089 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001091}
1092
Harald Welte075d84c2018-03-12 13:07:24 +01001093/* Test SACCH scheduling of multiple different SI message types */
1094private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1095 var octetstring si5 := f_rnd_octstring(19);
1096 var octetstring si5bis := f_rnd_octstring(19);
1097 var octetstring si5ter := f_rnd_octstring(19);
1098 var octetstring si6 := f_rnd_octstring(19);
1099
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1104
1105 f_l1_tune(L1CTL);
1106 RSL.clear;
1107
1108 /* activate the logical channel */
1109 f_est_dchan();
1110 L1CTL.clear;
1111
1112 /* check that SACCH actually are received as expected */
1113 f_sacch_present(si5);
1114 f_sacch_present(si5bis);
1115 f_sacch_present(si5ter);
1116 f_sacch_present(si6);
1117
1118 /* release the channel */
1119 f_rsl_chan_deact();
1120 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1121}
1122testcase TC_sacch_multi() runs on test_CT {
1123 var ConnHdlr vc_conn;
1124 var ConnHdlrPars pars;
1125 f_init();
1126 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1127 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1128 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1129 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1130 vc_conn.done;
1131 }
1132 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001134}
1135
Harald Welte55700662018-03-12 13:15:43 +01001136/* Test if SACH information is modified as expected */
1137private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1138 var octetstring si5 := f_rnd_octstring(19);
1139 var octetstring si6 := f_rnd_octstring(19);
1140
1141 /* First, configure both SI5 and SI6 to be transmitted */
1142 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1143 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1144
1145 f_l1_tune(L1CTL);
1146 RSL.clear;
1147
1148 /* activate the logical channel */
1149 f_est_dchan();
1150 L1CTL.clear;
1151
1152 /* check that SACCH actually are received as expected */
1153 f_sacch_present(si5);
1154 f_sacch_present(si6);
1155
1156 /* disable SI6 */
1157 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1158
1159 /* check that SI5 is still transmitted */
1160 f_sacch_present(si5);
1161 /* check if SI6 is now gone */
1162 f_sacch_missing(si6);
1163
1164 /* release the channel */
1165 f_rsl_chan_deact();
1166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1167}
1168testcase TC_sacch_multi_chg() runs on test_CT {
1169 var ConnHdlr vc_conn;
1170 var ConnHdlrPars pars;
1171 f_init();
1172 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1173 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1174 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1175 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1176 vc_conn.done;
1177 }
1178 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001180}
1181
Harald Weltec8d363c2019-05-19 20:36:48 +02001182/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1183private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1184 var octetstring si5 := f_rnd_octstring(19);
1185 var octetstring si6 := f_rnd_octstring(19);
1186 var octetstring si5_specific := f_rnd_octstring(19);
1187 var octetstring si6_specific := f_rnd_octstring(19);
1188
1189 /* First, configure both SI5 and SI6 to be transmitted */
1190 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1191 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1192
1193 f_l1_tune(L1CTL);
1194 RSL.clear;
1195
1196 /* activate channel with different SACCH filling */
1197 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1198 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1199 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1200 }));
1201 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1202 RSL_IE_Body:{sacch_info := sacch_info})) };
1203 f_est_dchan(more_ies := addl_ies);
1204
1205 /* check that SACCH actually are received as expected */
1206 f_sacch_present(si5_specific);
1207 f_sacch_present(si6_specific);
1208
1209 /* release the channel */
1210 f_rsl_chan_deact();
1211 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1212}
1213testcase TC_sacch_chan_act() runs on test_CT {
1214 var ConnHdlr vc_conn;
1215 var ConnHdlrPars pars;
1216 f_init();
1217
1218 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1219 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1220 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1221 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1222 vc_conn.done;
1223 }
1224 /* TODO: do the above in parallel, rather than sequentially? */
1225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1226}
1227
Harald Welte8b01c792019-05-19 22:51:25 +02001228/* verify that SACCH DL transmission is started only if MS power IE present
1229 * see section 4.1.3 of 3GPP TS 48.058 */
1230private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1231 var octetstring si5 := f_rnd_octstring(19);
1232
1233 f_l1_tune(L1CTL);
1234 RSL.clear;
1235
1236 /* Step 1: Activate ASYNC HO channel without MS power IE */
1237
1238 /* Activate channel on BTS side */
1239 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1240 /* don't perform immediate assignment here, as we're testing non-IA case */
1241 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001242 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001243
1244 /* Verify that no DL SACCH is being received */
1245 f_sacch_missing(?);
1246
1247 f_rsl_chan_deact();
1248 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1249
1250
1251 /* Step 2: Activate ASYNC HO channel with MS power IE */
1252
1253 /* Activate channel on BTS side */
1254 var RSL_IE_List addl_ies := {
1255 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1256 };
1257 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1258 /* don't perform immediate assignment here, as we're testing non-IA case */
1259 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001260 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001261
1262 /* Verify that DL SACCH is being received */
1263 f_sacch_present(si5);
1264
1265 f_rsl_chan_deact();
1266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1267}
1268testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1269 var ConnHdlr vc_conn;
1270 var ConnHdlrPars pars;
1271 f_init();
1272
1273 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1274 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1275 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1276 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1277 vc_conn.done;
1278 }
1279 /* TODO: do the above in parallel, rather than sequentially? */
1280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1281}
1282
1283/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1284 * see section 4.1.4 of 3GPP TS 48.058 */
1285private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1286 var octetstring si5 := f_rnd_octstring(19);
1287 var RSL_IE_List addl_ies;
1288
1289 f_l1_tune(L1CTL);
1290 RSL.clear;
1291
1292 /* Step 1: Activate SYNC HO channel without MS power IE */
1293
1294 /* Activate channel on BTS side */
1295 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1296 /* don't perform immediate assignment here, as we're testing non-IA case */
1297 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001298 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001299
1300 /* Verify that no DL SACCH is being received */
1301 f_sacch_missing(?);
1302
1303 f_rsl_chan_deact();
1304 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1305
1306
1307 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1308
1309 /* Activate channel on BTS side */
1310 addl_ies := {
1311 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1312 };
1313 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1314 /* don't perform immediate assignment here, as we're testing non-IA case */
1315 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001316 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001317
1318 /* Verify that no DL SACCH is being received */
1319 f_sacch_missing(?);
1320
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323
1324
1325 /* Step 2b: Activate SYNC HO channel with TA IE */
1326
1327 /* Activate channel on BTS side */
1328 addl_ies := {
1329 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1330 };
1331 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1332 /* don't perform immediate assignment here, as we're testing non-IA case */
1333 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001334 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001335
1336 /* Verify that no DL SACCH is being received */
1337 f_sacch_missing(?);
1338
1339 f_rsl_chan_deact();
1340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1341
1342
1343 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1344
1345 /* Activate channel on BTS side */
1346 addl_ies := {
1347 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1348 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1349 };
1350 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1351 /* don't perform immediate assignment here, as we're testing non-IA case */
1352 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001353 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001354
1355 /* Verify that DL SACCH is being received */
1356 f_sacch_present(si5);
1357
1358 f_rsl_chan_deact();
1359 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1360}
1361testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1362 var ConnHdlr vc_conn;
1363 var ConnHdlrPars pars;
1364 f_init();
1365
1366 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1367 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1368 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1369 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1370 vc_conn.done;
1371 }
1372 /* TODO: do the above in parallel, rather than sequentially? */
1373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1374}
Harald Welte629cc6b2018-03-11 17:19:05 +01001375
1376
1377/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001378 * RACH Handling
1379 ***********************************************************************/
1380
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001382private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001383 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001384 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001385 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001386
Harald Welte8c24c2b2018-02-26 08:31:31 +01001387 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001388 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001389 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001390 var OCT1 ra := f_rnd_ra_emerg();
1391 if (emerg == true) {
1392 ra := f_rnd_ra_emerg();
1393 } else {
1394 ra := f_rnd_ra_cs();
1395 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001396 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1397 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001399 }
1400 fn_last := fn;
1401
1402 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001403 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001404 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001405 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406 T.stop;
1407 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001408 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001410 }
1411 [] RSL_CCHAN.receive { repeat; }
1412 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001413 test_failed := true;
1414 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001415 }
1416 }
1417 }
Maxba06feb2019-03-05 10:52:46 +01001418 if (test_failed) {
1419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001420 }
Maxba06feb2019-03-05 10:52:46 +01001421 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001423}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001424
Philipp Maier16ade782020-07-08 21:36:00 +02001425/* Normal variant */
1426testcase TC_rach_content() runs on test_CT {
1427 f_TC_rach_content(emerg := false);
1428}
1429
1430/* Emergency call variant */
1431testcase TC_rach_content_emerg() runs on test_CT {
1432 f_TC_rach_content(emerg := true);
1433}
1434
Harald Welte8c24c2b2018-02-26 08:31:31 +01001435/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1436testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001437 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001439 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 f_l1_tune(L1CTL);
1441
1442 var GsmFrameNumber fn_last := 0;
1443 for (var integer i := 0; i < 1000; i := i+1) {
1444 var OCT1 ra := f_rnd_ra_cs();
1445 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1446 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001448 }
1449 fn_last := fn;
1450 }
1451 var integer rsl_chrqd := 0;
1452 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001453 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001454 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001455 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001457 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 repeat;
1459 }
1460 [] RSL_CCHAN.receive { repeat; }
1461 [] T.timeout { }
1462 }
1463 if (rsl_chrqd == 1000) {
1464 setverdict(pass);
1465 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001469}
1470
Harald Welte3453ab42019-05-24 21:19:58 +02001471private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1472 var charstring bts_str := "bts " & int2str(bts_nr);
1473 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1474}
1475
1476/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1477private template integer tr_rach_slots_per_interval := (90 .. 130);
1478
1479/* Expect 0 RACH load on an idle BTS that has just started up */
1480testcase TC_rach_load_idle_thresh0() runs on test_CT {
1481 var ASP_RSL_Unitdata rx_ud;
1482
1483 f_init_vty_bsc();
1484 /* send load indications even at 0% load */
1485 f_vty_load_ind_thresh(0);
1486 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1487 f_sleep(2.0);
1488
1489 f_init();
1490
Harald Weltee37f9a52020-10-11 20:45:23 +02001491 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1492 alt {
1493 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1494 [] RSL_CCHAN.receive { repeat }
1495 }
1496
Harald Welte3453ab42019-05-24 21:19:58 +02001497 timer T := 5.0;
1498 T.start;
1499 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001500 [] 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 +02001501 setverdict(pass);
1502 repeat;
1503 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001504 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001505 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1506 repeat;
1507 }
1508 [] RSL_CCHAN.receive {
1509 repeat;
1510 }
1511 [] T.timeout { }
1512 }
1513
1514 f_vty_load_ind_thresh(10);
1515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1516}
1517
1518/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1519testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1520 var ASP_RSL_Unitdata rx_ud;
1521
1522 f_init_vty_bsc();
1523 f_init();
1524
1525 timer T := 5.0;
1526 T.start;
1527 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001528 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001529 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1530 repeat;
1531 }
1532 [] RSL_CCHAN.receive {
1533 repeat;
1534 }
1535 [] T.timeout {
1536 setverdict(pass);
1537 }
1538 }
1539
1540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1541}
1542
1543/* Expect 0 RACH load on an idle BTS that has just started up */
1544testcase TC_rach_load_count() runs on test_CT {
1545 var ASP_RSL_Unitdata rx_ud;
1546 var integer load_access_count := 0;
1547
1548 f_init_vty_bsc();
1549 /* send load indications even at 0% load */
1550 f_vty_load_ind_thresh(0);
1551 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1552 f_sleep(2.0);
1553 f_init();
1554
1555 f_init_l1ctl();
1556 f_sleep(1.0);
1557 f_l1_tune(L1CTL);
1558
Harald Welte52ae1682020-10-11 20:45:55 +02001559 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1560 alt {
1561 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1562 [] RSL_CCHAN.receive { repeat }
1563 }
1564
Harald Welte3453ab42019-05-24 21:19:58 +02001565 var GsmFrameNumber fn_last := 0;
1566 for (var integer i := 0; i < 1000; i := i+1) {
1567 var OCT1 ra := f_rnd_ra_cs();
1568 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1569 if (fn == fn_last) {
1570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1571 }
1572 fn_last := fn;
1573 }
1574
1575 timer T := 5.0;
1576 T.start;
1577 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001578 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001579 -> value rx_ud {
1580 var RSL_IE_Body ie;
1581 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1582 load_access_count := load_access_count + ie.rach_load.access_count;
1583 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1584 setverdict(fail, "Access count cannot be < Busy count");
1585 }
1586 repeat;
1587 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001588 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001589 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1590 repeat;
1591 }
1592 [] RSL_CCHAN.receive {
1593 repeat;
1594 }
1595 [] T.timeout { }
1596 }
1597 if (load_access_count == 1000) {
1598 setverdict(pass);
1599 } else {
1600 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1601 }
1602
1603 f_vty_load_ind_thresh(10);
1604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1605}
1606
Harald Welte54a2a2d2018-02-26 09:14:05 +01001607private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001608 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001609 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001610 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001611 f_sleep(0.5);
1612
1613 /* Transmit RACH request + wait for confirmation */
1614 var OCT1 ra := f_rnd_ra_cs();
1615 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1616
1617 /* Check for expected result */
1618 timer T := 1.5;
1619 T.start;
1620 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001621 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001622 setverdict(pass);
1623 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001626 }
1627 [] RSL_CCHAN.receive { repeat; }
1628 [not expect_pass] T.timeout {
1629 setverdict(pass);
1630 }
1631 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001633 }
1634 }
1635}
1636
1637/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1638testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001639 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001640 f_init_l1ctl();
1641 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642 f_sleep(1.0);
1643
1644 /* default max-ta is 63 (full range of GSM timing advance */
1645
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001646 /* We allow early arrival up to 2 symbols */
1647 f_rach_toffs(-1*256, true);
1648 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001649 f_rach_toffs(-10*256, false);
1650
1651 /* 0 / 32 / 63 bits is legal / permitted */
1652 f_rach_toffs(0, true);
1653 f_rach_toffs(32*256, true);
1654 f_rach_toffs(63*256, true);
1655
1656 /* more than 63 bits is not legal / permitted */
1657 f_rach_toffs(64*256, false);
1658 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001660}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001661
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001662private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001663 var GsmFrameNumber fn;
1664 var RSL_Message rm;
1665
1666 f_l1_tune(L1CTL);
1667 RSL.clear;
1668
1669 /* Generate a random Handover Reference */
1670 var integer ho_ref := oct2int(f_rnd_octstring(1));
1671
1672 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1673 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1674 RSL_IE_Body:{ handover_ref := ho_ref }));
1675
1676 /* Activate a channel on the BTS side (no encryption) */
1677 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1678 act_type := t_RSL_IE_ActType_HO_SYNC);
1679
1680 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1681 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001682 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001683
1684 /* Send handover Access Burst */
1685 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1686
1687 /* TODO: test mismatching Handover Reference, and missing IE */
1688
1689 /* Wait for handover detection */
1690 timer T := 3.0;
1691 T.start;
1692 alt {
1693 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1694 log("Handover RACH has been detected: ", rm);
1695 setverdict(pass);
1696 }
1697 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1699 log2str("RSL_CHAN_RQD was not expected: ", rm));
1700 }
1701 [] RSL.receive { repeat; }
1702 [] T.timeout {
1703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1704 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1705 }
1706 }
1707
1708 /* Release the channel */
1709 f_rsl_chan_deact();
1710 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1711}
1712
1713/* Test handover RACH detection */
1714testcase TC_ho_rach() runs on test_CT {
1715 var ConnHdlrPars pars;
1716 var ConnHdlr vc_conn;
1717
1718 f_init();
1719
1720 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1721 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1722 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1723 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1724 vc_conn.done;
1725 }
1726
1727 /* TODO: do the above in parallel, rather than sequentially? */
1728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1729}
1730
Harald Welte93640c62018-02-25 16:59:33 +01001731/***********************************************************************
1732 * Measurement Processing / Reporting
1733 ***********************************************************************/
1734
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001735private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001736 spare := '0'B,
1737 lpd := 0,
1738 sapi := sapi,
1739 c_r := c_r,
1740 ea := true
1741}
1742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001743private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001744 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001745 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001746 len := 0, /* overwritten */
1747 m := false,
1748 el := 1,
1749 payload := pl
1750}
1751
1752/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001753private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001754 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001755 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001756 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001757 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 +01001758 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001759 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001760
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001761 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1762 g_pars.l1_pars.ms_power_level, false,
1763 g_pars.l1_pars.ms_actual_ta);
1764
1765 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1766 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1767
1768 log("Sending Measurement Report: ", l1h, l2);
1769 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001770 repeat;
1771 }
1772}
1773
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001774private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001775 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001776 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001777 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1778 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001779 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1780 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001781 repeat;
1782 }
1783}
1784
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001785private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001786 uint6_t rxlev,
1787 uint3_t rxqual
1788}
1789
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001790private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001791 MeasElem full,
1792 MeasElem sub
1793}
1794
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001795private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001796 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001797 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001798 MeasElemFS meas_ul,
1799 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001800 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001801 uint5_t ms_power_level,
1802 uint8_t ms_actual_ta
1803}
1804
1805/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1806private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1807 return 63 + (toffs256s/256);
1808}
1809
Harald Welted5684392018-03-10 18:22:04 +01001810private function f_max(integer a, integer b) return integer {
1811 if (a > b) {
1812 return a;
1813 } else {
1814 return b;
1815 }
1816}
1817
1818private function f_min(integer a, integer b) return integer {
1819 if (a < b) {
1820 return a;
1821 } else {
1822 return b;
1823 }
1824}
1825
1826/* compute negative tolerance val-tolerance, ensure >= min */
1827private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1828 val := val - tolerance;
1829 return f_max(val, min);
1830}
1831
1832/* compute positive tolerance val+tolerance, ensure <= max */
1833private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1834 val := val + tolerance;
1835 return f_min(val, max);
1836}
1837
1838/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1839private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1840return template integer {
1841 var template integer ret;
1842 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1843 return ret;
1844}
1845
1846
Harald Welte70767382018-02-21 12:16:40 +01001847/* build a template for matching measurement results against */
1848private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1849 var ConnL1Pars l1p := g_pars.l1_pars;
1850 var template RSL_IE_UplinkMeas ul_meas := {
1851 len := 3,
1852 rfu := '0'B,
1853 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001854 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001855 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001856 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001857 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001858 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1859 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001860 supp_meas_info := omit
1861 };
Harald Welte685d5982018-02-27 20:42:05 +01001862 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001863 ul_meas.len := (3+8);
1864 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001865 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001866 toa256_min := ?,
1867 toa256_max := ?,
1868 toa256_std_dev := ?
1869 }
Harald Welte685d5982018-02-27 20:42:05 +01001870 }
Harald Welte70767382018-02-21 12:16:40 +01001871 var template RSL_IE_BS_Power bs_power := {
1872 reserved := 0,
1873 epc := false,
1874 fpc := false,
1875 power_level := l1p.bs_power_level
1876 };
1877 var template RSL_IE_L1Info l1_info := {
1878 ms_power_lvl := l1p.ms_power_level,
1879 fpc := false,
1880 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001881 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001882 };
1883 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001884 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001885 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1886 ?, t_toffs);
1887}
1888
Philipp Maierdd841d32019-12-17 14:44:54 +01001889/* build a template for matching measurement results that do not contain any
1890 * MS related measurement (l1_info, l3_info and ms timing offset). */
1891private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1892 var ConnL1Pars l1p := g_pars.l1_pars;
1893 var template RSL_IE_UplinkMeas ul_meas := {
1894 len := 3,
1895 rfu := '0'B,
1896 dtx_d := l1p.dtx_enabled,
1897 rxlev_f_u := ?,
1898 reserved1 := '00'B,
1899 rxlev_s_u := ?,
1900 reserved2 := '00'B,
1901 rxq_f_u := ?,
1902 rxq_s_u := ?,
1903 supp_meas_info := omit
1904 };
1905 if (l1p.toa256_enabled) {
1906 ul_meas.len := (3+8);
1907 ul_meas.supp_meas_info := {
1908 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1909 toa256_min := ?,
1910 toa256_max := ?,
1911 toa256_std_dev := ?
1912 }
1913 }
1914 var template RSL_IE_BS_Power bs_power := {
1915 reserved := 0,
1916 epc := false,
1917 fpc := false,
1918 power_level := l1p.bs_power_level
1919 };
1920
1921 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1922}
1923
Harald Welte70767382018-02-21 12:16:40 +01001924/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001925private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001926 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001927 var boolean chan_est := false;
1928
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001929 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001930
1931 /* Receive osmocom specific measurement reports. This is the normal
1932 * case. Here we verify that the measurement reports we sent are
1933 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001934 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1935 /* increment counter of next to-be-expected meas rep */
1936 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1937 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001938 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001939
1940 /* The following two cases may only happen in the beginning
1941 * of the channel establishment phase. Once we have received
1942 * the "our" measurement report the first time, the channel
1943 * is established and empty or hardcoded TRXCON reports must
1944 * not occur anymore. */
1945 chan_est := true;
1946
1947 repeat;
1948 }
1949
1950 /* When the BTS has established the channel, the MS might need slightly
1951 * more time to establish the channel and actually start sending. The
1952 * result is then a measurement report that just lacks the measurement
1953 * information of the MS. This is normal and we tolerate this behavior. */
1954 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1955 /* increment counter of next to-be-expected meas rep */
1956 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1957 /* Re-start the timer expecting the next MEAS RES */
1958 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001959 repeat;
1960 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001961
1962 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1963 * measurements if the TTCN3 side does not supply measurement input in
1964 * time. In those cases TRXCON will either use a cached measurement
1965 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1966 * report the templates above will not match. We tolerate this
1967 * behavior, but only once. */
1968 [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 +01001969 /* increment counter of next to-be-expected meas rep */
1970 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1971 if (g_first_meas_res) {
1972 g_first_meas_res := false;
1973 repeat;
1974 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001976 }
Harald Welte70767382018-02-21 12:16:40 +01001977 }
1978 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001980 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001981 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001983 }
1984}
1985
Harald Weltee613f962018-04-18 22:38:16 +02001986private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1987 select (rsl_alg_id) {
1988 case (RSL_ALG_ID_A5_0) { return 0; }
1989 case (RSL_ALG_ID_A5_1) { return 1; }
1990 case (RSL_ALG_ID_A5_2) { return 2; }
1991 case (RSL_ALG_ID_A5_3) { return 3; }
1992 case (RSL_ALG_ID_A5_4) { return 4; }
1993 case (RSL_ALG_ID_A5_5) { return 5; }
1994 case (RSL_ALG_ID_A5_6) { return 6; }
1995 case (RSL_ALG_ID_A5_7) { return 7; }
1996 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1998 /* Make compiler happy by calling mtc.stop here. It is already
1999 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002000 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002001 }
2002 }
2003}
2004
2005private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2006 select (rsl_alg_id) {
2007 case (RSL_ALG_ID_A5_1) { return '000'B; }
2008 case (RSL_ALG_ID_A5_2) { return '001'B; }
2009 case (RSL_ALG_ID_A5_3) { return '010'B; }
2010 case (RSL_ALG_ID_A5_4) { return '011'B; }
2011 case (RSL_ALG_ID_A5_5) { return '100'B; }
2012 case (RSL_ALG_ID_A5_6) { return '101'B; }
2013 case (RSL_ALG_ID_A5_7) { return '110'B; }
2014 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2016 /* Make compiler happy by calling mtc.stop here. It is already
2017 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002018 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002019 }
2020 }
2021}
2022
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002023/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2024private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2025 var GsmFrameNumber fn;
2026 timer T := 8.0;
2027
2028 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2029 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2030
2031 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2032 /* Send the actual RACH */
2033 fn := f_L1CTL_RACH(L1CTL, ra);
2034
2035 T.start;
2036 alt {
2037 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2038 [] T.timeout {
2039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2040 }
2041 }
2042 T.stop
2043 return fn;
2044}
Harald Weltee613f962018-04-18 22:38:16 +02002045
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002046/* Tune to a dedicated channel: L1CTL only */
2047private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002048 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002049 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2050 7 /* TODO: mp_tsc */,
2051 mp_trx0_arfcn));
2052 } else {
2053 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2054 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002055 pars.fhp.maio_hsn.hsn,
2056 pars.fhp.maio_hsn.maio,
2057 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002058 }
2059}
2060
Harald Welte70767382018-02-21 12:16:40 +01002061/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002062private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002063 var GsmFrameNumber fn;
2064 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002065 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002066 var integer ra := 23;
2067
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002068 /* Send RACH request and wait for ChanReq */
2069 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002070
2071 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002072 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002073
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002074 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002075 if (g_pars.fhp.enabled) {
2076 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002077 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002078 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002079 }
2080
Harald Welte70767382018-02-21 12:16:40 +01002081 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002082 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 +01002083 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2084
2085 /* receive IMM.ASS on MS side */
2086 var ImmediateAssignment ia_um;
2087 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002088
2089 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2090 if (ch_desc.h != ia_um.chan_desc.h) {
2091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2092 }
2093
Harald Welte70767382018-02-21 12:16:40 +01002094 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002095 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002096 /* enable encryption, if requested */
2097 if (encr_enable) {
2098 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2099 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2100 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002101
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002102 /* Send TCH Mode Request to the L1 if needed */
2103 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2104 var L1ctlTchMode tch_mode;
2105
2106 select (g_pars.chan_mode.coding_alg_rate) {
2107 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2108 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2109 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2110 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2111 case else {
2112 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2113 " is not supported by the L1, falling back to signalling");
2114 tch_mode := L1CTL_CHAN_MODE_SIGN;
2115 }
2116 }
2117
2118 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2119 }
2120
Harald Weltefa45e9e2018-03-10 18:59:03 +01002121 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002122}
2123
2124/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002125private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002126 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002127 RSL.clear;
2128
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002129 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002130 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002131 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002132 }
Harald Welte70767382018-02-21 12:16:40 +01002133
2134 f_est_dchan();
2135
2136 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2137 * RSL measurement reports on Abis side */
2138 timer T := 8.0;
2139 T.start;
2140 alt {
2141 [] as_l1_sacch();
2142 [] as_meas_res();
2143 [] as_l1_dcch();
2144 [] L1CTL.receive { repeat; }
2145 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002146 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002147 * of any earlier errors, so if we reach this timeout, we're good */
2148 setverdict(pass);
2149 }
2150 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002152 }
2153 }
2154 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002156}
Harald Welte0472ab42018-03-12 15:02:26 +01002157
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002158/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2159private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002160 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002161 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2162 timer Tup := 10.0;
2163 Tup.start;
2164 alt {
2165 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2166 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2167 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002168
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002169 if (rx_lvl != max_rx_lvl) {
2170 repeat;
2171 }
2172 Tup.stop;
2173 }
2174 [] L1CTL.receive { repeat; }
2175 [] Tup.timeout {
2176 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2177 log2str("Didn't reach full power ", max_rx_lvl));
2178 }
2179 }
2180 return max_rx_lvl;
2181}
2182
2183/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2184private function f_verify_ramp_up() runs on ConnHdlr {
2185 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002186 var integer initial_rx_lvl := -1;
2187 var integer last_rx_lvl := -1;
2188 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2189
2190 timer T := 2.0;
2191 alt {
2192 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2193 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2194 log("Received rx_level=", rx_lvl);
2195 if (initial_rx_lvl == -1) {
2196 initial_rx_lvl := rx_lvl;
2197 last_rx_lvl := rx_lvl;
2198
2199 /* Expect a somehow low value during first received messages */
2200 if (initial_rx_lvl >= max_rx_lvl / 2) {
2201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2202 log2str("Detected high initial tx power during ramp up: ",
2203 initial_rx_lvl , ", full power is", max_rx_lvl));
2204 }
2205 }
2206
2207 /* received Rx level bigger than maximum allowed power by CN */
2208 if (rx_lvl > max_rx_lvl) {
2209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2210 log2str("Detected Tx power higher than full power: ",
2211 rx_lvl , " > ", max_rx_lvl));
2212 }
2213
2214 /* Make sure it never decreases, since we are rumping up */
2215 if (last_rx_lvl > rx_lvl) {
2216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2217 log2str("Detected Tx power decrease during ramp up: ",
2218 last_rx_lvl , " -> ", rx_lvl));
2219 }
2220
2221 if (rx_lvl == max_rx_lvl and not T.running) {
2222 /* We reached the maximum power, start timer and receive
2223 /* a few more to make sure we don't surpass it */
2224 log("Reached full power, wating a bit more until success");
2225 T.start;
2226 }
2227
2228 last_rx_lvl := rx_lvl;
2229 repeat;
2230 }
2231 [] L1CTL.receive { repeat; }
2232 [] T.timeout { }
2233 }
2234
2235 /* We didn't increase tx power during ramp up */
2236 if (initial_rx_lvl < last_rx_lvl) {
2237 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2238 } else {
2239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2240 log2str("No Tx power increase during whole ramp up: ",
2241 initial_rx_lvl , " -> ", last_rx_lvl));
2242 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002243}
2244
2245/* verify BTS ramps power down to rx_level 0 */
2246private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2247 var L1ctlDlMessage l1_dl;
2248 var integer last_rx_lvl := max_rx_lvl;
2249
2250 timer Tdown := 5.0;
2251 Tdown.start;
2252 alt {
2253 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2254 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2255 log("Received rx_level=", rx_lvl);
2256
2257 /* received Rx level bigger than maximum allowed power by CN */
2258 if (rx_lvl > max_rx_lvl) {
2259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2260 log2str("Detected Tx power higher than full power: ",
2261 rx_lvl , " > ", max_rx_lvl));
2262 }
2263
2264 /* Make sure it never increases, since we are rumping down */
2265 if (last_rx_lvl < rx_lvl) {
2266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2267 log2str("Detected Tx power increase during ramp up: ",
2268 last_rx_lvl , " -> ", rx_lvl));
2269 }
2270
2271 last_rx_lvl := rx_lvl;
2272 if (last_rx_lvl != 0) {
2273 repeat;
2274 }
2275 /* we reached power level 0, we are done */
2276 Tdown.stop;
2277 }
2278 [] L1CTL.receive { repeat; }
2279 [] Tdown.timeout { }
2280 }
2281
2282 /* We didn't increase tx power during ramp down */
2283 if (max_rx_lvl > last_rx_lvl) {
2284 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2285 } else {
2286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2287 log2str("No Tx power decrease during whole ramp down: ",
2288 max_rx_lvl , " -> ", last_rx_lvl));
2289 }
2290}
2291
2292/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002293private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002294 f_l1_tune(L1CTL);
2295 RSL.clear;
2296
2297 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002298
2299 setverdict(pass);
2300}
2301testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2302 var ConnHdlr vc_conn;
2303 var ConnHdlrPars pars;
2304 f_init();
2305 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2306 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2307 pcu_comp := false, trxc_comp := true);
2308 vc_conn.done;
2309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2310}
2311
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002312/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002313private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002314 f_connhdlr_init_vty_bsc();
2315
2316 f_l1_tune(L1CTL);
2317 RSL.clear;
2318
2319 /* Wait until BTS is started and at full power */
2320 var integer max_rx_lvl := f_wait_ramp_up();
2321 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2322
2323 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2324 f_verify_ramp_down(max_rx_lvl);
2325
2326 setverdict(pass);
2327}
2328testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2329 var ConnHdlr vc_conn;
2330 var ConnHdlrPars pars;
2331 f_init();
2332 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2333 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2334 pcu_comp := false, trxc_comp := true);
2335 vc_conn.done;
2336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2337}
2338
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002339/* Verify Tx power:
2340 * + ramping down during ADM state UNLOCKED->LOCKED
2341 * + ramping up during ADM state LOCKED->UNLOCKED
2342 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002343private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002344 var L1ctlDlMessage l1_dl;
2345 var integer last_rx_lvl;
2346
2347 f_connhdlr_init_vty_bsc();
2348
2349 f_l1_tune(L1CTL);
2350 RSL.clear;
2351
2352 /* Wait until BTS is started and at full power */
2353 var integer max_rx_lvl := f_wait_ramp_up();
2354 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2355
2356 log("ADM STATE UNLOCKED->LOCKED");
2357 f_vty_enter_cfg_trx(BSCVTY);
2358 f_vty_transceive(BSCVTY, "rf_locked 1");
2359 last_rx_lvl := max_rx_lvl;
2360 f_verify_ramp_down(max_rx_lvl);
2361
2362 /* Let some time after we received 0dBm, then check we don't receive BCCH
2363 * anymore because scheduler has stopped after ramping down */
2364 f_sleep(2.0);
2365 L1CTL.clear;
2366 timer Tlocked := 2.0;
2367 Tlocked.start;
2368 alt {
2369 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2371 log2str("Received data_ind during rf_locked: ", l1_dl));
2372 }
2373 [] L1CTL.receive { repeat; }
2374 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2375 }
2376
2377 log("ADM STATE LOCKED->UNLOCKED");
2378 f_vty_transceive(BSCVTY, "rf_locked 0");
2379 f_verify_ramp_up();
2380 setverdict(pass);
2381}
2382testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2383 var ConnHdlr vc_conn;
2384 var ConnHdlrPars pars;
2385 f_init();
2386 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2387 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2388 pcu_comp := false, trxc_comp := true);
2389 vc_conn.done;
2390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2391}
2392
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002393private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002394 timer T := 8.0;
2395 T.start;
2396 var RSL_Message rsl;
2397 alt {
2398 [] as_l1_sacch();
2399 [] L1CTL.receive { repeat; }
2400 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2401 if (rsl.ies[3].body.bs_power.power_level == level) {
2402 setverdict(pass)
2403 } else {
2404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2405 }
2406 }
2407 [] T.timeout {
2408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2409 }
2410 }
2411}
2412
2413/* see if the rsl meas res contains our expeced bs power level
2414bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002415private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002416 f_l1_tune(L1CTL);
2417 RSL.clear;
2418
2419 if (mp_bts_trxc_port != -1) {
2420 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2421 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2422 }
2423
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002424 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002425 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2426 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2427
2428 f_est_dchan(more_ies :={valueof(pwr)});
2429
2430 f_check_meas_bs_power_level(pwr_var);
2431
2432 f_rsl_chan_deact();
2433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2434}
2435
2436/* see if the rsl meas res contains our expeced bs power level
2437bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002438private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002439 f_l1_tune(L1CTL);
2440 RSL.clear;
2441
2442 if (mp_bts_trxc_port != -1) {
2443 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2444 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2445 }
2446
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002447 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002448 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2449
2450 f_est_dchan();
2451
2452 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2453
2454 f_check_meas_bs_power_level(pwr_var);
2455
2456 f_rsl_chan_deact();
2457 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2458}
2459
2460testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2461 var ConnHdlr vc_conn;
2462 var ConnHdlrPars pars;
2463 f_init();
2464 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2465 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2466 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2467 pcu_comp := false, trxc_comp := true);
2468 vc_conn.done;
2469 }
2470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2471}
2472
2473testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2474 var ConnHdlr vc_conn;
2475 var ConnHdlrPars pars;
2476 f_init();
2477 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2478 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2479 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2480 pcu_comp := false, trxc_comp := true);
2481 vc_conn.done;
2482 }
2483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2484}
2485
Eric Wild61edb7e2019-06-03 12:38:31 +02002486/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2487second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2488These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002489private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002490 var uint5_t pwr_var := 7;
2491 var L1ctlDlMessage l1_dl;
2492
2493 f_trxc_fake_rssi(rxlev2dbm(10));
2494 f_l1_tune(L1CTL);
2495 RSL.clear;
2496
2497 var RSL_IE_List addl_ies;
2498 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2499
2500 addl_ies := {
2501 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2502 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2503 };
2504
2505 /* establish with power parameters */
2506 f_est_dchan(more_ies := addl_ies);
2507
2508 /* set a high value to ensure L1 power control level increases */
2509 f_trxc_fake_rssi(rxlev2dbm(20));
2510
2511 timer T2 := 6.0;
2512 T2.start;
2513 alt {
2514 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002515 /* Update sent MS power to follow what BTS requests */
2516 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2517 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002518 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002519 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002520 T2.stop;
2521 }
2522 [] L1CTL.receive { repeat; }
2523 [] T2.timeout {
2524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2525 "Power Level in L1 header has not increased sufficiently");
2526 }
2527 }
2528
2529 /* set a low value to ensure L1 power control level decreases */
2530 f_trxc_fake_rssi(rxlev2dbm(0));
2531
2532 timer T4 := 6.0;
2533 T4.start;
2534 alt {
2535 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002536 /* Update sent MS power to follow what BTS requests */
2537 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2538 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002539 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002540 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002541 T4.stop;
2542 setverdict(pass, "Power level in L1 decreased/increased as expected");
2543 }
2544 [] L1CTL.receive { repeat; }
2545 [] T4.timeout {
2546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2547 "Power Level in L1 header has not decreased sufficiently");
2548 }
2549 }
2550
2551 f_rsl_chan_deact();
2552 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2553
2554}
2555
2556/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002557private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002558 var uint5_t pwr_var := 7;
2559 var L1ctlDlMessage l1_dl;
2560
2561 /* set a low value to ensure power increases */
2562 f_trxc_fake_rssi(rxlev2dbm(10));
2563 f_l1_tune(L1CTL);
2564 RSL.clear;
2565
2566 var RSL_IE_List addl_ies;
2567 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2568
2569 addl_ies := {
2570 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2571 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2572 };
2573
2574 /* establish with power parameters */
2575 f_est_dchan(more_ies := addl_ies);
2576
2577 timer T1 := 10.0;
2578 T1.start;
2579 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002580 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2581 /* Update sent MS power to follow what BTS requests */
2582 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2583 repeat;
2584 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002585 [] L1CTL.receive { repeat; }
2586 [] T1.timeout {
2587 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2588 setverdict(fail, "Power level in L1 header should not have changed");
2589 }
2590 }
2591 }
2592
2593 f_rsl_chan_deact();
2594 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2595
2596}
2597
2598/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002599private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002600 var L1ctlDlMessage l1_dl;
2601 var uint5_t pwr_var := 15;
2602 var uint5_t pwr_max_var := f_get_max_power_from_band();
2603
2604 /* set a low value to ensure power increases */
2605 f_trxc_fake_rssi(rxlev2dbm(10));
2606 f_l1_tune(L1CTL);
2607 RSL.clear;
2608
2609 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2610 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2611
2612 /* establish with fixed power level */
2613 f_est_dchan(more_ies :={valueof(pwr)});
2614
2615 /* check our initial power level */
2616 f_wait_for_l1_power_level(pwr_var);
2617
2618 /* update power param to enable power loop
2619 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2620 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2621
2622 /* wait, then check that our power level was reduced */
2623 timer T1 := 10.0;
2624 T1.start;
2625 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002626 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2627 /* Update sent MS power to follow what BTS requests */
2628 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2629 repeat;
2630 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002631 [] L1CTL.receive { repeat; }
2632 [] T1.timeout {
2633 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2634 if( f_power_level_is_highest_dbm(rcv) ){
2635 setverdict(pass, "Power level in L1 header reduced as expected");
2636 } else {
2637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2638 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2639 }
2640 }
2641 }
2642
2643 f_rsl_chan_deact();
2644 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2645
2646}
2647
2648/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002649private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002650 var L1ctlDlMessage l1_dl;
2651
2652 /* set a high value to ensure power decreases */
2653 f_trxc_fake_rssi(rxlev2dbm(50));
2654 f_l1_tune(L1CTL);
2655 RSL.clear;
2656
2657 var uint5_t pwr_var := 5;
2658 var uint5_t pwr_target_val := 15;
2659
2660 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2661 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2662
2663 /* establish with fixed power level */
2664 f_est_dchan(more_ies :={valueof(pwr)});
2665
2666 /* check our initial power level */
2667 f_wait_for_l1_power_level(pwr_var);
2668
2669 /* update power param to enable power loop
2670 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002671 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002672
2673 /* wait, then check that our power level was increased */
2674 timer T1 := 10.0;
2675 T1.start;
2676 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002677 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2678 /* Update sent MS power to follow what BTS requests */
2679 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2680 repeat;
2681 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002682 [] L1CTL.receive { repeat; }
2683 [] T1.timeout {
2684 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2685 setverdict(pass, "Power level in L1 header increased to lowest power value");
2686 } else {
2687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2688 "Power level in L1 header NOT increased to lowest power value");
2689 }
2690 }
2691 }
2692
2693 f_rsl_chan_deact();
2694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2695
2696}
2697
Eric Wild095024b2019-06-17 15:08:57 +02002698/* see if we change the power level without receiving power parameters, which should not happen
2699rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002700private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002701 var L1ctlDlMessage l1_dl;
2702
2703 /* set a high value to ensure power decreases */
2704 f_trxc_fake_rssi(rxlev2dbm(50));
2705 f_l1_tune(L1CTL);
2706 RSL.clear;
2707
2708 var uint5_t pwr_var := 5;
2709
2710 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2711 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2712
2713 /* establish with fixed power level */
2714 f_est_dchan(more_ies :={valueof(pwr)});
2715
2716 /* check our initial power level */
2717 f_wait_for_l1_power_level(pwr_var);
2718
2719 /* wait, then check that our power level did not change */
2720 timer T1 := 10.0;
2721 T1.start;
2722 alt {
2723 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2724 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2726 "BS power control should not be active unless we receive a power parameters IE!");
2727 }
2728 repeat;
2729 }
2730 [] L1CTL.receive { repeat; }
2731 [] T1.timeout { setverdict(pass); }
2732 }
2733
2734 f_rsl_chan_deact();
2735 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2736
2737}
2738
Eric Wild095024b2019-06-17 15:08:57 +02002739/* see if we change the power level without receiving power parameters, which should not happen
2740ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002741private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002742 var L1ctlDlMessage l1_dl;
2743
2744 /* set a high value to ensure power decreases */
2745 f_trxc_fake_rssi(rxlev2dbm(50));
2746 f_l1_tune(L1CTL);
2747 RSL.clear;
2748
2749 var uint5_t pwr_var := 5;
2750
2751 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2752 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2753
2754 /* establish with fixed power level */
2755 f_est_dchan(more_ies :={valueof(pwr)});
2756
2757 /* check our initial power level */
2758 f_wait_for_l1_power_level(pwr_var);
2759
2760 /* pwr control without power params IE, should NOT activate MS power control*/
2761 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2762
2763 /* wait, then check that our power level did not change */
2764 timer T1 := 10.0;
2765 T1.start;
2766 alt {
2767 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2768 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2770 "BS power control should not be active unless we receive a power parameters IE!");
2771 }
2772 repeat;
2773 }
2774 [] L1CTL.receive { repeat; }
2775 [] T1.timeout { setverdict(pass); }
2776 }
2777
2778 f_rsl_chan_deact();
2779 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2780
2781}
2782
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002783private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002784 var L1ctlDlMessage l1_dl;
2785 timer T0 := 10.0;
2786 T0.start;
2787 alt {
2788 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2789 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2791 "Power level in L1 header != signaled (RSL) power level.");
2792 }
2793 }
2794 [] L1CTL.receive { repeat; }
2795 [] T0.timeout {
2796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2797 "Timeout waiting for initial power level");
2798 }
2799 }
2800 T0.stop;
2801}
2802
2803private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2804 var IntegerRecord min_dbm_level;
2805 var IntegerRecord max_dbm_level;
2806 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2807
2808 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2809 if (min_dbm_level[i] == level) {
2810 return true;
2811 }
2812 }
2813 return false;
2814}
2815
2816private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2817 var IntegerRecord min_dbm_level;
2818 var IntegerRecord max_dbm_level;
2819 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2820
2821 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2822 if (max_dbm_level[i] == level) {
2823 return true;
2824 }
2825 }
2826 return false;
2827}
2828
2829private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2830 var IntegerRecord min_dbm_level;
2831 var IntegerRecord max_dbm_level;
2832 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2833 return max_dbm_level[0];
2834}
2835
2836type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002837private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002838private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2839 // 45.005 4.1.1
2840 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2841 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2842 2, 1, 0};
2843 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2844 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2845 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2846 var IntegerRecord rv;
2847
2848 select(band){
2849 case (BtsBand_allGSM){
2850 rv := gsm_power;
2851 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2852 max_dbm_level := {2, 1, 0};
2853 }
2854 case("DCS1800"){
2855 rv := dcs_power;
2856 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2857 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2858 }
2859 case("PCS1900"){
2860 rv := pcs_power;
2861 min_dbm_level := {15};
2862 max_dbm_level := {30};
2863 }
Harald Welte194b6912020-10-11 21:01:55 +02002864 case else {
2865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2866 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002867 }
2868
2869 return rv;
2870}
2871
2872private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002873 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 +02002874}
2875
2876testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2877 var ConnHdlr vc_conn;
2878 var ConnHdlrPars pars;
2879 f_init();
2880 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2881 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2882 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2883 pars.bts0_band := f_vty_get_bts0_band();
2884 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2885 vc_conn.done;
2886 }
2887 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2889}
2890
2891testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2892 var ConnHdlr vc_conn;
2893 var ConnHdlrPars pars;
2894 f_init();
2895 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2896 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2897 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2898 pars.bts0_band := f_vty_get_bts0_band();
2899 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2900 vc_conn.done;
2901 }
2902 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2904}
2905
2906testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2907 var ConnHdlr vc_conn;
2908 var ConnHdlrPars pars;
2909 f_init();
2910 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2911 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2912 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2913 pars.bts0_band := f_vty_get_bts0_band();
2914 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2915 vc_conn.done;
2916 }
2917 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2919}
2920
2921testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2922 var ConnHdlr vc_conn;
2923 var ConnHdlrPars pars;
2924 f_init();
2925 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2926 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2927 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2928 pars.bts0_band := f_vty_get_bts0_band();
2929 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2930 vc_conn.done;
2931 }
2932 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2934}
2935
Eric Wild280ccb82019-06-17 11:11:52 +02002936testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2937 var ConnHdlr vc_conn;
2938 var ConnHdlrPars pars;
2939 f_init();
2940 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2941 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2942 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2943 pars.bts0_band := f_vty_get_bts0_band();
2944 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2945 vc_conn.done;
2946 }
2947 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2949}
2950
Eric Wild095024b2019-06-17 15:08:57 +02002951testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2952 var ConnHdlr vc_conn;
2953 var ConnHdlrPars pars;
2954 f_init();
2955 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2956 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2957 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2958 pars.bts0_band := f_vty_get_bts0_band();
2959 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2960 vc_conn.done;
2961 }
2962 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2964}
2965
Harald Welte70767382018-02-21 12:16:40 +01002966testcase TC_meas_res_sign_tchf() runs on test_CT {
2967 var ConnHdlr vc_conn;
2968 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002969 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002970 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2971 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002972 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2973 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002974 vc_conn.done;
2975 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002977}
2978testcase TC_meas_res_sign_tchh() 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 ss := 0; ss <= 1; ss := ss+1) {
2983 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002984 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_sdcch4() 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 <= 3; ss := ss+1) {
2995 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, 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_sdcch8() 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 <= 7; ss := ss+1) {
3007 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 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}
Harald Welte685d5982018-02-27 20:42:05 +01003014testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3015 var ConnHdlr vc_conn;
3016 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003017 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003018 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3019 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3020 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3021 pars.l1_pars.toa256_enabled := true;
3022 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3023 vc_conn.done;
3024 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003026}
3027
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003028/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3029 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003030private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003031 var L1ctlDlMessage l1_dl;
3032 var RSL_IE_MS_Power ms_power;
3033 var RSL_Message rsl;
3034 var uint5_t power_level := 0;
3035
3036 f_l1_tune(L1CTL);
3037 RSL.clear;
3038
3039 f_est_dchan();
3040
3041 ms_power.reserved := 0;
3042 ms_power.fpc_epc := false;
3043
3044 /* Send the first power control command. This will disable any BTS/TRX
3045 * internal power control and switch the MS (which is not in scope of
3046 * this test) to a constant power level. We start with a power level
3047 * of 0 */
3048 ms_power.power_level := power_level;
3049 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3050 RSL.send(rsl);
3051
3052 alt {
3053
3054 /* Pick all SACCH blocks for checking */
3055 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3056
3057 /* The first byte of the L1 header contains the power level.
3058 * The reserved bits and the fpc bit is set to 0, so we may
3059 * compare directly. */
3060 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3061 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3062 }
3063
3064 /* Signal a new power level via RSL for the next turn. */
3065 if (power_level < 31) {
3066 power_level := power_level + 1;
3067 ms_power.power_level := power_level;
3068 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3069 RSL.send(rsl);
3070 repeat;
3071 }
3072
3073 }
3074
3075 /* Ignore all other blocks */
3076 [] L1CTL.receive { repeat; }
3077
3078 }
3079
3080 f_rsl_chan_deact();
3081 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3082
3083 setverdict(pass);
3084}
3085
3086testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3087 var ConnHdlr vc_conn;
3088 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003089 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003090
3091 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3092 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3093 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3094 vc_conn.done;
3095 }
3096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3097}
Harald Welte70767382018-02-21 12:16:40 +01003098
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003099/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003100TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003101private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003102 var L1ctlDlMessage l1_dl;
3103 var uint5_t ta_to_test := 16;
3104
3105
3106 f_l1_tune(L1CTL);
3107 RSL.clear;
3108
3109 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003110 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003111
3112 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3113
3114
3115 alt {
3116
3117 /* Pick all SACCH blocks for checking */
3118 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3119
3120 /* The second byte of the L1 header contains the TA. */
3121 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3122 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3123 }
3124
3125 }
3126
3127 /* Ignore all other blocks */
3128 [] L1CTL.receive { repeat; }
3129
3130 }
3131
3132 f_rsl_chan_deact();
3133 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3134
3135 setverdict(pass);
3136}
3137
3138testcase TC_rsl_chan_initial_ta() runs on test_CT {
3139 var ConnHdlr vc_conn;
3140 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003141 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003142 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003143 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3144 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003145 vc_conn.done;
3146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3147}
3148
Eric Wilde57e1a62019-05-28 13:30:55 +02003149/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003150private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003151 var L1ctlDlMessage l1_dl;
3152 var uint5_t ms_power_level := 7;
3153
3154 var RSL_IE_MS_Power ms_power;
3155 ms_power.reserved := 0;
3156 ms_power.fpc_epc := false;
3157 ms_power.power_level := ms_power_level;
3158
3159 f_l1_tune(L1CTL);
3160 RSL.clear;
3161
3162 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3163
3164 timer T := 1.0;
3165 T.start;
3166 alt {
3167 /* Pick all SACCH blocks for checking */
3168 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3169 /* The first byte of the L1 header contains the power level.. */
3170 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3171 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3172 }
3173 }
3174 /* Ignore all other blocks */
3175 [] L1CTL.receive { repeat; }
3176 [] T.timeout {
3177 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3178 }
3179 }
3180
3181 f_rsl_chan_deact();
3182 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3183 setverdict(pass);
3184}
3185
3186testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3187 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3188 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3189}
3190
Harald Welte0472ab42018-03-12 15:02:26 +01003191/* 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 +01003192private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003193 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003194 RSL.clear;
3195
3196 f_est_dchan();
3197 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003198 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003199
3200 timer T := 40.0;
3201 T.start;
3202 alt {
3203 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3204 setverdict(pass)
3205 }
3206 [] RSL.receive { repeat };
3207 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003209 }
3210 }
3211 f_rsl_chan_deact();
3212}
3213testcase TC_conn_fail_crit() runs on test_CT {
3214 var ConnHdlr vc_conn;
3215 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003216 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003217 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3218 pars.t_guard := 60.0;
3219 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3220 vc_conn.done;
3221}
3222
Harald Welte93640c62018-02-25 16:59:33 +01003223/***********************************************************************
3224 * Paging
3225 ***********************************************************************/
3226
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003227private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003228 if (tmsi == 'FFFFFFFF'O) {
3229 return true;
3230 } else {
3231 return false;
3232 }
3233}
Harald Welte70767382018-02-21 12:16:40 +01003234
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003235private type record allowedFn { integer frame_nr }
3236private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3237private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3238private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3239private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3240private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3241private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3242private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3243private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3244private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003245{
3246 var integer frame_nr_51;
3247 frame_nr_51 := frame_nr mod 51
3248
3249 var allowedFn fn_check;
3250 fn_check.frame_nr := frame_nr_51;
3251
3252 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003254 return;
3255 }
3256
3257 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3258 return;
3259 }
3260 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3261 return;
3262 }
3263 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3264 return;
3265 }
3266 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3267 return;
3268 }
3269 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3270 return;
3271 }
3272 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3273 return;
3274 }
3275 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3276 return;
3277 }
3278 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3279 return;
3280 }
3281
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003283 return;
3284}
3285
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003286private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3287 inout integer num_paging_rcv_ids,
3288 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003289runs on test_CT {
3290 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003291 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003292 repeat;
3293 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003294 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003295 var octetstring without_plen :=
3296 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3297 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003298
3299 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3300
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003301 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3302 /* Ignore empty RR Paging Request (PCH filling) messages.
3303 * TODO: does it make sense to count them? */
3304 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003305 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3306 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003307 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003308 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3309 }
3310 } else if (match(rr, tr_PAGING_REQ2)) {
3311 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3312 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3313 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3314 }
3315 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3316 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3317 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003318 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003319 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3320 }
3321 } else if (match(rr, tr_PAGING_REQ3)) {
3322 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3323 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3324 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3325 }
3326 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3327 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3328 }
3329 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3330 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3331 }
3332 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3333 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3334 }
3335 }
3336 repeat;
3337 }
3338}
3339
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003340private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003341 boolean combined_ccch,
3342 integer bs_ag_blks_res,
3343 float load_factor,
3344 boolean exp_load_ind,
3345 boolean exp_overload,
3346 boolean use_tmsi
3347}
3348
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003349private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003350 integer num_paging_sent,
3351 integer num_paging_rcv_msgs,
3352 integer num_paging_rcv_ids,
3353 integer num_overload
3354}
3355
Harald Welte68e495b2018-02-25 00:05:57 +01003356/* Helper function for paging related testing */
3357private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003358 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003359 f_init_l1ctl();
3360 f_l1_tune(L1CTL);
3361
3362 var PagingTestState st := {
3363 num_paging_sent := 0,
3364 num_paging_rcv_msgs := 0,
3365 num_paging_rcv_ids := 0,
3366 num_overload := 0
3367 };
3368
3369 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3370 var float max_pch_imsi_per_sec;
3371 if (cfg.use_tmsi) {
3372 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3373 } else {
3374 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3375 }
3376 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3377 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003378 var float time_total := 20.0;
3379 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3380 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003381
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003382 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3383 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003384
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003385 timer T_itv := 0.0;
3386 T_itv.start;
3387 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003388 alt {
3389 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003390 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003391 st.num_overload := st.num_overload + 1;
3392 repeat;
3393 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003394 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003396 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003397 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003398 log("Rx LOAD_IND");
3399 /* FIXME: analyze/verify interval + contents */
3400 repeat;
3401 }
3402 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003403 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003404 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003405 [] T_itv.timeout {
3406 /* Send paging cmds based on elapsed time */
3407 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3408 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003409 var MobileIdentityV mi;
3410
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003411 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003412 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003413 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003414 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003415 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003416 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003417
3418 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003419 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 +02003420
3421 st.num_paging_sent := st.num_paging_sent + 1;
3422 }
3423 if (st.num_paging_sent < pkt_total) {
3424 /* Wait for interval to next PAGING COMMAND */
3425 var float time_now := T_total.read;
3426 var float next_sched := int2float(st.num_paging_sent)*interval;
3427 if (next_sched > time_now) {
3428 T_itv.start(next_sched - time_now);
3429 } else {
3430 T_itv.start(0.0);
3431 }
3432 } else {
3433 /* We are done, no need to keep counting */
3434 T_total.stop;
3435 }
3436 }
3437 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003438 }
3439 }
3440
3441 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3442 timer T_wait := 18.0;
3443 T_wait.start;
3444 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003445 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003446 [] L1CTL.receive { repeat; }
3447 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003448 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3449 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003450 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003452 }
Harald Welte68e495b2018-02-25 00:05:57 +01003453 }
3454
3455 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3456 " rcvd_ids=", st.num_paging_rcv_ids);
3457 return st;
3458}
3459
3460/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3461 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3462 * - that CCCH LOAD IND (PCH) are being generated
3463 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3464testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003465 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003466 var PagingTestCfg cfg := {
3467 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003468 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003469 load_factor := 0.8,
3470 exp_load_ind := true,
3471 exp_overload := false,
3472 use_tmsi := false
3473 };
3474 var PagingTestState st := f_TC_paging(cfg);
3475 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3477 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003478 } else {
3479 setverdict(pass);
3480 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003482}
3483
3484/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3485 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3486 * - that CCCH LOAD IND (PCH) are being generated
3487 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3488testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003489 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003490 var PagingTestCfg cfg := {
3491 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003492 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003493 load_factor := 0.8,
3494 exp_load_ind := true,
3495 exp_overload := false,
3496 use_tmsi := true
3497 };
3498 var PagingTestState st := f_TC_paging(cfg);
3499 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3501 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003502 } else {
3503 setverdict(pass);
3504 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003506}
3507
3508/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3509 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3510 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3511 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3512testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003513 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003514 var PagingTestCfg cfg := {
3515 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003516 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003517 load_factor := 2.0,
3518 exp_load_ind := true,
3519 exp_overload := true,
3520 use_tmsi := false
3521 };
3522 var PagingTestState st := f_TC_paging(cfg);
3523 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3524 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003525 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003526 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003527 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 +01003528 } else {
3529 setverdict(pass);
3530 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003532}
3533
3534/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3535 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3536 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3537 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3538testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003539 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003540 var PagingTestCfg cfg := {
3541 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003542 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003543 load_factor := 2.0,
3544 exp_load_ind := true,
3545 exp_overload := true,
3546 use_tmsi := true
3547 };
3548 var PagingTestState st := f_TC_paging(cfg);
3549 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3550 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003551 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003552 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003553 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 +01003554 } else {
3555 setverdict(pass);
3556 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003558}
3559
3560
Harald Welte93640c62018-02-25 16:59:33 +01003561/***********************************************************************
3562 * Immediate Assignment / AGCH
3563 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003564private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003565 len := 0,
3566 ma := ''B
3567}
Harald Welte93640c62018-02-25 16:59:33 +01003568
Harald Weltee8d750e2018-06-10 21:41:35 +02003569private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3570 return int2str(num_tx) & " sent, "
3571 & int2str(num_rx) & " received, "
3572 & int2str(num_del) & " deleted";
3573}
3574
3575private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3576 var L1ctlDlMessage l1_dl;
3577 timer T := 10.0;
3578 var integer num_tx := 0;
3579 var integer num_rx := 0;
3580 var integer num_del := 0;
3581 var charstring res_str;
3582 var float rx_ratio;
3583
Harald Welte10474062019-05-30 16:48:17 +02003584 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003585 f_init_l1ctl();
3586 f_l1_tune(L1CTL);
3587
3588 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003589 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003590 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3591 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003592 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003593 num_tx := num_tx+1;
3594 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003595 }
3596 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003597 T.start;
3598 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003599 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003600 num_del := num_del+1;
3601 repeat;
3602 }
3603 [] RSL_CCHAN.receive {
3604 repeat;
3605 }
3606 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003607 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3608 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3609 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003610 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003611 } else {
3612 num_rx := num_rx+1;
3613 }
3614 repeat;
3615 }
3616 [] L1CTL.receive { repeat; }
3617 [] T.timeout { }
3618 }
3619 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3620 log("AGCH test: " & res_str);
3621 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003623 }
3624 rx_ratio := int2float(num_rx) / int2float(num_tx);
3625 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003626 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 +02003627 } else {
3628 setverdict(pass);
3629 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003631}
3632
Harald Weltee8d750e2018-06-10 21:41:35 +02003633/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3634testcase TC_imm_ass_1000_20ms() runs on test_CT {
3635 f_TC_imm_ass(1000, 0.02, 0.25);
3636}
3637
3638/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3639testcase TC_imm_ass_200_0ms() runs on test_CT {
3640 f_TC_imm_ass(200, 0.0, 0.05);
3641}
3642
3643/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3644testcase TC_imm_ass_200_76ms() runs on test_CT {
3645 f_TC_imm_ass(150, 0.076, 1.00);
3646}
3647
3648
3649
Harald Welte48494ca2018-02-25 16:59:50 +01003650/***********************************************************************
3651 * BCCH
3652 ***********************************************************************/
3653
3654/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003655private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003656 GsmFrameNumber frame_number,
3657 SystemInformation si
3658}
3659
3660/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003661private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003662
3663/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003664private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003665
3666/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003667private function f_si_vecslot_contains(SystemInformationVector arr,
3668 RrMessageType key,
3669 boolean bcch_ext := false)
3670return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003671 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3672 var integer fn_mod51 := arr[i].frame_number mod 51;
3673 if (not bcch_ext and fn_mod51 == 2 or
3674 bcch_ext and fn_mod51 == 6) {
3675 if (arr[i].si.header.message_type == key) {
3676 return true;
3677 }
3678 }
3679 }
3680 return false;
3681}
3682
3683/* 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 +07003684private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3685 integer tc, RrMessageType key,
3686 boolean ext_bcch := false)
3687{
Harald Welte48494ca2018-02-25 16:59:50 +01003688 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003690 }
3691}
3692
3693/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003694private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3695 RrMessageType key)
3696return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003697 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3698 if (f_si_vecslot_contains(arr[tc], key) or
3699 f_si_vecslot_contains(arr[tc], key, true)) {
3700 return true;
3701 }
3702 }
3703 return false;
3704}
3705
3706/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003707private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3708 RrMessageType key,
3709 boolean bcch_ext := false,
3710 integer n := 1, integer m := 4)
3711return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003712 var integer count := 0;
3713 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3715 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003716 }
3717 for (var integer i:= 0; i < m; i := i + 1) {
3718 var integer fn_mod51 := arr[i].frame_number mod 51;
3719 if (not bcch_ext and fn_mod51 == 2 or
3720 bcch_ext and fn_mod51 == 6) {
3721 if (arr[i].si.header.message_type == key) {
3722 count := count + 1;
3723 }
3724 }
3725 }
3726 if (count >= n) {
3727 return true;
3728 } else {
3729 return false;
3730 }
3731}
3732
3733/* 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 +07003734private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3735 integer tc, RrMessageType key,
3736 boolean ext_bcch := false,
3737 integer n, integer m)
3738{
Harald Welte48494ca2018-02-25 16:59:50 +01003739 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003741 }
3742}
3743
3744/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003745private function f_si_vecslot_contains_only(SystemInformationVector arr,
3746 RrMessageType key,
3747 boolean bcch_ext := false)
3748return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003749 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3750 var integer fn_mod51 := arr[i].frame_number mod 51;
3751 if (not bcch_ext and fn_mod51 == 2 or
3752 bcch_ext and fn_mod51 == 6) {
3753 if (arr[i].si.header.message_type != key) {
3754 return false;
3755 }
3756 }
3757 }
3758 return true;
3759}
3760
3761/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003762private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3763 integer tc, RrMessageType key,
3764 boolean ext_bcch := false)
3765{
Harald Welte48494ca2018-02-25 16:59:50 +01003766 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003767 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003768 }
3769}
3770
3771/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003772private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003773 boolean bcch_extended,
3774 boolean si1_present,
3775 boolean si2bis_present,
3776 boolean si2ter_present,
3777 boolean si2quater_present,
3778 boolean si7_present,
3779 boolean si8_present,
3780 boolean si9_present,
3781 boolean si13_present,
3782 boolean si13alt_present,
3783 boolean si15_present,
3784 boolean si16_present,
3785 boolean si17_present,
3786 boolean si2n_present,
3787 boolean si21_present,
3788 boolean si22_present
3789}
3790
3791/* 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 +07003792private function f_validate_si_scheduling(SystemInformationConfig cfg,
3793 SystemInformationVectorPerTc si_per_tc)
3794{
Harald Welte48494ca2018-02-25 16:59:50 +01003795 var integer i;
3796 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3797 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003799 }
3800 }
3801 if (cfg.si1_present) {
3802 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3803 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3804 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3805 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3806 /* make sure *ALL* contain SI1 */
3807 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3808 }
3809 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3810 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3811 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3812 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3813 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3814 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3815
3816 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3817 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3818 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3819 * consecutive occurrences of TC = 4. */
3820 if (cfg.si2bis_present and not cfg.si2ter_present) {
3821 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3822 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3823 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3824 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3825 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3826 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3827 }
3828
3829 if (cfg.si7_present or cfg.si8_present) {
3830 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3831 * if System Information type 4 does not contain all information needed for cell
3832 * selection and reselection. */
3833 if (not cfg.bcch_extended) {
3834 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3835 }
3836 if (cfg.si7_present) {
3837 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3838 }
3839 if (cfg.si8_present) {
3840 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3841 }
3842 }
3843
3844 if (cfg.si2quater_present) {
3845 /* iii) System information type 2 quater is sent if needed, as determined by the system
3846 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3847 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3848 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3849 * within any of 4 consecutive occurrences of TC = 5. */
3850 if (not (cfg.bcch_extended)) {
3851 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3852 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3853 } else {
3854 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3855 }
3856 } else {
3857 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3858 }
3859 }
3860 if (cfg.si9_present) {
3861 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3862 * in system information type 3 as defined in 3GPP TS 44.018. */
3863 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3864 }
3865 if (cfg.si13_present) {
3866 /* vii) System Information type 13 is only related to the GPRS service. System Information
3867 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3868 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3869 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3870 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3871 * within any of 4 consecutive occurrences of TC=4. */
3872 if (not cfg.bcch_extended) {
3873 log("not-bccch-extended");
3874 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3875 } else {
3876 log("bccch-extended");
3877 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3878 }
3879 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003881 }
3882 }
3883 if (cfg.si16_present or cfg.si17_present) {
3884 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3885 * should not be sent in a cell where network sharing is used (see rule xv). */
3886 if (cfg.si22_present) {
3887 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3888 }
3889 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003891 }
3892 if (not cfg.bcch_extended) {
3893 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3894 }
3895 if (cfg.si16_present) {
3896 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3897 }
3898 if (cfg.si17_present) {
3899 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3900 }
3901 }
3902
3903 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3904 * broadcast information. The frequency with which they are sent is determined by the
3905 * system operator. System Information type 9 identifies the scheduling of System
3906 * Information type 18 and 20 messages. */
3907
3908 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3909 * Information Type 19 is present, then its scheduling shall be indicated in System
3910 * Information Type 9. */
3911
3912 if (cfg.si15_present) {
3913 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3914 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3915 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3916 * 4 consecutive occurrences of TC = 1. */
3917 if (not cfg.bcch_extended) {
3918 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3919 } else {
3920 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3921 }
3922 }
3923 if (cfg.si13alt_present) {
3924 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3925 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3926 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3927 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3928 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3929 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3930 * of TC = 4. */
3931 if (cfg.si13_present) {
3932 testcase.stop("Error: Cannot have SI13alt and SI13");
3933 }
3934 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003935 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003936 }
3937 if (not cfg.bcch_extended) {
3938 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3939 } else {
3940 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3941 }
3942 }
3943 if (cfg.si2n_present) {
3944 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3945 * as determined by the system operator. In the case that the message is sent on the
3946 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3947 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3948 * consecutive occurrences of TC = 4. */
3949 if (not cfg.bcch_extended) {
3950 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3951 } else {
3952 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3953 }
3954 }
3955 if (cfg.si21_present) {
3956 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3957 * determined by the system operator. If Extended Access Barring is in use in the cell
3958 * then this message is sent at least once within any of 4 consecutive occurrences of
3959 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3960 * cell then this message shall only be sent on BCCH Ext. */
3961 if (not cfg.bcch_extended) {
3962 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3963 } else {
3964 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3965 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003967 }
3968 }
3969 }
3970 if (cfg.si22_present) {
3971 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3972 * should not be sent in a cell where SoLSA is used (see rule viii). System
3973 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3974 * =2 and TC=6. */
3975 if (cfg.si16_present or cfg.si17_present) {
3976 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3977 }
3978 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3979 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003981 }
3982 if (not cfg.bcch_extended) {
3983 testcase.stop("Error: SI22 requires BCCH Extd!");
3984 } else {
3985 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3986 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3987 }
3988 }
3989}
3990
3991/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003992private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3993return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003994 timer T := duration;
3995 var SystemInformationVectorPerTc si_per_tc;
3996 var L1ctlDlMessage l1_dl;
3997
3998 /* initialize all per-TC vectors empty */
3999 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4000 si_per_tc[i] := {};
4001 }
4002
4003 /* flush all previous L1 queued msgs */
4004 pt.clear;
4005
4006 T.start;
4007 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004008 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004009 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4010 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4011 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004012 repeat;
4013 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004014
Harald Welte48494ca2018-02-25 16:59:50 +01004015 var integer tc := f_gsm_compute_tc(sig.frame_number);
4016 log("SI received at TC=", tc, ": ", sig.si);
4017 /* append to the per-TC bucket */
4018 si_per_tc[tc] := si_per_tc[tc] & { sig };
4019 repeat;
4020 }
4021 [] pt.receive { repeat; }
4022 [] T.timeout { }
4023 }
4024
4025 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4026 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4027 }
4028 log("si_per_tc=", si_per_tc);
4029 return si_per_tc;
4030}
4031
4032/* helper function: Set given SI via RSL + validate scheduling.
4033 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004034private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004035 var SystemInformationVectorPerTc si_per_tc;
4036 f_init_l1ctl();
4037 f_l1_tune(L1CTL);
4038
4039 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004040 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004041 f_validate_si_scheduling(si_cfg, si_per_tc);
4042
4043 setverdict(pass);
4044}
4045
4046testcase TC_si_sched_default() runs on test_CT {
4047 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004048 /* 2+3+4 are mandatory and set in f_init() */
4049 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004051}
4052
4053testcase TC_si_sched_1() runs on test_CT {
4054 f_init();
4055 si_cfg.si1_present := true;
4056 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004057 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004059}
4060
4061testcase TC_si_sched_2bis() runs on test_CT {
4062 f_init();
4063 si_cfg.si2bis_present := true;
4064 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4065 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004067}
4068
4069testcase TC_si_sched_2ter() runs on test_CT {
4070 f_init();
4071 si_cfg.si2ter_present := true;
4072 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4073 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004075}
4076
4077testcase TC_si_sched_2ter_2bis() runs on test_CT {
4078 f_init();
4079 si_cfg.si2bis_present := true;
4080 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4081 si_cfg.si2ter_present := true;
4082 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4083 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004085}
4086
4087testcase TC_si_sched_2quater() runs on test_CT {
4088 f_init();
4089 si_cfg.si2quater_present := true;
4090 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004091 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004093}
4094
4095testcase TC_si_sched_13() runs on test_CT {
4096 f_init();
4097 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004098 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004099 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004101}
4102
4103testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4104 f_init();
4105 si_cfg.si2bis_present := true;
4106 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4107 si_cfg.si2ter_present := true;
4108 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4109 si_cfg.si2quater_present := true;
4110 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4111 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004112 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004113 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004115}
4116
4117
Harald Welte68e495b2018-02-25 00:05:57 +01004118testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004119 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004120 /* FIXME: enable / disable individual BCCH info */
4121 //ts_RSL_BCCH_INFO(si_type, info);
4122 /* expect no ERROR REPORT after either of them *
4123 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004124 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004125}
4126
Harald Welte93640c62018-02-25 16:59:33 +01004127/***********************************************************************
4128 * Low-Level Protocol Errors / ERROR REPORT
4129 ***********************************************************************/
4130
Harald Welte01d982c2018-02-25 01:31:40 +01004131private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4132 timer T := 5.0;
4133 T.start;
4134 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004135 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004136 setverdict(pass);
4137 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004138 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004140 }
4141 [] RSL_CCHAN.receive {
4142 repeat;
4143 }
4144 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004146 }
4147 }
4148}
4149
4150/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4151testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004152 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004153 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4154 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004155 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004156
4157 f_exp_err_rep(RSL_ERR_PROTO);
4158}
4159
4160/* Provoke a mandatory IE error and match on ERROR REPORT */
4161testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004162 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004163
4164 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4165 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004166 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004167
4168 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4169}
4170
4171/* Provoke an IE content error and match on ERROR REPORT */
4172testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004173 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004174 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4175 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004176 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004177
4178 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4179}
4180
Harald Welteee25aae2019-05-19 14:32:37 +02004181/* attempt to activate channel with wrong RSL Message Discriminator IE */
4182function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4183 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4184 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4185 RSL.send(rsl);
4186 f_rslem_unregister(0, g_chan_nr);
4187}
4188testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4189 var ConnHdlr vc_conn;
4190 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4191
Harald Welte10474062019-05-30 16:48:17 +02004192 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004193
4194 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4195 vc_conn.done;
4196 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4197
4198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4199}
4200
4201/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004202private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004203 var template (value) RSL_Message rsl_tx;
4204 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4205 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4206 RSL.send(rsl_tx);
4207 f_rslem_unregister(0, g_chan_nr);
4208}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004209private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004210 var template (value) RSL_Message rsl_tx;
4211 /* we first have to activate the dedicated channel */
4212 f_rsl_chan_act(g_pars.chan_mode);
4213 /* ... to then send an invalid RLL message */
4214 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4215 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4216 RSL.send(rsl_tx);
4217 f_rslem_unregister(0, g_chan_nr);
4218}
4219testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4220 var ConnHdlr vc_conn;
4221 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4222 var template (value) RSL_Message rsl_tx;
4223
Harald Welte10474062019-05-30 16:48:17 +02004224 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004225
4226 /* Common Channel with wrong message type */
4227 RSL_CCHAN.clear;
4228 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4229 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004230 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004231 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4232
4233 /* TRX Management */
4234 RSL_CCHAN.clear;
4235 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4236 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004237 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004238 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4239
4240 /* Dedicated Channel */
4241 RSL_CCHAN.clear;
4242 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4243 vc_conn.done;
4244 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4245
4246 /* RLL */
4247 RSL_CCHAN.clear;
4248 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4249 vc_conn.done;
4250 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4251}
4252
4253/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004254private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004255 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4256 f_rslem_unregister(0, g_chan_nr);
4257}
4258testcase TC_err_rep_wrong_sequence() runs on test_CT {
4259 var ConnHdlr vc_conn;
4260 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4261
Harald Welte10474062019-05-30 16:48:17 +02004262 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004263
4264 RSL_CCHAN.clear;
4265 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4266 vc_conn.done;
4267 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4268}
4269
Harald Welte93640c62018-02-25 16:59:33 +01004270/***********************************************************************
4271 * IPA CRCX/MDCX/DLCS media stream handling
4272 ***********************************************************************/
4273
Harald Weltea871a382018-02-25 02:03:14 +01004274/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004275private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004276 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4277 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004278}
4279testcase TC_ipa_dlcx_not_active() runs on test_CT {
4280 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004281 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004282 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4283 vc_conn.done;
4284}
Harald Welte68e495b2018-02-25 00:05:57 +01004285
Harald Weltea3f1df92018-02-25 12:49:55 +01004286/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004287private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004288 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4289 "IPA CRCX ACK");
4290 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4291 "IPA CRCX NACK");
4292}
4293testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4294 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004295 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004296 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4297 vc_conn.done;
4298}
4299
4300/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004301private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004302 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4303 "IPA CRCX ACK");
4304 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4305 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4306 var uint7_t rtp_pt2 := f_rnd_int(127);
4307 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4308 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4309 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4310 "IPA MDCX ACK");
4311 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4312 "IPA DLCX ACK");
4313}
4314testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4315 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004316 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004317 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4318 vc_conn.done;
4319}
4320
Harald Welte3ae11da2018-02-25 13:36:06 +01004321/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004322private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004323 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4324 "IPA CRCX ACK");
4325 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4326 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4327 var uint7_t rtp_pt2 := f_rnd_int(127);
4328 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4329 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4330 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4331 "IPA MDCX ACK");
4332 /* Second MDCX */
4333 remote_ip := f_rnd_int(c_UINT32_MAX);
4334 remote_port := f_rnd_int(c_UINT16_MAX);
4335 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4336 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4337 "IPA MDCX ACK");
4338 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4339 "IPA DLCX ACK");
4340}
4341testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4342 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004343 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004344 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4345 vc_conn.done;
4346}
4347
Harald Welte9912eb52018-02-25 13:30:15 +01004348/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004349private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004350 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4351 "IPA CRCX NACK");
4352}
4353testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4354 var ConnHdlrPars pars;
4355 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004356 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004357
4358 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4359 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4360 vc_conn.done;
4361
4362 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4363 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4364 vc_conn.done;
4365}
4366
Harald Weltea3f1df92018-02-25 12:49:55 +01004367
Harald Welte883340c2018-02-28 18:59:29 +01004368/***********************************************************************
4369 * PCU Socket related tests
4370 ***********************************************************************/
4371
Harald Welte07bd2d22019-05-25 11:03:30 +02004372/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004373friend 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 +01004374runs on test_CT {
4375 timer T := 3.0;
4376
4377 /* we don't expect any RTS.req before PDCH are active */
4378 T.start;
4379 alt {
4380 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004382 }
4383 [] PCU.receive { repeat; }
4384 [] T.timeout { }
4385 }
4386
4387 /* Send PDCH activate request for known PDCH timeslot */
4388 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4389
4390 /* we now expect RTS.req for this timeslot (only) */
4391 T.start;
4392 alt {
4393 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4394 setverdict(pass);
4395 }
4396 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4397 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004399 }
4400 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004402 }
4403 [] PCU.receive { repeat; }
4404 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004406 }
4407 [not exp_success] T.timeout {
4408 setverdict(pass);
4409 }
4410 }
4411}
4412
Harald Welte07bd2d22019-05-25 11:03:30 +02004413/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004414friend 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 +01004415runs on test_CT {
4416 timer T := 3.0;
4417
4418 /* Send PDCH activate request for known PDCH timeslot */
4419 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 +02004420 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4421 * when it will actually have been executed in the BTS */
4422 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004423 PCU.clear;
4424 /* we now expect no RTS.req for this timeslot */
4425 T.start;
4426 alt {
4427 [] 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 +02004428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004429 }
4430 [] PCU.receive { repeat; }
4431 [] T.timeout {
4432 setverdict(pass);
4433 }
4434 }
4435}
4436
Harald Weltead033dc2019-05-25 17:28:16 +02004437friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004438 f_init();
4439 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4440}
4441
Harald Welte883340c2018-02-28 18:59:29 +01004442/* PDCH activation via PCU socket; check for presence of RTS.req */
4443testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004444 f_init_pcu_test();
4445
Harald Welte883340c2018-02-28 18:59:29 +01004446 f_TC_pcu_act_req(0, 0, 7, true);
4447}
4448
4449/* PDCH activation via PCU socket on non-PDCU timeslot */
4450testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004451 f_init_pcu_test();
4452
Harald Welte883340c2018-02-28 18:59:29 +01004453 f_TC_pcu_act_req(0, 0, 1, false);
4454}
4455
4456/* PDCH activation via PCU socket on wrong BTS */
4457testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004458 f_init_pcu_test();
4459
Harald Welte883340c2018-02-28 18:59:29 +01004460 f_TC_pcu_act_req(23, 0, 7, false);
4461}
4462
4463/* PDCH activation via PCU socket on wrong TRX */
4464testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004465 f_init_pcu_test();
4466
Harald Welte883340c2018-02-28 18:59:29 +01004467 f_TC_pcu_act_req(0, 23, 7, false);
4468}
4469
4470/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4471testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004472 f_init_pcu_test();
4473
Harald Welte883340c2018-02-28 18:59:29 +01004474 /* Activate PDCH */
4475 f_TC_pcu_act_req(0, 0, 7, true);
4476 f_sleep(1.0);
4477 /* and De-Activate again */
4478 f_TC_pcu_deact_req(0, 0, 7);
4479}
4480
4481/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4482testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004483 f_init_pcu_test();
4484
Harald Welte883340c2018-02-28 18:59:29 +01004485 f_TC_pcu_deact_req(0, 0, 1);
4486}
4487
4488/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4489testcase TC_pcu_ver_si13() runs on test_CT {
4490 const octetstring si13 := '00010203040506070909'O;
4491 var PCUIF_send_data sd;
4492 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004493 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004494
4495 /* Set SI13 via RSL */
4496 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004497
Harald Welte883340c2018-02-28 18:59:29 +01004498 T.start;
4499 alt {
4500 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4501 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4502 setverdict(pass);
4503 } else {
4504 repeat;
4505 }
4506 }
4507 [] PCU.receive { repeat; }
4508 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004510 }
4511 }
4512}
4513
4514private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4515
4516/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004517friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004518 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4519runs on test_CT
4520{
4521 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4522 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4523}
4524
4525/* 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 +02004526friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4527 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004528runs on test_CT
4529{
4530 var PCUIF_send_data sd;
4531
4532 timer T := 3.0;
4533 T.start;
4534 alt {
4535 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4536 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4537 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4538 sd.data.u.rts_req.fn, sapi, data);
4539 }
4540 [] PCU.receive { repeat; }
4541 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004543 }
4544 }
4545}
4546
4547/* Send DATA.req on invalid BTS */
4548testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004549 var TfiUsfArr tua := f_TfiUsfArrInit();
4550 var octetstring data := '0000'O & f_rnd_octstring(21);
4551
4552 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004553
Harald Welte883340c2018-02-28 18:59:29 +01004554 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004555 f_TfiUsfArrSet(tua, 7, 0);
4556 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4557 f_sleep(1.0);
4558
4559 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004560}
4561
4562/* Send DATA.req on invalid TRX */
4563testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004564 var TfiUsfArr tua := f_TfiUsfArrInit();
4565 var octetstring data := '0000'O & f_rnd_octstring(21);
4566
4567 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004568
Harald Welte883340c2018-02-28 18:59:29 +01004569 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004570 f_TfiUsfArrSet(tua, 7, 0);
4571 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4572 f_sleep(1.0);
4573
4574 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004575}
4576
4577/* Send DATA.req on invalid timeslot */
4578testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004579 var TfiUsfArr tua := f_TfiUsfArrInit();
4580 var octetstring data := '0000'O & f_rnd_octstring(21);
4581
4582 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004583
Harald Welte883340c2018-02-28 18:59:29 +01004584 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004585 f_TfiUsfArrSet(tua, 7, 0);
4586 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4587 f_sleep(1.0);
4588
4589 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004590}
4591
4592/* Send DATA.req on timeslot that hasn't been activated */
4593testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004594 var TfiUsfArr tua := f_TfiUsfArrInit();
4595 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004596
Harald Welte7162a612019-05-26 12:56:09 +02004597 f_virtphy_common();
4598
4599 f_TfiUsfArrSet(tua, 7, 0);
4600 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4601 f_sleep(1.0);
4602
4603 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004604}
4605
Harald Weltead033dc2019-05-25 17:28:16 +02004606private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004607 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4608 boolean wait_rts := true)
4609runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004610 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004611 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004612
4613 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004614 if (wait_rts) {
4615 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4616 } else {
4617 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4618 }
Harald Weltead033dc2019-05-25 17:28:16 +02004619
4620 T.start;
4621 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004622 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004623 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4624 setverdict(pass);
4625 }
Harald Welte7162a612019-05-26 12:56:09 +02004626 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4627 setverdict(fail, "Received unexpected ", rx_dl);
4628 }
Harald Weltead033dc2019-05-25 17:28:16 +02004629 [] L1CTL.receive {
4630 repeat;
4631 }
Harald Welte7162a612019-05-26 12:56:09 +02004632 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004633 setverdict(fail, "Timeout waiting for ", data);
4634 }
Harald Welte7162a612019-05-26 12:56:09 +02004635 [not expect_data] T.timeout {
4636 setverdict(pass);
4637 }
Harald Weltead033dc2019-05-25 17:28:16 +02004638 }
4639}
4640
4641private function f_disable_dynamic_ts() runs on test_CT
4642{
4643 f_init_vty_bsc();
4644 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4645 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4646 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4647 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004648 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004649}
4650
4651private function f_virtphy_common() runs on test_CT {
4652 f_disable_dynamic_ts();
4653 f_init_l1ctl();
4654 f_l1_tune(L1CTL);
4655}
4656
4657testcase TC_pcu_data_req_pdtch() runs on test_CT {
4658 var TfiUsfArr tua := f_TfiUsfArrInit();
4659 var octetstring data := '0000'O & f_rnd_octstring(21);
4660
4661 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004662
Harald Welte883340c2018-02-28 18:59:29 +01004663 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004664 f_TfiUsfArrSet(tua, 7, 0);
4665 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4666 f_sleep(1.0);
4667
4668 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004669}
4670
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004671/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004672testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004673 var TfiUsfArr tua := f_TfiUsfArrInit();
4674 var octetstring data := '0000'O & f_rnd_octstring(21);
4675
4676 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004677
Harald Welte883340c2018-02-28 18:59:29 +01004678 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004679 f_TfiUsfArrSet(tua, 7, 0);
4680 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4681 f_sleep(1.0);
4682
4683 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004684}
4685
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004686private function f_TC_pcu_ptcch_ul(uint16_t ra)
4687runs on test_CT {
4688 var template PCUIF_Message pcu_rach_ind;
4689 var PCUIF_send_data sd;
4690 var GsmFrameNumber fn;
4691 timer T;
4692
4693 /* Send an Access Burst on PTCCH/U over the Um-interface */
4694 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4695 chan_nr := ts_RslChanNr_PDCH(7),
4696 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4697
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004698 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4699 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004700
4701 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4702 T.start(52.0 * 4.615 / 1000.0);
4703 alt {
4704 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4705 log("Rx an Access Burst on the PCU interface: ", sd.data);
4706 setverdict(pass);
4707 T.stop;
4708 }
4709 [] PCU.receive { repeat; }
4710 [] T.timeout {
4711 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4712 /* Keep going, that's not the end of the world */
4713 }
4714 }
4715}
4716
4717testcase TC_pcu_ptcch() runs on test_CT {
4718 var L1ctlDlMessage dl;
4719 var octetstring data;
4720 timer T;
4721
4722 f_init_pcu_test();
4723 f_init_l1ctl();
4724 f_l1_tune(L1CTL);
4725
4726 /* Activate PDCH channel on TS7 */
4727 f_TC_pcu_act_req(0, 0, 7, true);
4728
4729 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004730 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004731 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004732 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004733 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004734
4735 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4736 for (var integer i := 0; i < 16; i := i + 1) {
4737 log("Sending an Access Burst towards the L1CTL interface");
4738 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4739 }
4740
4741 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4742 data := f_rnd_octstring(23);
4743
4744 /* Verify PTCCH/D: send a random data block, make sure it's received */
4745 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4746 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4747
4748 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4749 * let's give it more time in case if we miss the beginning. */
4750 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4751 alt {
4752 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4753 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4754 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4755 frame := data)) -> value dl {
4756 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4757 setverdict(pass);
4758 T.stop;
4759 }
4760 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4761 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4762 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4763 l2_data := data)) -> value dl {
4764 log("Rx PTCCH/D data block on L1CTL: ", dl);
4765 setverdict(pass);
4766 T.stop;
4767 }
4768 [] L1CTL.receive { repeat; }
4769 [] T.timeout {
4770 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4771 }
4772 }
4773}
4774
Harald Welte883340c2018-02-28 18:59:29 +01004775/* Send AGCH from PCU; check it appears on Um side */
4776testcase TC_pcu_data_req_agch() runs on test_CT {
4777 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004778 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004779 f_init_l1ctl();
4780 f_l1_tune(L1CTL);
4781
4782 f_TC_pcu_act_req(0, 0, 7, true);
4783 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4784
4785 T.start;
4786 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004787 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004788 setverdict(pass);
4789 }
4790 [] L1CTL.receive { repeat; }
4791 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004793 }
4794 }
4795}
4796
Harald Welte928622b2019-05-26 13:22:59 +02004797/* Send AGCH from PCU; check it appears on Um side */
4798testcase TC_pcu_data_req_pch() runs on test_CT {
4799 timer T := 3.0;
4800 f_init_pcu_test();
4801 f_init_l1ctl();
4802 f_l1_tune(L1CTL);
4803
4804 f_TC_pcu_act_req(0, 0, 7, true);
4805 /* three characters prefix: last 3 digits of IMSI as ASCII */
4806 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4807
4808 T.start;
4809 alt {
4810 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4811 setverdict(pass);
4812 }
4813 [] L1CTL.receive { repeat; }
4814 [] T.timeout {
4815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4816 }
4817 }
4818}
4819
Harald Welte883340c2018-02-28 18:59:29 +01004820/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4821testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4822 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004823 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004824 f_init_l1ctl();
4825 f_l1_tune(L1CTL);
4826
4827 /* append 3 last imsi digits so BTS can compute pagng group */
4828 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4829
4830 timer T := 0.5;
4831 T.start;
4832 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004833 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004834 /* TODO: verify paging group */
4835 setverdict(pass);
4836 }
4837 [] L1CTL.receive { repeat; }
4838 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004840 }
4841 }
4842}
4843
4844/* Send RACH from Um side, expect it to show up on PCU socket */
4845testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004846 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004847 f_init_l1ctl();
4848 f_l1_tune(L1CTL);
4849
4850 var GsmFrameNumber fn_last := 0;
4851 for (var integer i := 0; i < 1000; i := i+1) {
4852 var OCT1 ra := f_rnd_ra_ps();
4853 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4854 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004856 }
4857 fn_last := fn;
4858
4859 timer T := 2.0;
4860 T.start;
4861 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004862 [] 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 +01004863 T.stop;
4864 }
4865 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004867 }
4868 [] PCU.receive { repeat; }
4869 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004871 }
4872 }
4873 }
4874 setverdict(pass);
4875}
4876
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004877/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4878 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4879testcase TC_pcu_ext_rach_content() runs on test_CT {
4880 var template PCUIF_Message pcu_rach_ind;
4881 var GsmFrameNumber fn_last := 0;
4882 var L1ctlRachSynchSeq synch_seq;
4883 var PCUIF_BurstType pcu_bt;
4884 var GsmFrameNumber fn;
4885 var BIT11 ra11;
4886
4887 f_init_pcu_test();
4888 f_init_l1ctl();
4889 f_l1_tune(L1CTL);
4890
4891 for (var integer i := 0; i < 1000; i := i+1) {
4892 /* We need to test both TS1 & TS2 */
4893 if (i rem 2 == 0) {
4894 synch_seq := RACH_SYNCH_SEQ_TS1;
4895 pcu_bt := BURST_TYPE_1;
4896 } else {
4897 synch_seq := RACH_SYNCH_SEQ_TS2;
4898 pcu_bt := BURST_TYPE_2;
4899 }
4900
4901 ra11 := f_rnd_ra11_ps();
4902 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4903 if (fn == fn_last) {
4904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4905 "Two RACH in same FN?!?");
4906 }
4907 fn_last := fn;
4908
4909 /* Compose the expected message */
4910 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004911 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004912 ra := bit2int(ra11),
4913 is_11bit := 1,
4914 burst_type := pcu_bt,
4915 fn := fn);
4916
4917 timer T := 2.0;
4918 T.start;
4919 alt {
4920 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4921 T.stop;
4922 }
4923 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4925 }
4926 [] PCU.receive { repeat; }
4927 [] T.timeout {
4928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4929 }
4930 }
4931 }
4932 setverdict(pass);
4933}
4934
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004935private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4936runs on test_CT {
4937 var template PCUIF_send_data sdt;
4938 var PCUIF_send_data sd;
4939 var int16_t lqual_cb;
4940 timer T := 1.0;
4941
4942 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4943 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4944
4945 /* Send a random PDTCH frame over Um */
4946 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4947 '0000'O & f_rnd_octstring(21)));
4948
4949 T.start;
4950 alt {
4951 /* If expected link quality is above the threshold */
4952 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4953 lqual_cb := sd.data.u.data_ind.lqual_cb;
4954 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4955
4956 /* Make sure the actual link quality matches the expected value */
4957 if (not match(lqual_cb, lqual_cb_exp)) {
4958 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4959 "expected value ", lqual_cb_exp));
4960 } else {
4961 setverdict(pass);
4962 }
4963 }
4964 /* If expected link quality is below the threshold */
4965 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4967 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4968 }
4969 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4970 [] PCU.receive { repeat; }
4971 [lqual_cb_exp < thresh] T.timeout {
4972 log("Rx nothing, as expected");
4973 setverdict(pass);
4974 }
4975 [lqual_cb_exp >= thresh] T.timeout {
4976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4977 "Timeout waiting for PCUIF_DATA.ind");
4978 }
4979 }
4980}
4981
4982/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4983testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4984 f_init_pcu_test();
4985 PCU.clear;
4986
4987 f_init_l1ctl();
4988 f_l1_tune(L1CTL);
4989
4990 /* Activate a PDCH channel on TS7 */
4991 f_TC_pcu_act_req(0, 0, 7, true);
4992
4993 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004994 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004995 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004996 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004997 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004998
4999 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5000 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5001 var TrxcMessage ret;
5002
5003 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5004 valueof(ts_TRXC_FAKE_CI(i)));
5005
5006 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5007 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5008 }
5009}
5010
Harald Welte883340c2018-02-28 18:59:29 +01005011/* Send PAGING via RSL, expect it to shw up on PCU socket */
5012testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005013 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005014
5015 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005016 var MobileIdentityLV mi_lv;
5017 var octetstring mi_lv_enc;
5018 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005019 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005020
Harald Welte883340c2018-02-28 18:59:29 +01005021 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005022 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005023 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005024 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005025 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005026
5027 /* Fancy encoding for PCUIF */
5028 mi_lv := valueof(ts_MI_LV(mi));
5029 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5030 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005031
5032 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005033 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005034 T.start;
5035 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005036 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005037 }
5038 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005040 }
5041 [] PCU.receive { repeat; }
5042 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005044 }
5045 }
5046 }
5047 setverdict(pass);
5048}
5049
Harald Welted66c9b82019-05-25 09:03:15 +02005050/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5051testcase TC_pcu_time_ind() runs on test_CT {
5052 var PCUIF_send_data pcu_sd;
5053 var integer num_time_ind := 0;
5054 var integer first_fn, last_fn;
5055 var float test_duration := 5.0;
5056 timer T;
5057
5058 f_init_pcu_test();
5059 f_TC_pcu_act_req(0, 0, 7, true);
5060
5061 PCU.clear;
5062 T.start(test_duration);
5063 alt {
5064 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5065 num_time_ind := num_time_ind + 1;
5066 if (not isbound(first_fn)) {
5067 first_fn := pcu_sd.data.u.time_ind.fn;
5068 }
5069 last_fn := pcu_sd.data.u.time_ind.fn;
5070 repeat;
5071 }
5072 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5073 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5074 repeat;
5075 }
5076 [] PCU.receive {
5077 repeat;
5078 }
5079 [] T.timeout {}
5080 }
5081 var integer fn_expired := last_fn - first_fn;
5082 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5083
5084 /* verify the number of frames expired matches our expectation */
5085 const float c_GSM_FN_DURATION_MS := 4.61538;
5086 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005087 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005088 if (not match(fn_expired, t_fn_expected)) {
5089 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5090 }
5091
5092 /* There are three TIME.ind in every fn MOD 13 */
5093 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5094 /* Add some tolerance */
5095 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5096 if (not match(num_time_ind, t_time_ind_exp)) {
5097 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5098 }
5099
5100 setverdict(pass);
5101}
5102
Harald Welte4832c862019-05-25 14:57:18 +02005103/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5104testcase TC_pcu_rts_req() runs on test_CT {
5105 var PCUIF_send_data pcu_sd;
5106 var integer first_fn, last_fn;
5107 var integer num_rts_pdtch := 0;
5108 var integer num_rts_ptcch := 0;
5109 var float test_duration := 5.0;
5110 timer T;
5111
5112 f_init_pcu_test();
5113 f_TC_pcu_act_req(0, 0, 7, true);
5114
5115 PCU.clear;
5116 T.start(test_duration);
5117 alt {
5118 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5119 -> value pcu_sd {
5120 num_rts_pdtch := num_rts_pdtch + 1;
5121 if (not isbound(first_fn)) {
5122 first_fn := pcu_sd.data.u.rts_req.fn;
5123 }
5124 last_fn := pcu_sd.data.u.rts_req.fn;
5125 repeat;
5126 }
5127 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5128 -> value pcu_sd {
5129 num_rts_ptcch := num_rts_ptcch + 1;
5130 if (not isbound(first_fn)) {
5131 first_fn := pcu_sd.data.u.rts_req.fn;
5132 }
5133 last_fn := pcu_sd.data.u.rts_req.fn;
5134 repeat;
5135 }
5136 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5137 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5138 repeat;
5139 }
5140 [] PCU.receive {
5141 repeat;
5142 }
5143 [] T.timeout {}
5144 }
5145 var integer fn_expired := last_fn - first_fn;
5146 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5147 ", num_rts_ptcch=", num_rts_ptcch);
5148
5149 /* verify the number of frames expired matches our expectation */
5150 const float c_GSM_FN_DURATION_MS := 4.61538;
5151 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005152 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005153 if (not match(fn_expired, t_fn_expected)) {
5154 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5155 }
5156
5157 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5158 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5159 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5160 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5161 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5162 t_ptcch_exp);
5163 }
5164
5165 /* We have 12 PDTCH blocks every 52-multiframe */
5166 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5167 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5168 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5169 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5170 t_pdtch_exp);
5171 }
5172
5173 setverdict(pass);
5174}
5175
Harald Welte07bd2d22019-05-25 11:03:30 +02005176/* test for generating Abis side OML ALERT from the PCU */
5177testcase TC_pcu_oml_alert() runs on test_CT {
5178 var PCUIF_send_data pcu_sd;
5179 var integer num_time_ind := 0;
5180 var integer first_fn, last_fn;
5181 var float test_duration := 5.0;
5182 timer T;
5183
5184 f_init_pcu_test();
5185 f_TC_pcu_act_req(0, 0, 7, true);
5186
5187 /* re-connect CTRL port from BTS to BSC */
5188 f_ipa_ctrl_stop();
5189 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5190
5191 /* Send that OML Alert */
5192 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5193
5194 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5195 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5196 setverdict(pass);
5197}
5198
Harald Welteeaa9a862019-05-26 23:01:08 +02005199/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5200private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5201 var PCUIF_Message first_info;
5202 var integer pcu_conn_id := -1;
5203 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5204 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5205 var OCT4 tlli := '01020304'O;
5206 var OCT1 cause := '23'O;
5207 timer T := 5.0;
5208
5209 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5210
5211 f_l1_tune(L1CTL);
5212 RSL.clear;
5213
5214 f_est_dchan();
5215 L1CTL.clear;
5216
5217 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5218
5219 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5220 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5221 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5222
5223 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5224 T.start;
5225 alt {
5226 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5227 setverdict(pass);
5228 }
5229 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5230 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5231 }
5232 [] PCU.receive {
5233 repeat;
5234 }
5235 [] T.timeout {
5236 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5237 }
5238 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005239
5240 /* release the channel */
5241 f_rsl_chan_deact();
5242 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5243 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005244}
5245testcase TC_pcu_rr_suspend() runs on test_CT {
5246 var ConnHdlrPars pars;
5247 var ConnHdlr vc_conn;
5248
5249 f_init();
5250
5251 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5252 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5253 vc_conn.done;
5254}
Harald Welte07bd2d22019-05-25 11:03:30 +02005255
Harald Weltea2e0e942019-05-27 18:12:53 +02005256/* Ensure that PCUIF socket can accept only a single connection */
5257testcase TC_pcu_socket_connect_multi() runs on test_CT {
5258 timer T := 5.0;
5259
5260 /* this (among other things) establishes the first connection to the PCUIF socket */
5261 f_init();
5262
5263 /* try to establish a second connection, expect it to fail */
5264 PCU.send(UD_connect:{mp_pcu_socket, -1});
5265 T.start;
5266 alt {
5267 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5268 setverdict(pass);
5269 }
5270 [] PCU.receive(UD_connect_result:?) {
5271 setverdict(fail, "Unexpected unix domain connect result");
5272 }
5273 [] T.timeout {
5274 setverdict(pass);
5275 }
5276 }
5277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5278}
5279
Harald Weltec8effb72019-05-27 18:23:04 +02005280/* Ensure that PCUIF socket can disconnect + reconnect */
5281testcase TC_pcu_socket_reconnect() runs on test_CT {
5282 /* this (among other things) establishes the first connection to the PCUIF socket */
5283 f_init();
5284
5285 f_sleep(1.0);
5286
5287 f_pcuif_close(PCU, g_pcu_conn_id);
5288 g_pcu_conn_id := -1;
5289
5290 f_sleep(1.0);
5291
5292 /* re-connect */
5293 PCU.clear;
5294 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5295 setverdict(pass);
5296
5297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5298}
5299
Harald Weltebe030482019-05-27 22:29:35 +02005300/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005301private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5302runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005303 var L1ctlDlMessage l1_dl;
5304 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005305 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005306 timer T := 5.0;
5307 T.start;
5308 alt {
5309 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005310 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5311 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005312 repeat;
5313 }
5314 }
5315 [] pt.receive {
5316 repeat;
5317 }
5318 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5320 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005321 }
5322 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005323 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005324}
5325
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005326/* Check if GPRS Indicator is present in RR System Information of a given type */
5327private function f_si_has_gprs_indicator(RrMessageType si_type)
5328runs on test_CT return boolean {
5329 var SystemInformation si := f_get_si(L1CTL, si_type);
5330
5331 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005332 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005333 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005334 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005335 }
5336
5337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5338 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005339}
5340
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005341/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5342private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5343runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005344 /* don't call f_init() as this would connect PCU socket */
5345 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005346
5347 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005348 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005349 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005350
5351 f_init_l1ctl();
5352 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005353 f_sleep(2.0);
5354 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005355
5356 if (f_si_has_gprs_indicator(si_type)) {
5357 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005358 } else {
5359 setverdict(pass);
5360 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005361
Harald Weltebe030482019-05-27 22:29:35 +02005362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5363}
5364
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005365testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5366 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5367}
Harald Weltebe030482019-05-27 22:29:35 +02005368
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005369testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5370 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5371}
5372
5373/* Ensure that GPRS capability is advertised after PCU socket connect */
5374private function f_TC_pcu_socket_connect(RrMessageType si_type)
5375runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005376 /* this (among other things) establishes the first connection to the PCUIF socket */
5377 f_init();
5378 f_init_l1ctl();
5379 f_l1_tune(L1CTL);
5380
5381 f_sleep(2.0);
5382 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005383
5384 if (not f_si_has_gprs_indicator(si_type)) {
5385 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005386 } else {
5387 setverdict(pass);
5388 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005389
Harald Weltebe030482019-05-27 22:29:35 +02005390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5391}
5392
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005393testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5394 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5395}
Harald Weltebe030482019-05-27 22:29:35 +02005396
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005397testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5398 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5399}
5400
5401/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5402private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5403runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005404 /* this (among other things) establishes the first connection to the PCUIF socket */
5405 f_init();
5406 f_init_l1ctl();
5407 f_l1_tune(L1CTL);
5408
5409 f_pcuif_close(PCU, g_pcu_conn_id);
5410 g_pcu_conn_id := -1;
5411
5412 f_sleep(1.0);
5413
5414 /* re-connect */
5415 PCU.clear;
5416 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5417
5418 f_sleep(2.0);
5419 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005420
5421 if (f_si_has_gprs_indicator(si_type)) {
5422 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005423 } else {
5424 setverdict(pass);
5425 }
5426
5427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5428}
5429
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005430testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5431 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5432}
5433
5434testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5435 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5436}
5437
Oliver Smithf5239c72019-08-28 10:01:25 +02005438/* 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) */
5439testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5440 var SystemInformation si3 := valueof(ts_SI3_default);
5441
5442 f_init();
5443
Harald Welte76220222020-10-11 20:32:44 +02005444 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5445 * information */
5446 timer T := 2.0;
5447 T.start;
5448 alt {
5449 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5450 [] T.timeout {}
5451 }
5452
Oliver Smithf5239c72019-08-28 10:01:25 +02005453 /* Verify cell_id */
5454 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5455 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5456 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005457 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5458 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5459 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005460 }
5461
5462 /* Verify LAC */
5463 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5464 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5465 if (lac_si3 != lac_pcu) {
5466 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5467 }
5468
5469 setverdict(pass);
5470}
Harald Welted66c9b82019-05-25 09:03:15 +02005471
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005472/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5473testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5474 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005475 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005476
5477 f_init();
5478
5479 info_ind := g_pcu_last_info.u.info_ind;
5480
5481 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5482 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5483 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5484 /* Skip inactive timeslots */
5485 continue;
5486 }
5487
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005488 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005489 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005490 else
5491 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005492
5493 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005494 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005495 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005496 hsn := fhp.maio_hsn.hsn,
5497 maio := fhp.maio_hsn.maio,
5498 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005499 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005500 } else {
5501 tr_ts := tr_PCUIF_InfoTrxTsH0;
5502 }
5503
5504 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5505 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5506 if (not match(ts, tr_ts)) {
5507 setverdict(fail, "Hopping parameters do not match: ",
5508 "received ", ts, " vs expected ", tr_ts);
5509 } else {
5510 setverdict(pass);
5511 }
5512 }
5513 }
5514}
5515
Alexander Couzens5283f552020-07-28 15:39:04 +02005516/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5517testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5518 f_init_vty_bsc();
5519 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5520 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5521
5522 f_init();
5523
5524 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5525 if (not ischosen(remote_addr.v10)) {
5526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5527 log2str("Unexpected remote_addr: ", remote_addr));
5528 }
5529
5530 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5531 setverdict(fail, "Received address family is not IPv4");
5532 }
5533
5534 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5535 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5536 }
5537
5538 setverdict(pass);
5539}
5540
5541/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5542testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5543 f_init_vty_bsc();
5544 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5545
5546 f_init();
5547
5548 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5549 if (not ischosen(remote_addr.v10)) {
5550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5551 log2str("Unexpected remote_addr: ", remote_addr));
5552 }
5553
5554 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5555 setverdict(fail, "Received address family is not IPv6");
5556 }
5557
5558 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5559 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5560 }
5561
5562 setverdict(pass);
5563}
5564
Harald Welte3d04ae62018-04-04 20:29:05 +02005565/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005566 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005567 ***********************************************************************/
5568
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005569private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5570 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005571runs on ConnHdlr {
5572 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005573
5574 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005575 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005576 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5577 repeat;
5578 }
5579 }
5580}
5581
5582private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5583runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005584 /* Expect BTS to immediately acknowledge activation as PDCH */
5585 PCU.clear;
5586 f_rsl_chan_act(g_pars.chan_mode);
5587 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005588 timer T_wait := 2.0;
5589 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005590 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005591 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005592 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005593 [] T_wait.timeout {
5594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5595 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5596 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005597 }
5598 /* try to activate this PDCH from the PCU point of view */
5599 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5600 /* FIXME: is there a response? */
5601}
5602
5603private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5604runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005605 /* Send RSL CHAN REL (deactivate) */
5606 PCU.clear;
5607 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5608 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005609 timer T_wait := 2.0;
5610 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005611 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005612 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005613 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005614 [] T_wait.timeout {
5615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5616 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5617 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005618 }
5619 /* Emulate PCU asking BTS to deactivate PDCH */
5620 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5621 alt {
5622 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5623 setverdict(pass);
5624 }
5625 [] RSL.receive { repeat; }
5626 }
5627}
5628
5629/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005630private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005631 var PCUIF_Message first_info;
5632 var integer ts_nr := g_chan_nr.tn;
5633 var integer trx_nr := 0;
5634 var integer bts_nr := 0;
5635 var integer pcu_conn_id := -1;
5636
5637 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5638
5639 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5640 f_sleep(3.0);
5641 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5642 setverdict(pass);
5643}
5644testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5645 var ConnHdlrPars pars;
5646 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005647 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005648
5649 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5650 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5651 vc_conn.done;
5652}
5653
5654/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005655private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005656 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005657 var integer pcu_conn_id := -1;
5658
5659 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5660
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005661 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5662 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5663 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005664 setverdict(pass);
5665}
5666testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5667 var ConnHdlrPars pars;
5668 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005669 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005670
5671 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5672 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5673 vc_conn.done;
5674}
5675
5676/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005677private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005678 var PCUIF_Message first_info;
5679 var integer ts_nr := g_chan_nr.tn;
5680 var integer trx_nr := 0;
5681 var integer bts_nr := 0;
5682 var integer pcu_conn_id := -1;
5683
5684 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5685
5686 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005687 /* Send a second Chan Activ and expect it to be NACKed */
5688 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5689 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005690 setverdict(pass);
5691}
5692testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5693 var ConnHdlrPars pars;
5694 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005695 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005696
5697 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5698 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5699 vc_conn.done;
5700}
5701
5702/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005703private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005704 var PCUIF_Message first_info;
5705 var integer ts_nr := g_chan_nr.tn;
5706 var integer trx_nr := 0;
5707 var integer bts_nr := 0;
5708 var integer pcu_conn_id := -1;
5709 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5710
5711 /* register for the TCH/F channel number */
5712 f_rslem_register(0, chan_nr);
5713
5714 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5715
5716 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5717 "RSL CHAN ACT");
5718 setverdict(pass);
5719}
5720testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5721 var ConnHdlrPars pars;
5722 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005723 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005724
5725 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5726 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5727 vc_conn.done;
5728}
5729
5730/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005731private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005732 var PCUIF_Message first_info;
5733 var integer ts_nr := g_chan_nr.tn;
5734 var integer trx_nr := 0;
5735 var integer bts_nr := 0;
5736 var integer pcu_conn_id := -1;
5737 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5738 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5739
5740 /* register for the TCH/H channel numbers */
5741 f_rslem_register(0, chan_nr[0]);
5742 f_rslem_register(0, chan_nr[1]);
5743
5744 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5745
5746 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5747 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5748 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5749 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5750 setverdict(pass);
5751}
5752testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5753 var ConnHdlrPars pars;
5754 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005755 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005756
5757 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5758 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5759 vc_conn.done;
5760}
5761
Harald Welte9bbbfb52018-04-05 09:33:19 +02005762/***********************************************************************
5763 * IPA Style Dynamic Timeslot Support
5764 ***********************************************************************/
5765
5766private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5767runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005768 /* Expect BTS to immediately acknowledge activation as PDCH */
5769 PCU.clear;
5770 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5771 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005772 timer T_wait := 2.0;
5773 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005774 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005775 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005776 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005777 [] T_wait.timeout {
5778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5779 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5780 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005781 }
5782 /* try to activate this PDCH from the PCU point of view */
5783 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5784 /* FIXME: is there a response? */
5785
5786 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5787}
5788
5789private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5790runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005791 /* Send RSL CHAN REL (deactivate) */
5792 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5793 PCU.clear;
5794 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005795 timer T_wait := 2.0;
5796 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005797 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005798 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005799 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005800 [] T_wait.timeout {
5801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5802 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5803 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005804 }
5805 /* Emulate PCU asking BTS to deactivate PDCH */
5806 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5807 alt {
5808 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5809 setverdict(pass);
5810 }
5811 [] RSL.receive { repeat; }
5812 }
5813}
5814
5815/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005816private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005817 var PCUIF_Message first_info;
5818 var integer ts_nr := g_chan_nr.tn;
5819 var integer trx_nr := 0;
5820 var integer bts_nr := 0;
5821 var integer pcu_conn_id := -1;
5822
5823 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5824
5825 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5826 f_sleep(3.0);
5827 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5828
5829 setverdict(pass);
5830
5831}
5832testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5833 var ConnHdlrPars pars;
5834 var ConnHdlr vc_conn;
5835 f_init();
5836
5837 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5838 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5839 vc_conn.done;
5840}
5841
5842/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005843private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005844 var PCUIF_Message first_info;
5845 var integer ts_nr := g_chan_nr.tn;
5846 var integer trx_nr := 0;
5847 var integer bts_nr := 0;
5848 var integer pcu_conn_id := -1;
5849
5850 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5851
5852 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5853 "RSL CHAN ACT");
5854 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5855 "RF CHAN REL", true);
5856 setverdict(pass);
5857}
5858testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5859 var ConnHdlrPars pars;
5860 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005861 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005862
5863 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5864 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5865 vc_conn.done;
5866}
5867
5868/* 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 +07005869private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005870 var PCUIF_Message first_info;
5871 var integer ts_nr := g_chan_nr.tn;
5872 var integer trx_nr := 0;
5873 var integer bts_nr := 0;
5874 var integer pcu_conn_id := -1;
5875
5876 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5877
5878 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5879 "RSL CHAN ACT");
5880
5881 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5882 alt {
5883 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5884 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005886 }
5887 [] RSL.receive { repeat; }
5888 }
5889
5890 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5891 "RF CHAN REL", true);
5892 setverdict(pass);
5893}
5894testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5895 var ConnHdlrPars pars;
5896 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005897 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005898
5899 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5900 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5901 vc_conn.done;
5902}
5903
5904/* 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 +07005905private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005906 var PCUIF_Message first_info;
5907 var integer ts_nr := g_chan_nr.tn;
5908 var integer trx_nr := 0;
5909 var integer bts_nr := 0;
5910 var integer pcu_conn_id := -1;
5911
5912 /* register for the TCH/F channel number */
5913 f_rslem_register(0, g_chan_nr);
5914
5915 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5916
5917 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5918
5919 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5920 "RSL CHAN ACT");
5921
5922 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5923
5924 setverdict(pass);
5925}
5926testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5927 var ConnHdlrPars pars;
5928 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005929 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005930
5931 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5932 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5933 vc_conn.done;
5934}
5935
5936
Harald Welte0472ab42018-03-12 15:02:26 +01005937/***********************************************************************
5938 * LAPDm / RLL related
5939 ***********************************************************************/
5940
5941private function f_tx_lapdm(template (value) LapdmFrame l,
5942 template (value) RslLinkId link_id) runs on ConnHdlr {
5943 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005944 var template (value) SacchL1Header l1h;
5945
5946 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005947 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005948 /* Compose dummy L1 header */
5949 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5950 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 +02005951 } else {
5952 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005953 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 +01005954 }
Harald Welte0472ab42018-03-12 15:02:26 +01005955}
5956
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005957private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005958 uint3_t sapi,
5959 RslLinkId link_id,
5960 octetstring l3,
5961 boolean exp
5962}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005963private type record of RllTestCase RllTestCases;
5964private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5965 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005966 sapi := sapi,
5967 link_id := id,
5968 l3 := l3,
5969 exp := exp
5970}
5971
5972/* execute the same callback function with a set of different parameters (tcs) on a
5973 * variety of logical channels */
5974private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5975 var ConnHdlrPars pars;
5976 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005977 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005978
5979 /* test on each of the channels we have */
5980 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5981 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5982
5983 /* test each of the test cases on the current channel */
5984 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5985 pars.spec.rll := tcs[j];
5986 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5987 vc_conn := f_start_handler(fn, pars);
5988 vc_conn.done;
5989 }
5990 }
5991
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005993}
5994
5995/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5996private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5997 var RllTestCase tc := g_pars.spec.rll;
5998 timer T := 3.0;
5999
6000 f_l1_tune(L1CTL);
6001 RSL.clear;
6002
6003 /* activate the logical channel */
6004 f_est_dchan();
6005 L1CTL.clear;
6006
6007 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6008 T.start;
6009 alt {
6010 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6011 if (tc.exp) {
6012 setverdict(pass);
6013 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006015 }
6016 }
6017 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6018 if (tc.exp) {
6019 setverdict(pass);
6020 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006022 }
6023 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006024 /* We also expect to receive the measurements */
6025 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006026 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006028 }
6029 [not tc.exp] T.timeout {
6030 setverdict(pass);
6031 }
6032 }
6033
6034 f_rsl_chan_deact();
6035 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6036 f_rslem_unregister(0, g_chan_nr);
6037}
6038testcase TC_rll_est_ind() runs on test_CT {
6039 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006040 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006041 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006042 /* normal SAPI0 establishment */
6043 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006044 /* SAPI 3 doesn't support contention resolution */
6045 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6046 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6047 /* normal SAPI3 establishment on main DCCH */
6048 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6049 /* normal SAPI3 establishment on SACCH */
6050 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6051 };
6052 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6053}
6054
6055/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6056private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6057 var RllTestCase tc := g_pars.spec.rll;
6058 var L1ctlDlMessage dl;
6059 timer T := 3.0;
6060
6061 f_l1_tune(L1CTL);
6062 RSL.clear;
6063
6064 /* activate the logical channel */
6065 f_est_dchan();
6066 L1CTL.clear;
6067
6068 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6069 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6070 T.start;
6071 alt {
6072 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6073 var LapdmFrame lapdm;
6074 var octetstring l2 := dl.payload.data_ind.payload;
6075 if (dl.dl_info.link_id.c == SACCH) {
6076 /* remove L1 header */
6077 l2 := substr(l2, 2, lengthof(l2)-2);
6078 }
6079 lapdm.ab := dec_LapdmFrameAB(l2);
6080 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6081 setverdict(pass);
6082 } else {
6083 repeat;
6084 }
6085 }
6086 [] L1CTL.receive { repeat; }
6087 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006089 }
6090 }
6091
6092 f_rsl_chan_deact();
6093 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6094 f_rslem_unregister(0, g_chan_nr);
6095}
6096testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6097 var RllTestCases tcs := {
6098 /* normal SAPI3 establishment on main DCCH */
6099 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6100 };
6101 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6102}
6103testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6104 var RllTestCases tcs := {
6105 /* normal SAPI3 establishment on SACCH */
6106 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6107 }
6108 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6109}
6110
6111/* altstep to receive a LAPDm frame matching the given template */
6112private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6113 var L1ctlDlMessage dl;
6114 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6115 var LapdmFrame lapdm;
6116 var octetstring l2 := dl.payload.data_ind.payload;
6117 if (dl.dl_info.link_id.c == SACCH) {
6118 /* remove L1 header */
6119 l2 := substr(l2, 2, lengthof(l2)-2);
6120 }
6121 if (ischosen(exp.ab)) {
6122 lapdm.ab := dec_LapdmFrameAB(l2);
6123 } else if (ischosen(exp.b4)) {
6124 lapdm.b4 := dec_LapdmFrameB4(l2);
6125 } else if (ischosen(exp.bbis)) {
6126 lapdm.bbis := dec_LapdmFrameBbis(l2);
6127 }
6128 log("Rx LAPDm ", lapdm);
6129 if (match(lapdm, exp)) {
6130 setverdict(pass);
6131 } else {
6132 repeat;
6133 }
6134 }
6135 [] L1CTL.receive { repeat; }
6136}
6137private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6138 timer T := t;
6139 T.start;
6140 alt {
6141 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006143 }
6144 [] as_l1_exp_lapdm(exp);
6145 }
6146}
6147
6148/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6149private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6150 /* send SABM from MS -> BTS */
6151 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6152 /* expect RLL EST IND on Abis */
6153 alt {
6154 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6155 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6156 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006158 }
6159 [] RSL.receive { repeat; }
6160 }
6161 /* expect UA from BTS -> MS */
6162 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6163}
6164
6165/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6166private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6167 var RllTestCase tc := g_pars.spec.rll;
6168
6169 f_l1_tune(L1CTL);
6170 RSL.clear;
6171
6172 /* activate the logical channel */
6173 f_est_dchan();
6174 L1CTL.clear;
6175
6176 /* first establish the link-layer */
6177 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6178
6179 /* then send the DISC */
6180 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6181 /* ... and expect the REL IND on the RSL side */
6182 alt {
6183 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6184 setverdict(pass);
6185 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006186 /* We also expect to receive the measurements */
6187 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006188 }
6189
6190 /* release the channel */
6191 f_rsl_chan_deact();
6192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6193 f_rslem_unregister(0, g_chan_nr);
6194}
6195testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6196 var RllTestCases tcs := {
6197 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6198 };
6199 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6200}
6201
6202testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6203 var RllTestCases tcs := {
6204 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6205 };
6206 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6207}
6208testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6209 var RllTestCases tcs := {
6210 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6211 };
6212 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6213}
6214testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6215 var RllTestCases tcs := {
6216 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6217 };
6218 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6219}
6220
6221/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6222private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6223 var RllTestCase tc := g_pars.spec.rll;
6224 f_l1_tune(L1CTL);
6225 RSL.clear;
6226
6227 /* activate the logical channel */
6228 f_est_dchan();
6229 L1CTL.clear;
6230
6231 /* first establish the link-layer */
6232 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6233
6234 /* then send the REL REQ via RSL */
6235 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6236 /* ... and expect the DISC on the Um side */
6237 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006238 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006239 /* FIXME: send a UA in resposne to the DISC */
6240 }
6241 }
6242
6243 /* release the channel */
6244 f_rsl_chan_deact();
6245 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6246 f_rslem_unregister(0, g_chan_nr);
6247}
6248testcase TC_rll_rel_req() runs on test_CT {
6249 var RllTestCases tcs := {
6250 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6251 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6252 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6253 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6254 };
6255 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6256}
6257
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006258/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006259testcase TC_rll_data_req() runs on test_CT {
6260}
6261
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006262/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006263testcase TC_rll_data_ind() runs on test_CT {
6264}
6265
6266/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6267private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6268 var RllTestCase tc := g_pars.spec.rll;
6269
6270 f_l1_tune(L1CTL);
6271 RSL.clear;
6272
6273 f_est_dchan();
6274 L1CTL.clear;
6275
6276 /* Send UNITDATA REQ on RSL side */
6277 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6278 /* Expect it to arrive on the other side */
6279 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006280 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006281 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006282 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006283 }
6284
6285 /* release the channel */
6286 f_rsl_chan_deact();
6287 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6288 f_rslem_unregister(0, g_chan_nr);
6289}
6290testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6291 var octetstring l3 := f_rnd_octstring(15);
6292 var RllTestCases tcs := {
6293 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6294 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6295 };
6296 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6297}
6298testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6299 var octetstring l3 := f_rnd_octstring(19);
6300 var RllTestCases tcs := {
6301 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6302 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6303 };
6304 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6305}
6306
6307/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6308private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6309 var RllTestCase tc := g_pars.spec.rll;
6310
6311 f_l1_tune(L1CTL);
6312 RSL.clear;
6313
6314 f_est_dchan();
6315 L1CTL.clear;
6316
6317 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006318 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006319 /* Expdct RLL UNITDATA IND on RSL side */
6320 alt {
6321 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6322 setverdict(pass);
6323 }
6324 [] RSL.receive { repeat; }
6325 }
6326
6327 /* release the channel */
6328 f_rsl_chan_deact();
6329 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6330 f_rslem_unregister(0, g_chan_nr);
6331}
6332testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006333 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006334 var RllTestCases tcs := {
6335 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6336 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6337 };
6338 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6339}
6340testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6341 var octetstring l3 := f_rnd_octstring(18);
6342 var RllTestCases tcs := {
6343 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6344 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6345 };
6346 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6347}
6348
Harald Weltee613f962018-04-18 22:38:16 +02006349/***********************************************************************
6350 * Encryption Related
6351 ***********************************************************************/
6352
6353/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006354private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006355 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6356 if (link_id.c == SACCH) {
6357 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6358 } else {
6359 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6360 }
6361}
6362
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006363/* Expect (or not expect) other kinds of messages */
6364private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6365 [exp_any] RSL.receive { repeat; }
6366 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006368 }
6369}
6370
Harald Weltee613f962018-04-18 22:38:16 +02006371/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006372private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006373 RslLinkId link_id,
6374 octetstring l3,
6375 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006376 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006377) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006378 timer T := 3.0;
6379 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6380 T.start;
6381 /* Expect RLL UNITDATA IND on RSL side */
6382 alt {
6383 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6384 setverdict(pass);
6385 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006386 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006387 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006388 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006390 }
Harald Weltee613f962018-04-18 22:38:16 +02006391 }
6392}
6393
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006394/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6395private function f_data_mo(
6396 RslLinkId link_id,
6397 boolean p, uint3_t nr, uint3_t ns,
6398 octetstring l3,
6399 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006400 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006401) runs on ConnHdlr {
6402 timer T := 3.0;
6403 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6404 T.start;
6405 /* Expect RLL DATA IND on RSL side */
6406 alt {
6407 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6408 setverdict(pass);
6409 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006410 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006411 [] as_rsl_any_ind(exp_any);
6412 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006414 }
6415 }
6416}
6417
Harald Weltee613f962018-04-18 22:38:16 +02006418/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006419private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006420 f_l1_tune(L1CTL);
6421 f_est_dchan(true);
6422
6423 /* now we actually need to transmit some data both ways to check if the encryption works */
6424 var L1ctlDlMessage dl;
6425
Stefan Sperling603d98e2018-07-25 16:47:28 +02006426 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006427 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6428
6429 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6430 f_unitdata_mt(link_id, l3);
6431
6432 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6433 f_unitdata_mo(link_id, l3);
6434
6435 /* release the channel */
6436 f_rsl_chan_deact();
6437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6438 f_rslem_unregister(0, g_chan_nr);
6439}
6440testcase TC_chan_act_a51() runs on test_CT {
6441 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6442 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6443 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6444}
6445testcase TC_chan_act_a52() runs on test_CT {
6446 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6447 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6448 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6449}
6450testcase TC_chan_act_a53() runs on test_CT {
6451 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6452 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6453 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6454}
6455
Eric Wildf1827a72019-05-28 17:37:35 +02006456/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6457 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 +07006458private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006459 f_l1_tune(L1CTL);
6460 f_est_dchan(true);
6461
6462 /* now we actually need to transmit some data both ways to check if the encryption works */
6463 var L1ctlDlMessage dl;
6464
6465 var octetstring l3 := f_rnd_octstring(20);
6466 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6467
6468 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6469 f_unitdata_mt(link_id, l3);
6470
6471 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6472 f_unitdata_mo(link_id, l3);
6473
6474 var RSL_Message rsl;
6475 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6476
6477 /* modify key to break proper encryption */
6478 g_pars.encr.key := f_rnd_octstring(8);
6479 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6480 rsl.ies := rsl.ies & { ei };
6481 RSL.send(rsl);
6482
6483 timer T0 := 1.0;
6484 T0.start;
6485 /* Expect RSL MODIFY ACK */
6486 alt {
6487 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6488 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6490 }
6491 [] T0.timeout {
6492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6493 }
6494 }
6495
6496 var octetstring l3msg := f_rnd_octstring(15);
6497 timer T1 := 3.0;
6498 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6499 due to broken encryption */
6500 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6501 T1.start;
6502 alt {
6503 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6505 }
6506 [] T1.timeout {
6507 setverdict(pass);
6508 }
6509 }
6510
6511 /* release the channel */
6512 f_rsl_chan_deact();
6513 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6514 f_rslem_unregister(0, g_chan_nr);
6515}
6516testcase TC_rsl_modify_encr() runs on test_CT {
6517 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6518 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6519 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6520}
Harald Weltee613f962018-04-18 22:38:16 +02006521
6522/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006523private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006524 /* L3 payload doesn't matter, as it is passed transparently */
6525 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6526 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6527 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6528
6529 f_l1_tune(L1CTL);
6530
6531 /* first establish a dedicated channel in the clear */
6532 f_est_dchan(false);
6533
6534 /* Establish ABM */
6535 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6536
6537 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6538 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6539 /* expect the L3 to arrive still unencrypted on the MS side */
6540 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6541
6542 /* configure L1 to apply ciphering */
6543 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6544 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6545
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006546 /* send first ciphered I-frame in response and expect it on RSL */
6547 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006548
6549 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6550 * and hence enable encryption also on the downlink */
6551
6552 /* expect bi-directional communication work in encrypted mode */
6553 f_unitdata_mo(link_id, f_rnd_octstring(15));
6554 f_unitdata_mt(link_id, f_rnd_octstring(15));
6555
6556 /* release the channel */
6557 f_rsl_chan_deact();
6558 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6559 f_rslem_unregister(0, g_chan_nr);
6560}
6561testcase TC_encr_cmd_a51() runs on test_CT {
6562 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6563 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6564 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6565}
6566testcase TC_encr_cmd_a52() runs on test_CT {
6567 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6568 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6569 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6570}
6571testcase TC_encr_cmd_a53() runs on test_CT {
6572 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6573 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6574 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6575}
6576
6577private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6578 var LapdmFrame lf;
6579 var octetstring reenc;
6580
6581 /* decode the LAPDm frame */
6582 if (ischosen(exp_match.ab)) {
6583 lf.ab := dec_LapdmFrameAB(enc);
6584 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006586 }
6587
6588 /* check if decoder result matches expectation */
6589 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006591 } else {
6592 log(name, ": matched");
6593 setverdict(pass);
6594 }
6595
6596 /* test if re-encoded frame equals original input */
6597 reenc := enc_LapdmFrame(lf);
6598 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006600 } else {
6601 setverdict(pass);
6602 }
6603}
6604
6605testcase TC_lapdm_selftest() runs on test_CT {
6606 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6607 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6608 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6609 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6610 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6611 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6612 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6613}
6614
Stefan Sperling4880be42018-08-07 18:12:59 +02006615/***********************************************************************
6616 * DTX Related (see GSM 05.08, section 8.3)
6617 ***********************************************************************/
6618
6619/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006620private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006621 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6622 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6623 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6624 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6625}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006626private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006627 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6628 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6629}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006630private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006631 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6632 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6633 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6634 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6635}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006636private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006637 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6638 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6639 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6640 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6641 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6642 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6643 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6644 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6645}
6646
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006647private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006648 var L1ctlDlMessage dl;
6649 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6650 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6651 var GsmFrameNumber first_fn;
6652 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006653 var integer nfill_frames_sacch := 0;
6654 var integer nfill_frames_nonsacch := 0;
6655 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006656 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6657 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006658 const integer frame_dtx_tchf_mod := 104;
6659 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6660 * which operates in terms of blocks rather than frames. */
6661 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6662 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006663 timer T := 5.0;
6664
6665 f_l1_tune(L1CTL);
6666 RSL.clear;
6667 L1CTL.clear;
6668
6669 /* activate TCHF signalling channel */
6670 f_est_dchan(false);
6671
6672 T.start;
6673 alt {
6674 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6675 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6676 var octetstring l2 := dl.payload.data_ind.payload;
6677
6678 if (is_first_frame) {
6679 is_first_frame := false;
6680 first_fn := dl.dl_info.frame_nr;
6681 }
6682
6683 if (dl.dl_info.link_id.c == SACCH) {
6684 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6685 if (not match(l2_fill_frame_sacch, l2)) {
6686 repeat;
6687 }
6688 } else if (not match(l2_fill_frame, l2)) {
6689 repeat;
6690 }
6691
6692 if (dtxd) {
6693 if (not f_g_chan_is_tchf()) {
6694 T.stop;
6695 f_rsl_chan_deact();
6696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006697 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 +02006698 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006699 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006700 T.stop;
6701 f_rsl_chan_deact();
6702 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006703
6704 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6705 * 2 SACCH, 1 TCH/F */
6706 expected_fill_frames := 3;
6707
6708 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6709 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6710 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006712 } else {
6713 setverdict(pass);
6714 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006715 } else {
6716 if (dl.dl_info.link_id.c == SACCH) {
6717 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006718 repeat;
6719 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006720 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6721 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6722 * we should only see the subset of frames numbers which correspond to a block boundary.
6723 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6724 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6725 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6726 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6727 repeat;
6728 }
6729 }
6730 log("Received DTX TCH fill frame with bad frame number: ", fn,
6731 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6732 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6733 f_rsl_chan_deact();
6734 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006736 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006737 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006738 if (dl.dl_info.link_id.c == SACCH) {
6739 nfill_frames_sacch := nfill_frames_sacch + 1;
6740 } else {
6741 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6742 }
6743 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006744 T.stop;
6745 if (f_g_chan_is_tchf()) {
6746 /* Without DTX we can expect 25 fill frames for every 104 frames.
6747 * (24 FACCH + 1 SACCH filling) */
6748 expected_fill_frames := 25;
6749 } else if (f_g_chan_is_tchh()) {
6750 /* We can expect 2 fill frames for every 104 frames. */
6751 expected_fill_frames := 2;
6752 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6753 /* We can expect 5 fill frames for every 104 frames. */
6754 expected_fill_frames := 5;
6755 } else {
6756 f_rsl_chan_deact();
6757 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006759 }
6760
6761 f_rsl_chan_deact();
6762 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006763
6764 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006765 setverdict(pass);
6766 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006767 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6768 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006770 }
6771 } else {
6772 repeat;
6773 }
6774 }
6775 }
6776 [] L1CTL.receive { repeat; }
6777 [] T.timeout {
6778 f_rsl_chan_deact();
6779 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006781 }
6782 }
6783}
6784
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006785private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006786 f_test_l2_fill_frames(false);
6787}
6788
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006789private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006790 f_test_l2_fill_frames(true);
6791}
6792
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006793private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006794 var ConnHdlr vc_conn;
6795 var ConnHdlrPars pars;
6796 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006797 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006798 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6799 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6800 if (dtxd) {
6801 if (i >= 4) { /* DTX is only allowed on TCH/F */
6802 break;
6803 }
6804 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6805 } else {
6806 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6807 }
6808 vc_conn.done;
6809 }
6810}
6811
6812/* Verify that L2 fill frames are sent on TCH in signaling mode if
6813 * there is nothing to transmit while DTX is disabled on downlink. */
6814testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6815 f_tch_sign_l2_fill_frame(false);
6816}
6817
6818/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6819 * there is nothing to transmit while DTX is enabled on downlink. */
6820testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6821 f_tch_sign_l2_fill_frame(true);
6822}
Harald Welte0472ab42018-03-12 15:02:26 +01006823
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006824testcase TC_chopped_ipa_ping() runs on test_CT {
6825 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6826}
6827
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006828testcase TC_chopped_ipa_payload() runs on test_CT {
6829 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6830}
6831
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006832
6833/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6834 * Return value: Measurement Report to be sent (encoded octetstring). */
6835type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6836 runs on ConnHdlr return octetstring;
6837
6838private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6839runs on ConnHdlr {
6840 var L1ctlDlMessage l1_dl;
6841 var SacchL1Header l1h;
6842 var octetstring l2;
6843
6844 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6845 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6846 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6847 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6848
6849 /* Pass it to the user specified call-back function */
6850 l2 := cb.apply(l1h, num_blocks);
6851 /* Send a Measurement Report generated by the call-back */
6852 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6853 l1_dl.dl_info.link_id,
6854 l1h, l2));
6855
6856 /* Shall we keep going? */
6857 num_blocks := num_blocks - 1;
6858 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6859 if (num_blocks > 0) { repeat; }
6860 }
6861 [] L1CTL.receive { repeat; }
6862}
6863
6864private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6865runs on ConnHdlr return octetstring {
6866 /* Command the L1 to apply received parameters */
6867 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6868
6869 /* Dummy measurement report (the results are invalid) */
6870 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6871}
6872
6873private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6874runs on ConnHdlr return octetstring {
6875 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6876 setverdict(fail, "Unexpected MS Power level change: ",
6877 g_pars.l1_pars.ms_power_level, " -> ",
6878 l1h.ms_power_lvl);
6879 }
6880
6881 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6882}
6883
6884/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6885private function f_TC_ms_pwr_ctrl_constant(charstring id)
6886runs on ConnHdlr {
6887 var integer num_blocks := 8;
6888 timer T := int2float(num_blocks);
6889
6890 f_l1_tune(L1CTL);
6891 RSL.clear;
6892
6893 /* These IEs are needed for autonomous MS power control */
6894 var template (value) RSL_IE_List ies := {
6895 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6896 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6897 }),
6898 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6899 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6900 })
6901 };
6902
6903 /* Ensure that 'rx-current' equals 'rx-target' */
6904 f_trxc_fake_rssi(mp_uplink_power_target);
6905
6906 /* Establish a dedicated channel */
6907 f_est_dchan(more_ies := valueof(ies));
6908
6909 L1CTL.clear;
6910 T.start;
6911 alt {
6912 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6913 [] T.timeout {
6914 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6915 num_blocks, " were not handled");
6916 }
6917 }
6918}
6919testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6920 var ConnHdlr vc_conn;
6921 var ConnHdlrPars pars;
6922
6923 f_init();
6924
6925 /* Explicitly configure the Uplink power target (in dBm) */
6926 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6927
6928 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6929 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6930 log(testcasename(), ": starting on ", pars.chan_nr);
6931
6932 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6933 pars, trxc_comp := true);
6934 vc_conn.done;
6935 }
6936
6937 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6939}
6940
Harald Welte0472ab42018-03-12 15:02:26 +01006941/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6942/* protocol error as per 44.006 */
6943/* link layer failure (repetition of I-frame N200 times without ACK */
6944/* repetition of SABM or DISC N200 times without ACK */
6945/* receptiom of SABM in multi-frame established state */
6946
6947
Harald Welte68e495b2018-02-25 00:05:57 +01006948/* TODO Areas:
6949
6950* channel activation
6951** with BS_Power / MS_Power, bypassing power control loop
6952** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006953** with timing advance from initial activation on
6954* mode modify
6955** encryption
6956** multirate
6957* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006958** unsupported algorithm
6959* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006960* BS Power Control
6961* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006962* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006963* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006964** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006965* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006966** DATA_IND from BTS->PCU
6967** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006968
6969*/
Harald Welte70767382018-02-21 12:16:40 +01006970
6971control {
6972 execute( TC_chan_act_stress() );
6973 execute( TC_chan_act_react() );
6974 execute( TC_chan_deact_not_active() );
6975 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006976 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006977 execute( TC_sacch_filling() );
6978 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006979 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006980 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006981 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006982 execute( TC_sacch_chan_act_ho_async() );
6983 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006984 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006985 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006986 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006987 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006988 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006989 execute( TC_rach_load_idle_thresh0() );
6990 execute( TC_rach_load_idle_below_thresh() );
6991 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006992 execute( TC_meas_res_sign_tchf() );
6993 execute( TC_meas_res_sign_tchh() );
6994 execute( TC_meas_res_sign_sdcch4() );
6995 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006996 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006997 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006998 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006999 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007000 execute( TC_rsl_bs_pwr_static_ass() );
7001 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007002 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007003 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007004 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007005 execute( TC_rsl_ms_pwr_dyn_up() );
7006 execute( TC_rsl_ms_pwr_dyn_down() );
7007 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7008 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007009 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007010 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007011 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007012 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007013 execute( TC_paging_imsi_80percent() );
7014 execute( TC_paging_tmsi_80percent() );
7015 execute( TC_paging_imsi_200percent() );
7016 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007017 execute( TC_rsl_protocol_error() );
7018 execute( TC_rsl_mand_ie_error() );
7019 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007020 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007021 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007022 execute( TC_si_sched_2bis() );
7023 execute( TC_si_sched_2ter() );
7024 execute( TC_si_sched_2ter_2bis() );
7025 execute( TC_si_sched_2quater() );
7026 execute( TC_si_sched_13() );
7027 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007028 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007029 execute( TC_ipa_crcx_twice_not_active() );
7030 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007031 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007032 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007033
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007034 if (mp_pcu_socket != "") {
7035 execute( TC_pcu_act_req() );
7036 execute( TC_pcu_act_req_wrong_ts() );
7037 execute( TC_pcu_act_req_wrong_bts() );
7038 execute( TC_pcu_act_req_wrong_trx() );
7039 execute( TC_pcu_deact_req() );
7040 execute( TC_pcu_deact_req_wrong_ts() );
7041 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007042 if (mp_l1_supports_gprs) {
7043 execute( TC_pcu_data_req_pdtch() );
7044 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007045 execute( TC_pcu_data_req_wrong_bts() );
7046 execute( TC_pcu_data_req_wrong_trx() );
7047 execute( TC_pcu_data_req_wrong_ts() );
7048 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007049 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007050 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007051 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007052 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007053 execute( TC_pcu_data_req_imm_ass_pch() );
7054 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007055 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007056 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007057 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007058 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007059 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007060 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007061 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007062 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007063 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007064 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007065 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007066 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007067 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007068 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007069 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007070 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007071 execute( TC_dyn_osmo_pdch_act_deact() );
7072 execute( TC_dyn_osmo_pdch_double_act() );
7073 execute( TC_dyn_ipa_pdch_act_deact() );
7074 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7075
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007076 if (PCUIF_Types.mp_pcuif_version >= 10) {
7077 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007078 execute( TC_pcu_socket_nsvc_ipv4() );
7079 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007080 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007081 } else {
7082 log("PCU socket path not available, skipping PCU tests");
7083 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007084
Harald Welte3d04ae62018-04-04 20:29:05 +02007085 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007086 execute( TC_dyn_osmo_pdch_tchf_act() );
7087 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007088 execute( TC_dyn_ipa_pdch_tchf_act() );
7089 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007090
7091 execute( TC_rll_est_ind() );
7092 execute( TC_rll_est_req_DCCH_3() );
7093 execute( TC_rll_est_req_ACCH_3() );
7094 execute( TC_rll_rel_ind_DCCH_0() );
7095 execute( TC_rll_rel_ind_DCCH_3() );
7096 execute( TC_rll_rel_ind_ACCH_0() );
7097 execute( TC_rll_rel_ind_ACCH_3() );
7098 execute( TC_rll_rel_req() );
7099 execute( TC_rll_unit_data_req_DCCH() );
7100 execute( TC_rll_unit_data_req_ACCH() );
7101 execute( TC_rll_unit_data_ind_DCCH() );
7102 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007103
7104 execute( TC_chan_act_a51() );
7105 execute( TC_chan_act_a52() );
7106 execute( TC_chan_act_a53() );
7107 execute( TC_encr_cmd_a51() );
7108 execute( TC_encr_cmd_a52() );
7109 execute( TC_encr_cmd_a53() );
7110
Harald Welteee25aae2019-05-19 14:32:37 +02007111 execute( TC_err_rep_wrong_mdisc() );
7112 execute( TC_err_rep_wrong_msg_type() );
7113 execute( TC_err_rep_wrong_sequence() );
7114
Harald Weltee613f962018-04-18 22:38:16 +02007115 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007116
7117 execute( TC_tch_sign_l2_fill_frame() );
7118 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007119
7120 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007121 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007122
7123 execute( TC_ms_pwr_ctrl_constant() );
Harald Welte70767382018-02-21 12:16:40 +01007124}
7125
7126
7127}