blob: c73981d90034a5ef790c5fc3a9794a4ecd968778 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
87 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070088 integer mp_trx1_arfcn := 873;
89 integer mp_trx2_arfcn := 875;
90 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_tolerance_rxqual := 1;
99 integer mp_tolerance_rxlev := 3;
100 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200101 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200102 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200103 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200104 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
105 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200106 integer mp_ms_actual_ta_exp := 0;
107 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700108 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700109 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100110 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200111 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200112 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200113 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
114 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700115 /* how many transceivers do we expect to connect */
116 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700117 /* frequency hopping status */
118 boolean mp_freq_hop_enabled := false;
119 /* frequency hopping parameters */
120 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
Harald Welte629cc6b2018-03-11 17:19:05 +0100123type record of RslChannelNr ChannelNrs;
124
Harald Welte70767382018-02-21 12:16:40 +0100125type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100127 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100129 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100130 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100131 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100132
133 /* L1CTL port (for classic tests) */
134 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100135
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700136 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100139
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100141 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200142 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100143
Harald Welte883340c2018-02-28 18:59:29 +0100144 /* PCU Interface of BTS */
145 port PCUIF_CODEC_PT PCU;
146 var integer g_pcu_conn_id;
147 /* Last PCU INFO IND we received */
148 var PCUIF_Message g_pcu_last_info;
149
Harald Welte48494ca2018-02-25 16:59:50 +0100150 /* SI configuration */
151 var SystemInformationConfig si_cfg := {
152 bcch_extended := false,
153 si1_present := false,
154 si2bis_present := false,
155 si2ter_present := false,
156 si2quater_present := false,
157 si7_present := false,
158 si8_present := false,
159 si9_present := false,
160 si13_present := false,
161 si13alt_present := false,
162 si15_present := false,
163 si16_present := false,
164 si17_present := false,
165 si2n_present := false,
166 si21_present := false,
167 si22_present := false
168 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100169
170 /* all logical channels available on the BTS */
171 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100172 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200176type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100177 port L1CTL_PT L1CTL;
178
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700179 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700180 port TRXC_CODEC_PT BTS_TRXC;
181 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100182
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200183 /* port to be initialized optionally to access BSC VTY */
184 port TELNETasp_PT BSCVTY;
185
Harald Welte70767382018-02-21 12:16:40 +0100186 timer g_Tguard;
187 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
188
189 var ConnHdlrPars g_pars;
190 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100191 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200192
193 /* PCU Interface of BTS */
194 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100195}
196
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700197private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200203 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700204 timer T;
205
Harald Welte70767382018-02-21 12:16:40 +0100206 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
207 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
208
209 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
210 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
211 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
212
213 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
214 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700215
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 T.start(mp_ipa_up_timeout);
219 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
222 /* Make sure that all transceivers use unique stream ID */
223 if (trx_mask[enum2int(ev.sid)] == '1'B) {
224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
225 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
226 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 trx_mask[enum2int(ev.sid)] := '1'B;
229 trx_count := trx_count + 1;
230
231 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200234 /* This message (RF RESource INDication) is sent by the IUT itself */
235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
236 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
239 }
240 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
242 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
243 }
244
245 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
246 rfind_count := rfind_count + 1;
247 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
248 if (rfind_count < mp_transceiver_num) { repeat; }
249 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700250 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
251 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
252 [] T.timeout {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 "Timeout waiting for RSL bring up");
255 }
256 }
Harald Welte70767382018-02-21 12:16:40 +0100257}
258
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700259friend type record FreqHopPars {
260 /* Whether frequency hopping is in use */
261 boolean enabled,
262 /* Mobile Allocation Index Offset / Hopping Sequence Number */
263 MaioHsn maio_hsn,
264 /* MA bitmap to be indicated in RR Immediate Assignment */
265 MobileAllocationLV ma_map,
266 /* The actual Mobile Allocation (ARFCN list) to be used */
267 L1ctlMA ma
268};
269
Harald Welte70767382018-02-21 12:16:40 +0100270type record ConnHdlrPars {
271 RslChannelNr chan_nr,
272 RSL_IE_ChannelMode chan_mode,
273 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100274 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200275 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200276 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700277 BtsBand bts0_band optional,
278
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700279 /* Frequency hopping parameters */
280 FreqHopPars fhp
281};
Harald Welte0472ab42018-03-12 15:02:26 +0100282
283/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700284private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100285 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100286}
287
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700288private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100289 max_retrans := RACH_MAX_RETRANS_7,
290 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100291 cell_barr_access := false,
292 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100293 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100294};
295
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700296private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100297 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200298 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100299 acs := '0'B,
300 neci := true,
301 rxlev_access_min := 0
302}
303
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100305 mcc_mnc := '262F42'H,
306 lac := 42
307}
308
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700309private template (value) GPRSIndicator ts_GPRSIndicator_def := {
310 ra_colour := 0,
311 si13_pos := '0'B
312}
313
314private template (value) SI3RestOctets ts_SI3RestOctets_def
315modifies ts_SI3RestOctets := {
316 gprs_ind := {
317 presence := CSN1_H,
318 ind := ts_GPRSIndicator_def
319 }
320}
321
322private template (value) SI4RestOctets ts_SI4RestOctets_def
323modifies ts_SI4RestOctets := {
324 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700325 presence := CSN1_H,
326 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700327 }
328}
329
Harald Welte7484fc42018-02-24 14:09:45 +0100330/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100332 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100333 payload := {
334 si3 := {
335 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100336 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100337 ctrl_chan_desc := {
338 msc_r99 := true,
339 att := true,
340 bs_ag_blks_res := 1,
341 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100342 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100343 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
344 spare := '00'B,
345 bs_pa_mfrms := 0, /* 2 multiframes */
346 t3212 := 1 /* 6 minutes */
347 },
Harald Welte82ccef72018-02-25 16:17:33 +0100348 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100349 dn_ind := false,
350 pwrc := false,
351 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100352 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100353 },
Harald Weltef10153f2018-02-25 16:34:05 +0100354 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100355 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200356 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100357 }
358 }
359}
Harald Welte70767382018-02-21 12:16:40 +0100360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100362 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100363 payload := {
364 si2 := {
365 bcch_freq_list := '00000000000000000000000000000000'O,
366 ncc_permitted := '11111111'B,
367 rach_control := ts_RachCtrl_default
368 }
369 }
370}
371
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700372private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100373 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100374 payload := {
375 si4 := {
376 lai := ts_LAI_default,
377 cell_sel_par := ts_CellSelPar_default,
378 rach_control := ts_RachCtrl_default,
379 cbch_chan_desc := omit,
380 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200381 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100382 }
383 }
384}
385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100387runs on test_CT {
388 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700389 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100390}
391
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700392private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100393runs on test_CT {
394 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
395 log("Setting ", rsl_si_type, ": ", si_dec);
396 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
397}
398
Harald Welte505cf9b2018-09-15 17:47:23 +0300399friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100400 map(self:BTSVTY, system:BTSVTY);
401 f_vty_set_prompts(BTSVTY);
402 f_vty_transceive(BTSVTY, "enable");
403}
404
Harald Welte505cf9b2018-09-15 17:47:23 +0300405friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200406 map(self:BSCVTY, system:BSCVTY);
407 f_vty_set_prompts(BSCVTY, "OsmoBSC");
408 f_vty_transceive(BSCVTY, "enable");
409}
410
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200411friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
412 map(self:BSCVTY, system:BSCVTY);
413 f_vty_set_prompts(BSCVTY, "OsmoBSC");
414 f_vty_transceive(BSCVTY, "enable");
415}
416
Harald Welte883340c2018-02-28 18:59:29 +0100417/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200418private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
419 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100420 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200421 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
422 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100423 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200424 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100426 }
427}
428
Harald Weltef26de0b2018-04-04 20:28:05 +0200429private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
430 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100431 timer T := 2.0;
432 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200434 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100435 return;
436 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200437 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100438
439 T.start;
440 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200441 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100442 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100444 }
445 }
446}
447
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700448private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
449 out integer trxc_conn_id) {
450 var Result res;
451
452 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
453 "", -1, -1, { udp := {} }, {});
454 if (not ispresent(res.connId)) {
455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
456 "Could not connect to the control (TRXC) interface " &
457 "of FakeTRX, check your configuration");
458 }
459 trxc_conn_id := res.connId;
460}
461
Harald Welte70767382018-02-21 12:16:40 +0100462/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700463friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200464 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100465 g_AllChannels := {
466 /* TS 1..4: TCH/F */
467 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
468 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
469 /* TS 5: TCH/H */
470 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
471 /* TS 0: SDCCH/4 */
472 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
473 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
474 /* TS 6: SDCCH/8 */
475 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
476 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
477 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
478 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
479 };
480
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200481 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700482 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200483 g_AllChanTypes := {
484 /* TS 1..4: TCH/F */
485 valueof(ts_RslChanNr_Bm(1)),
486 /* TS 5: TCH/H */
487 valueof(ts_RslChanNr_Lm(5,1)),
488 /* TS 0: SDCCH/4 */
489 valueof(ts_RslChanNr_SDCCH4(0,2)),
490 /* TS 6: SDCCH/8 */
491 valueof(ts_RslChanNr_SDCCH8(6,4))
492 };
493 } else {
494 g_AllChanTypes := {
495 /* TS 1..4: TCH/F */
496 valueof(ts_RslChanNr_Bm(1)),
497 /* TS 0: SDCCH/4 */
498 valueof(ts_RslChanNr_SDCCH4(0,2)),
499 /* TS 6: SDCCH/8 */
500 valueof(ts_RslChanNr_SDCCH8(6,4))
501 };
502 }
Harald Welte70767382018-02-21 12:16:40 +0100503 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100504 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100505 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200506 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100507
508 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100509 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
510 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
512 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100513
Harald Weltef26de0b2018-04-04 20:28:05 +0200514 map(self:PCU, system:PCU);
515 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100516
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700517 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100518 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700519
520 /* Init TRXC interface to FakeTRX */
521 map(self:BTS_TRXC, system:BTS_TRXC);
522 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
523
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700524 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700526 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700527 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
528 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100529 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200530
531 /* Wait some extra time to make sure the BTS emits a stable carrier.
532 * (this is only relevant when running the tests with a physical BTS.) */
533 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100534}
535
Harald Welte68e495b2018-02-25 00:05:57 +0100536/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700537friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100538 map(self:L1CTL, system:L1CTL);
539 f_connect_reset(L1CTL);
540}
541
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700542private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100543
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700544private type record length(8) of FreqHopGroups FreqHopConfig;
545
546private type record of FreqHopGroup FreqHopGroups;
547private type record FreqHopGroup {
548 uint6_t hsn,
549 FreqHopGroupItems trx_maio
550};
551
552private type record of FreqHopGroupItem FreqHopGroupItems;
553private type record FreqHopGroupItem {
554 uint8_t trx_nr,
555 uint6_t maio
556};
557
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700558friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
559 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700562 var integer i, j;
563
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700564 fhp.enabled := false;
565
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (i := 0; i < lengthof(groups); i := i + 1) {
567 var FreqHopGroup g := groups[i];
568 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
569 var FreqHopGroupItem gi := g.trx_maio[j];
570 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700571 fhp.maio_hsn.maio := gi.maio;
572 fhp.maio_hsn.hsn := g.hsn;
573 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700574 break;
575 }
576 }
577
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700578 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700579 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700580 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
581 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
582 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700583
584 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
586 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700587 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
588 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700589 }
590
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700591 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700592 break; /* We're done */
593 }
594 }
595}
596
Harald Welte70767382018-02-21 12:16:40 +0100597/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700598friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
599 boolean pcu_comp := false,
600 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100601runs on test_CT return ConnHdlr {
602 var charstring id := testcasename();
603 var ConnHdlr vc_conn;
604
605 vc_conn := ConnHdlr.create(id);
606 /* connect to RSL Emulation main component */
607 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
608 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700609
610 /* The ConnHdlr component may want to talk to some ports directly,
611 * so we disconnect it from the test_CT and connect it to the component.
612 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200614 unmap(self:PCU, system:PCU);
615 map(vc_conn:PCU, system:PCU);
616 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700617 if (trxc_comp) {
618 unmap(self:BTS_TRXC, system:BTS_TRXC);
619 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
620 }
Harald Welte70767382018-02-21 12:16:40 +0100621
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700622 /* Obtain frequency hopping parameters for a given timeslot */
623 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 }
626
Harald Welte70767382018-02-21 12:16:40 +0100627 vc_conn.start(f_handler_init(fn, id, pars));
628 return vc_conn;
629}
630
Harald Welte70767382018-02-21 12:16:40 +0100631private altstep as_Tguard() runs on ConnHdlr {
632 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100634 }
635}
636
Harald Welte990a3612019-05-27 14:02:13 +0200637friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
638 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100639}
640
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700641private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100642 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700643 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100644}
645
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700646private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100647 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700648 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* first function started in ConnHdlr component */
652private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
653runs on ConnHdlr {
654 g_pars := pars;
655 g_chan_nr := pars.chan_nr;
656
657 map(self:L1CTL, system:L1CTL);
658 f_connect_reset(L1CTL);
659
Harald Welted48c0c72019-06-05 10:01:15 +0200660 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700661 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100662 }
Harald Welte70767382018-02-21 12:16:40 +0100663
664 g_Tguard.start(pars.t_guard);
665 activate(as_Tguard());
666
667 f_rslem_register(0, pars.chan_nr);
668
669 /* call the user-supplied test case function */
670 fn.apply(id);
671}
672
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700673private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
674 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200675runs on ConnHdlr return RSL_Message {
676 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100677 timer T := 3.0;
678 RSL.send(tx);
679 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100680 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200681 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100682 T.stop;
683 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100684 }
Harald Welte1eba3742018-02-25 12:48:14 +0100685 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100687 }
Harald Welte21240e62018-03-11 21:43:35 +0100688 [not ignore_other] as_l1_sacch();
689 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700690 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700691 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100692 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welte21240e62018-03-11 21:43:35 +0100695 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100696 }
Harald Welteb1726c92018-03-30 11:56:38 +0200697 return rx;
698}
699
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700700friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
701 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200702runs on ConnHdlr {
703 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100704}
705
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700706friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
707 boolean encr_enable := false,
708 RSL_IE_List more_ies := {},
709 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
710runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200711 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200712 if (encr_enable) {
713 /* append encryption related IEs, if requested */
714 var RSL_IE_EncryptionInfo encr_info;
715 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
716 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
717encr_info})) };
718 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200719 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200720 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100721}
722
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700723friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100724 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100725 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100726}
727
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700728/* Default Mobile Allocation to be used for frequency hopping */
729private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
730 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
731
Harald Welte2f2b2b72019-05-31 22:24:57 +0200732friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100733 template RSL_IE_ChannelMode chan_mode,
734 float t_guard := 20.0) := {
735 chan_nr := valueof(chan_nr),
736 chan_mode := valueof(chan_mode),
737 t_guard := t_guard,
738 l1_pars := {
739 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100740 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100741 meas_ul := {
742 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200743 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100744 rxqual := 0
745 },
746 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200747 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100748 rxqual := 0
749 }
750 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200751 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100752 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200753 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200754 ms_actual_ta := mp_ms_actual_ta_exp,
755 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100756 },
Harald Weltee613f962018-04-18 22:38:16 +0200757 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200758 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700759 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700760 fhp := {
761 enabled := false,
762 maio_hsn := ts_HsnMaio(0, 0),
763 ma_map := c_MA_null,
764 ma := l1ctl_ma_def
765 }
Harald Welte70767382018-02-21 12:16:40 +0100766}
767
Harald Welte93640c62018-02-25 16:59:33 +0100768/***********************************************************************
769 * Channel Activation / Deactivation
770 ***********************************************************************/
771
Harald Welte70767382018-02-21 12:16:40 +0100772/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700773private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100774 for (var integer i := 0; i < 500; i := i+1) {
775 f_rsl_chan_act(g_pars.chan_mode);
776 f_rsl_chan_deact();
777 }
778 setverdict(pass);
779}
780testcase TC_chan_act_stress() runs on test_CT {
781 var ConnHdlr vc_conn;
782 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200783 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100784 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
785 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100787}
788
789/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700790private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100791 f_rsl_chan_act(g_pars.chan_mode);
792 /* attempt to activate the same lchan again -> expect reject */
793 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
794 alt {
795 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100797 }
798 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
799 setverdict(pass);
800 }
801 }
802 f_rsl_chan_deact();
803}
804testcase TC_chan_act_react() runs on test_CT {
805 var ConnHdlr vc_conn;
806 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100807 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100808 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
809 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100811}
812
813/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700814private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100815 timer T := 3.0;
816 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
817 T.start;
818 alt {
819 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
820 setverdict(pass);
821 }
822 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100824 }
825 }
826}
827testcase TC_chan_deact_not_active() runs on test_CT {
828 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100829 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100830 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
831 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100833}
834
835/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700836private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100837 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
838 alt {
839 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100841 }
842 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
843 setverdict(pass);
844 }
845 }
846}
847private type record WrongChanNrCase {
848 RslChannelNr chan_nr,
849 charstring description
850}
851private type record of WrongChanNrCase WrongChanNrCases;
852private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
853 chan_nr := chan_nr,
854 description := desc
855}
856
857testcase TC_chan_act_wrong_nr() runs on test_CT {
858 var ConnHdlr vc_conn;
859 var ConnHdlrPars pars;
860
Harald Welte294b0a22018-03-10 23:26:48 +0100861 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100862
863 var WrongChanNrCases wrong := {
864 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
866 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
867 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
868 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
869 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
870 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
871 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
872 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
873 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
874 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
875 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
876 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
877 };
878
879 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
880 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
881 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
882 vc_conn.done;
883 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100885}
886
Harald Weltee613f962018-04-18 22:38:16 +0200887/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200888friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200889 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200890 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200891
892 /* test on each of the channels we have */
893 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
894 pars.chan_nr := valueof(g_AllChanTypes[i]);
895
896 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
897 vc_conn := f_start_handler(fn, pars);
898 vc_conn.done;
899 }
900
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200902}
903
Harald Welte93640c62018-02-25 16:59:33 +0100904/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100905 * SACCH handling
906 ***********************************************************************/
907
908private function f_exp_sacch(boolean exp) runs on ConnHdlr {
909 timer T_sacch := 3.0;
910 T_sacch.start;
911 alt {
912 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100914 }
915 [not exp] T_sacch.timeout {
916 setverdict(pass);
917 }
918 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
919 setverdict(pass);
920 }
921 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100923 }
924 [] L1CTL.receive { repeat; }
925 [] RSL.receive { repeat; }
926 }
927}
928
929/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
930private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
931 f_l1_tune(L1CTL);
932 RSL.clear;
933
934 /* activate the logical channel */
935 f_est_dchan();
936 L1CTL.clear;
937
938 /* check that SACCH actually are received as expected */
939 f_exp_sacch(true);
940
941 /* deactivate SACCH on the logical channel */
942 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
943 f_sleep(1.0);
944 L1CTL.clear;
945
946 /* check that no SACCH are received anymore */
947 f_exp_sacch(false);
948
949 /* release the channel */
950 f_rsl_chan_deact();
951 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
952}
953testcase TC_deact_sacch() runs on test_CT {
954 var ConnHdlr vc_conn;
955 var ConnHdlrPars pars;
956 f_init();
957 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
958 //for (var integer i := 0; i < 1; i := i+1) {
959 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
960 log(testcasename(), ": Starting for ", g_AllChannels[i]);
961 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
962 vc_conn.done;
963 }
964 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100966}
967
Harald Welte55700662018-03-12 13:15:43 +0100968/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100969private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
970 var L1ctlDlMessage dl;
971 /* check that the specified SI5 value is actually sent */
972 timer T_sacch := 3.0;
973 L1CTL.clear;
974 T_sacch.start;
975 alt {
976 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
977 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
978 if (match(l3, l3_exp)) {
979 setverdict(pass);
980 } else {
981 repeat;
982 }
983 }
984 [] L1CTL.receive { repeat; }
985 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100987 }
988 }
989}
990
Harald Welte55700662018-03-12 13:15:43 +0100991/* verify that given SACCH payload is not present */
992private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
993 var L1ctlDlMessage dl;
994 /* check that the specified SI5 value is actually sent */
995 timer T_sacch := 3.0;
996 L1CTL.clear;
997 T_sacch.start;
998 alt {
999 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1000 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1001 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001003 } else {
1004 repeat;
1005 }
1006 }
1007 [] L1CTL.receive { repeat; }
1008 [] T_sacch.timeout {
1009 setverdict(pass);
1010 }
1011 }
1012}
1013
Harald Welte629cc6b2018-03-11 17:19:05 +01001014/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001015private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1016 /* Set a known default SACCH filling for SI5 */
1017 var octetstring si5 := f_rnd_octstring(19);
1018 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1019
1020 f_l1_tune(L1CTL);
1021 RSL.clear;
1022
1023 /* activate the logical channel */
1024 f_est_dchan();
1025
1026 /* check that the specified SI5 value is actually sent */
1027 f_sacch_present(si5);
1028
1029 /* release the channel */
1030 RSL.clear;
1031 f_rsl_chan_deact();
1032 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1033}
1034testcase TC_sacch_filling() runs on test_CT {
1035 var ConnHdlr vc_conn;
1036 var ConnHdlrPars pars;
1037 f_init();
1038 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1039 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1040 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1041 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1042 vc_conn.done;
1043 }
1044 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001046}
1047
Harald Welte629cc6b2018-03-11 17:19:05 +01001048/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001049private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1050 /* Set a known default SACCH filling for SI5 */
1051 var octetstring si5 := f_rnd_octstring(19);
1052 var octetstring si5_diff := f_rnd_octstring(19);
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 log("Activating channel, expecting standard SI5");
1059 /* activate the logical channel */
1060 f_est_dchan();
1061 /* check that the specified SI5 value is actually sent */
1062 f_sacch_present(si5);
1063
1064 /* set channel-specific different SI5 */
1065 log("Setting channel specific SACCH INFO, expecting it");
1066 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1067 /* check that the specified lchan-specific value is now used */
1068 f_sacch_present(si5_diff);
1069
1070 /* deactivate the channel and re-activate it, this should result in default SI5 */
1071 log("De-activating and re-activating channel, expecting standard SI5");
1072 f_rsl_chan_deact();
1073 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1074 /* Verify that the TRX-wide default SACCH filling is present again */
1075 f_sacch_present(si5);
1076
1077 /* release the channel */
1078 RSL.clear;
1079 f_rsl_chan_deact();
1080 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1081}
1082testcase TC_sacch_info_mod() runs on test_CT {
1083 var ConnHdlr vc_conn;
1084 var ConnHdlrPars pars;
1085 f_init();
1086 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1087 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1088 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1089 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1090 vc_conn.done;
1091 }
1092 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001094}
1095
Harald Welte075d84c2018-03-12 13:07:24 +01001096/* Test SACCH scheduling of multiple different SI message types */
1097private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1098 var octetstring si5 := f_rnd_octstring(19);
1099 var octetstring si5bis := f_rnd_octstring(19);
1100 var octetstring si5ter := f_rnd_octstring(19);
1101 var octetstring si6 := f_rnd_octstring(19);
1102
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1106 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1107
1108 f_l1_tune(L1CTL);
1109 RSL.clear;
1110
1111 /* activate the logical channel */
1112 f_est_dchan();
1113 L1CTL.clear;
1114
1115 /* check that SACCH actually are received as expected */
1116 f_sacch_present(si5);
1117 f_sacch_present(si5bis);
1118 f_sacch_present(si5ter);
1119 f_sacch_present(si6);
1120
1121 /* release the channel */
1122 f_rsl_chan_deact();
1123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1124}
1125testcase TC_sacch_multi() runs on test_CT {
1126 var ConnHdlr vc_conn;
1127 var ConnHdlrPars pars;
1128 f_init();
1129 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1130 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1131 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1132 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1133 vc_conn.done;
1134 }
1135 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001137}
1138
Harald Welte55700662018-03-12 13:15:43 +01001139/* Test if SACH information is modified as expected */
1140private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1141 var octetstring si5 := f_rnd_octstring(19);
1142 var octetstring si6 := f_rnd_octstring(19);
1143
1144 /* First, configure both SI5 and SI6 to be transmitted */
1145 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1146 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1147
1148 f_l1_tune(L1CTL);
1149 RSL.clear;
1150
1151 /* activate the logical channel */
1152 f_est_dchan();
1153 L1CTL.clear;
1154
1155 /* check that SACCH actually are received as expected */
1156 f_sacch_present(si5);
1157 f_sacch_present(si6);
1158
1159 /* disable SI6 */
1160 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1161
1162 /* check that SI5 is still transmitted */
1163 f_sacch_present(si5);
1164 /* check if SI6 is now gone */
1165 f_sacch_missing(si6);
1166
1167 /* release the channel */
1168 f_rsl_chan_deact();
1169 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1170}
1171testcase TC_sacch_multi_chg() runs on test_CT {
1172 var ConnHdlr vc_conn;
1173 var ConnHdlrPars pars;
1174 f_init();
1175 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1176 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1177 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1178 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1179 vc_conn.done;
1180 }
1181 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001183}
1184
Harald Weltec8d363c2019-05-19 20:36:48 +02001185/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1186private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1187 var octetstring si5 := f_rnd_octstring(19);
1188 var octetstring si6 := f_rnd_octstring(19);
1189 var octetstring si5_specific := f_rnd_octstring(19);
1190 var octetstring si6_specific := f_rnd_octstring(19);
1191
1192 /* First, configure both SI5 and SI6 to be transmitted */
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1194 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* activate channel with different SACCH filling */
1200 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1201 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1202 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1203 }));
1204 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1205 RSL_IE_Body:{sacch_info := sacch_info})) };
1206 f_est_dchan(more_ies := addl_ies);
1207
1208 /* check that SACCH actually are received as expected */
1209 f_sacch_present(si5_specific);
1210 f_sacch_present(si6_specific);
1211
1212 /* release the channel */
1213 f_rsl_chan_deact();
1214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1215}
1216testcase TC_sacch_chan_act() runs on test_CT {
1217 var ConnHdlr vc_conn;
1218 var ConnHdlrPars pars;
1219 f_init();
1220
1221 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1222 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1223 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1224 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1225 vc_conn.done;
1226 }
1227 /* TODO: do the above in parallel, rather than sequentially? */
1228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1229}
1230
Harald Welte8b01c792019-05-19 22:51:25 +02001231/* verify that SACCH DL transmission is started only if MS power IE present
1232 * see section 4.1.3 of 3GPP TS 48.058 */
1233private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1234 var octetstring si5 := f_rnd_octstring(19);
1235
1236 f_l1_tune(L1CTL);
1237 RSL.clear;
1238
1239 /* Step 1: Activate ASYNC HO channel without MS power IE */
1240
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001241 var integer ho_ref := oct2int(f_rnd_octstring(1));
1242 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1243 RSL_IE_Body:{ handover_ref := ho_ref }));
1244 var RSL_IE_List addl_ies := {
1245 ho_ref_ie
1246 };
1247
Harald Welte8b01c792019-05-19 22:51:25 +02001248 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001249 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001250 /* don't perform immediate assignment here, as we're testing non-IA case */
1251 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001252 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001253
1254 /* Verify that no DL SACCH is being received */
1255 f_sacch_missing(?);
1256
1257 f_rsl_chan_deact();
1258 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1259
1260
1261 /* Step 2: Activate ASYNC HO channel with MS power IE */
1262
1263 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001264 addl_ies := {
1265 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001266 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1267 };
1268 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1269 /* don't perform immediate assignment here, as we're testing non-IA case */
1270 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001271 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001272
1273 /* Verify that DL SACCH is being received */
1274 f_sacch_present(si5);
1275
1276 f_rsl_chan_deact();
1277 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1278}
1279testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1280 var ConnHdlr vc_conn;
1281 var ConnHdlrPars pars;
1282 f_init();
1283
1284 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1285 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1286 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1287 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1288 vc_conn.done;
1289 }
1290 /* TODO: do the above in parallel, rather than sequentially? */
1291 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1292}
1293
1294/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1295 * see section 4.1.4 of 3GPP TS 48.058 */
1296private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1297 var octetstring si5 := f_rnd_octstring(19);
1298 var RSL_IE_List addl_ies;
1299
1300 f_l1_tune(L1CTL);
1301 RSL.clear;
1302
1303 /* Step 1: Activate SYNC HO channel without MS power IE */
1304
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001305 var integer ho_ref := oct2int(f_rnd_octstring(1));
1306 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1307 RSL_IE_Body:{ handover_ref := ho_ref }));
1308 addl_ies := {
1309 ho_ref_ie
1310 };
1311
Harald Welte8b01c792019-05-19 22:51:25 +02001312 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001313 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001314 /* 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 2a: Activate SYNC HO channel with only MS power IE */
1326
1327 /* Activate channel on BTS side */
1328 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001329 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001330 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1331 };
1332 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1333 /* don't perform immediate assignment here, as we're testing non-IA case */
1334 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001335 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001336
1337 /* Verify that no DL SACCH is being received */
1338 f_sacch_missing(?);
1339
1340 f_rsl_chan_deact();
1341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1342
1343
1344 /* Step 2b: Activate SYNC HO channel with TA IE */
1345
1346 /* Activate channel on BTS side */
1347 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001348 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001349 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1350 };
1351 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1352 /* don't perform immediate assignment here, as we're testing non-IA case */
1353 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001354 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001355
1356 /* Verify that no DL SACCH is being received */
1357 f_sacch_missing(?);
1358
1359 f_rsl_chan_deact();
1360 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1361
1362
1363 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1364
1365 /* Activate channel on BTS side */
1366 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001367 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001368 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1369 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1370 };
1371 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1372 /* don't perform immediate assignment here, as we're testing non-IA case */
1373 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001374 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001375
1376 /* Verify that DL SACCH is being received */
1377 f_sacch_present(si5);
1378
1379 f_rsl_chan_deact();
1380 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1381}
1382testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1383 var ConnHdlr vc_conn;
1384 var ConnHdlrPars pars;
1385 f_init();
1386
1387 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1388 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1389 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1390 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1391 vc_conn.done;
1392 }
1393 /* TODO: do the above in parallel, rather than sequentially? */
1394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1395}
Harald Welte629cc6b2018-03-11 17:19:05 +01001396
1397
1398/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001399 * RACH Handling
1400 ***********************************************************************/
1401
Harald Welte8c24c2b2018-02-26 08:31:31 +01001402/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001403private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001404 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001406 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001407
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001409 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001410 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001411 var OCT1 ra := f_rnd_ra_emerg();
1412 if (emerg == true) {
1413 ra := f_rnd_ra_emerg();
1414 } else {
1415 ra := f_rnd_ra_cs();
1416 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1418 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001420 }
1421 fn_last := fn;
1422
1423 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001424 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001425 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001426 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001427 T.stop;
1428 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001429 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001431 }
1432 [] RSL_CCHAN.receive { repeat; }
1433 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001434 test_failed := true;
1435 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001436 }
1437 }
1438 }
Maxba06feb2019-03-05 10:52:46 +01001439 if (test_failed) {
1440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001441 }
Maxba06feb2019-03-05 10:52:46 +01001442 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001444}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001445
Philipp Maier16ade782020-07-08 21:36:00 +02001446/* Normal variant */
1447testcase TC_rach_content() runs on test_CT {
1448 f_TC_rach_content(emerg := false);
1449}
1450
1451/* Emergency call variant */
1452testcase TC_rach_content_emerg() runs on test_CT {
1453 f_TC_rach_content(emerg := true);
1454}
1455
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1457testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001458 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001460 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001461 f_l1_tune(L1CTL);
1462
1463 var GsmFrameNumber fn_last := 0;
1464 for (var integer i := 0; i < 1000; i := i+1) {
1465 var OCT1 ra := f_rnd_ra_cs();
1466 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1467 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 }
1470 fn_last := fn;
1471 }
1472 var integer rsl_chrqd := 0;
1473 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001474 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001475 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001476 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001477 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001478 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001479 repeat;
1480 }
1481 [] RSL_CCHAN.receive { repeat; }
1482 [] T.timeout { }
1483 }
1484 if (rsl_chrqd == 1000) {
1485 setverdict(pass);
1486 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001488 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001490}
1491
Harald Welte3453ab42019-05-24 21:19:58 +02001492private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1493 var charstring bts_str := "bts " & int2str(bts_nr);
1494 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1495}
1496
1497/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1498private template integer tr_rach_slots_per_interval := (90 .. 130);
1499
1500/* Expect 0 RACH load on an idle BTS that has just started up */
1501testcase TC_rach_load_idle_thresh0() runs on test_CT {
1502 var ASP_RSL_Unitdata rx_ud;
1503
1504 f_init_vty_bsc();
1505 /* send load indications even at 0% load */
1506 f_vty_load_ind_thresh(0);
1507 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1508 f_sleep(2.0);
1509
1510 f_init();
1511
Harald Weltee37f9a52020-10-11 20:45:23 +02001512 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1513 alt {
1514 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1515 [] RSL_CCHAN.receive { repeat }
1516 }
1517
Harald Welte3453ab42019-05-24 21:19:58 +02001518 timer T := 5.0;
1519 T.start;
1520 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001521 [] 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 +02001522 setverdict(pass);
1523 repeat;
1524 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001525 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001526 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1527 repeat;
1528 }
1529 [] RSL_CCHAN.receive {
1530 repeat;
1531 }
1532 [] T.timeout { }
1533 }
1534
1535 f_vty_load_ind_thresh(10);
1536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1537}
1538
1539/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1540testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1541 var ASP_RSL_Unitdata rx_ud;
1542
1543 f_init_vty_bsc();
1544 f_init();
1545
1546 timer T := 5.0;
1547 T.start;
1548 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001549 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001550 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1551 repeat;
1552 }
1553 [] RSL_CCHAN.receive {
1554 repeat;
1555 }
1556 [] T.timeout {
1557 setverdict(pass);
1558 }
1559 }
1560
1561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1562}
1563
1564/* Expect 0 RACH load on an idle BTS that has just started up */
1565testcase TC_rach_load_count() runs on test_CT {
1566 var ASP_RSL_Unitdata rx_ud;
1567 var integer load_access_count := 0;
1568
1569 f_init_vty_bsc();
1570 /* send load indications even at 0% load */
1571 f_vty_load_ind_thresh(0);
1572 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1573 f_sleep(2.0);
1574 f_init();
1575
1576 f_init_l1ctl();
1577 f_sleep(1.0);
1578 f_l1_tune(L1CTL);
1579
Harald Welte52ae1682020-10-11 20:45:55 +02001580 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1581 alt {
1582 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1583 [] RSL_CCHAN.receive { repeat }
1584 }
1585
Harald Welte3453ab42019-05-24 21:19:58 +02001586 var GsmFrameNumber fn_last := 0;
1587 for (var integer i := 0; i < 1000; i := i+1) {
1588 var OCT1 ra := f_rnd_ra_cs();
1589 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1590 if (fn == fn_last) {
1591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1592 }
1593 fn_last := fn;
1594 }
1595
1596 timer T := 5.0;
1597 T.start;
1598 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001599 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001600 -> value rx_ud {
1601 var RSL_IE_Body ie;
1602 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1603 load_access_count := load_access_count + ie.rach_load.access_count;
1604 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1605 setverdict(fail, "Access count cannot be < Busy count");
1606 }
1607 repeat;
1608 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001609 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001610 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1611 repeat;
1612 }
1613 [] RSL_CCHAN.receive {
1614 repeat;
1615 }
1616 [] T.timeout { }
1617 }
1618 if (load_access_count == 1000) {
1619 setverdict(pass);
1620 } else {
1621 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1622 }
1623
1624 f_vty_load_ind_thresh(10);
1625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1626}
1627
Harald Welte54a2a2d2018-02-26 09:14:05 +01001628private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001629 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001630 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001631 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001632 f_sleep(0.5);
1633
1634 /* Transmit RACH request + wait for confirmation */
1635 var OCT1 ra := f_rnd_ra_cs();
1636 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1637
1638 /* Check for expected result */
1639 timer T := 1.5;
1640 T.start;
1641 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001642 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001643 setverdict(pass);
1644 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001645 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001647 }
1648 [] RSL_CCHAN.receive { repeat; }
1649 [not expect_pass] T.timeout {
1650 setverdict(pass);
1651 }
1652 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001654 }
1655 }
1656}
1657
1658/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1659testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001660 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001661 f_init_l1ctl();
1662 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001663 f_sleep(1.0);
1664
1665 /* default max-ta is 63 (full range of GSM timing advance */
1666
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001667 /* We allow early arrival up to 2 symbols */
1668 f_rach_toffs(-1*256, true);
1669 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001670 f_rach_toffs(-10*256, false);
1671
1672 /* 0 / 32 / 63 bits is legal / permitted */
1673 f_rach_toffs(0, true);
1674 f_rach_toffs(32*256, true);
1675 f_rach_toffs(63*256, true);
1676
1677 /* more than 63 bits is not legal / permitted */
1678 f_rach_toffs(64*256, false);
1679 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001681}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001682
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001683private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001684 var GsmFrameNumber fn;
1685 var RSL_Message rm;
1686
1687 f_l1_tune(L1CTL);
1688 RSL.clear;
1689
1690 /* Generate a random Handover Reference */
1691 var integer ho_ref := oct2int(f_rnd_octstring(1));
1692
1693 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1694 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1695 RSL_IE_Body:{ handover_ref := ho_ref }));
1696
1697 /* Activate a channel on the BTS side (no encryption) */
1698 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1699 act_type := t_RSL_IE_ActType_HO_SYNC);
1700
1701 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1702 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001703 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001704
1705 /* Send handover Access Burst */
1706 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1707
1708 /* TODO: test mismatching Handover Reference, and missing IE */
1709
1710 /* Wait for handover detection */
1711 timer T := 3.0;
1712 T.start;
1713 alt {
1714 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1715 log("Handover RACH has been detected: ", rm);
1716 setverdict(pass);
1717 }
1718 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1720 log2str("RSL_CHAN_RQD was not expected: ", rm));
1721 }
1722 [] RSL.receive { repeat; }
1723 [] T.timeout {
1724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1725 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1726 }
1727 }
1728
1729 /* Release the channel */
1730 f_rsl_chan_deact();
1731 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1732}
1733
1734/* Test handover RACH detection */
1735testcase TC_ho_rach() runs on test_CT {
1736 var ConnHdlrPars pars;
1737 var ConnHdlr vc_conn;
1738
1739 f_init();
1740
1741 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1742 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1743 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1744 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1745 vc_conn.done;
1746 }
1747
1748 /* TODO: do the above in parallel, rather than sequentially? */
1749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1750}
1751
Harald Welte93640c62018-02-25 16:59:33 +01001752/***********************************************************************
1753 * Measurement Processing / Reporting
1754 ***********************************************************************/
1755
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001756private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001757 spare := '0'B,
1758 lpd := 0,
1759 sapi := sapi,
1760 c_r := c_r,
1761 ea := true
1762}
1763
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001764private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001765 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001766 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001767 len := 0, /* overwritten */
1768 m := false,
1769 el := 1,
1770 payload := pl
1771}
1772
1773/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001774private altstep as_l1_sacch() 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_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001777 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001778 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 +01001779 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001780 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001781
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001782 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1783 g_pars.l1_pars.ms_power_level, false,
1784 g_pars.l1_pars.ms_actual_ta);
1785
1786 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1787 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1788
1789 log("Sending Measurement Report: ", l1h, l2);
1790 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001791 repeat;
1792 }
1793}
1794
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001795private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001796 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001797 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001798 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1799 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001800 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1801 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001802 repeat;
1803 }
1804}
1805
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001806private altstep as_l1_tch_loop() runs on ConnHdlr {
1807 var L1ctlDlMessage l1_dl;
1808 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1809 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001810
1811 /* occasionaly inject FACCH frames into the uplink */
1812 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1813 var octetstring pl := '010301'O;
1814 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1815 f_pad_oct(pl, 23, '2B'O)));
1816 } else {
1817 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1818 l1_dl.payload.traffic_ind.data));
1819 }
1820
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001821 repeat;
1822 }
1823}
1824
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001825private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001826 uint6_t rxlev,
1827 uint3_t rxqual
1828}
1829
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001830private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001831 MeasElem full,
1832 MeasElem sub
1833}
1834
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001835private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001836 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001837 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001838 MeasElemFS meas_ul,
1839 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001840 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001841 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001842 uint8_t ms_actual_ta,
1843 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001844}
1845
1846/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1847private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1848 return 63 + (toffs256s/256);
1849}
1850
Harald Welted5684392018-03-10 18:22:04 +01001851private function f_max(integer a, integer b) return integer {
1852 if (a > b) {
1853 return a;
1854 } else {
1855 return b;
1856 }
1857}
1858
1859private function f_min(integer a, integer b) return integer {
1860 if (a < b) {
1861 return a;
1862 } else {
1863 return b;
1864 }
1865}
1866
1867/* compute negative tolerance val-tolerance, ensure >= min */
1868private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1869 val := val - tolerance;
1870 return f_max(val, min);
1871}
1872
1873/* compute positive tolerance val+tolerance, ensure <= max */
1874private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1875 val := val + tolerance;
1876 return f_min(val, max);
1877}
1878
1879/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1880private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1881return template integer {
1882 var template integer ret;
1883 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1884 return ret;
1885}
1886
1887
Harald Welte70767382018-02-21 12:16:40 +01001888/* build a template for matching measurement results against */
1889private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1890 var ConnL1Pars l1p := g_pars.l1_pars;
1891 var template RSL_IE_UplinkMeas ul_meas := {
1892 len := 3,
1893 rfu := '0'B,
1894 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001895 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001896 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001897 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001898 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001899 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1900 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001901 supp_meas_info := omit
1902 };
Harald Welte685d5982018-02-27 20:42:05 +01001903 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001904 ul_meas.len := (3+8);
1905 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001906 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001907 toa256_min := ?,
1908 toa256_max := ?,
1909 toa256_std_dev := ?
1910 }
Harald Welte685d5982018-02-27 20:42:05 +01001911 }
Harald Welte70767382018-02-21 12:16:40 +01001912 var template RSL_IE_BS_Power bs_power := {
1913 reserved := 0,
1914 epc := false,
1915 fpc := false,
1916 power_level := l1p.bs_power_level
1917 };
1918 var template RSL_IE_L1Info l1_info := {
1919 ms_power_lvl := l1p.ms_power_level,
1920 fpc := false,
1921 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001922 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001923 };
1924 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001925 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001926 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1927 ?, t_toffs);
1928}
1929
Philipp Maierdd841d32019-12-17 14:44:54 +01001930/* build a template for matching measurement results that do not contain any
1931 * MS related measurement (l1_info, l3_info and ms timing offset). */
1932private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1933 var ConnL1Pars l1p := g_pars.l1_pars;
1934 var template RSL_IE_UplinkMeas ul_meas := {
1935 len := 3,
1936 rfu := '0'B,
1937 dtx_d := l1p.dtx_enabled,
1938 rxlev_f_u := ?,
1939 reserved1 := '00'B,
1940 rxlev_s_u := ?,
1941 reserved2 := '00'B,
1942 rxq_f_u := ?,
1943 rxq_s_u := ?,
1944 supp_meas_info := omit
1945 };
1946 if (l1p.toa256_enabled) {
1947 ul_meas.len := (3+8);
1948 ul_meas.supp_meas_info := {
1949 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1950 toa256_min := ?,
1951 toa256_max := ?,
1952 toa256_std_dev := ?
1953 }
1954 }
1955 var template RSL_IE_BS_Power bs_power := {
1956 reserved := 0,
1957 epc := false,
1958 fpc := false,
1959 power_level := l1p.bs_power_level
1960 };
1961
1962 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1963}
1964
Harald Welte70767382018-02-21 12:16:40 +01001965/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001966private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001967 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001968 var boolean chan_est := false;
1969
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001970 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001971
1972 /* Receive osmocom specific measurement reports. This is the normal
1973 * case. Here we verify that the measurement reports we sent are
1974 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001975 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1976 /* increment counter of next to-be-expected meas rep */
1977 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1978 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001979 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001980
1981 /* The following two cases may only happen in the beginning
1982 * of the channel establishment phase. Once we have received
1983 * the "our" measurement report the first time, the channel
1984 * is established and empty or hardcoded TRXCON reports must
1985 * not occur anymore. */
1986 chan_est := true;
1987
1988 repeat;
1989 }
1990
1991 /* When the BTS has established the channel, the MS might need slightly
1992 * more time to establish the channel and actually start sending. The
1993 * result is then a measurement report that just lacks the measurement
1994 * information of the MS. This is normal and we tolerate this behavior. */
1995 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1996 /* increment counter of next to-be-expected meas rep */
1997 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1998 /* Re-start the timer expecting the next MEAS RES */
1999 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002000 repeat;
2001 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002002
2003 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2004 * measurements if the TTCN3 side does not supply measurement input in
2005 * time. In those cases TRXCON will either use a cached measurement
2006 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2007 * report the templates above will not match. We tolerate this
2008 * behavior, but only once. */
2009 [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 +01002010 /* increment counter of next to-be-expected meas rep */
2011 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2012 if (g_first_meas_res) {
2013 g_first_meas_res := false;
2014 repeat;
2015 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002017 }
Harald Welte70767382018-02-21 12:16:40 +01002018 }
2019 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002021 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002022 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002024 }
2025}
2026
Harald Weltee613f962018-04-18 22:38:16 +02002027private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2028 select (rsl_alg_id) {
2029 case (RSL_ALG_ID_A5_0) { return 0; }
2030 case (RSL_ALG_ID_A5_1) { return 1; }
2031 case (RSL_ALG_ID_A5_2) { return 2; }
2032 case (RSL_ALG_ID_A5_3) { return 3; }
2033 case (RSL_ALG_ID_A5_4) { return 4; }
2034 case (RSL_ALG_ID_A5_5) { return 5; }
2035 case (RSL_ALG_ID_A5_6) { return 6; }
2036 case (RSL_ALG_ID_A5_7) { return 7; }
2037 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2039 /* Make compiler happy by calling mtc.stop here. It is already
2040 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002041 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002042 }
2043 }
2044}
2045
2046private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2047 select (rsl_alg_id) {
2048 case (RSL_ALG_ID_A5_1) { return '000'B; }
2049 case (RSL_ALG_ID_A5_2) { return '001'B; }
2050 case (RSL_ALG_ID_A5_3) { return '010'B; }
2051 case (RSL_ALG_ID_A5_4) { return '011'B; }
2052 case (RSL_ALG_ID_A5_5) { return '100'B; }
2053 case (RSL_ALG_ID_A5_6) { return '101'B; }
2054 case (RSL_ALG_ID_A5_7) { return '110'B; }
2055 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2057 /* Make compiler happy by calling mtc.stop here. It is already
2058 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002059 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002060 }
2061 }
2062}
2063
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002064/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2065private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2066 var GsmFrameNumber fn;
2067 timer T := 8.0;
2068
2069 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2070 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2071
2072 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2073 /* Send the actual RACH */
2074 fn := f_L1CTL_RACH(L1CTL, ra);
2075
2076 T.start;
2077 alt {
2078 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2079 [] T.timeout {
2080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2081 }
2082 }
2083 T.stop
2084 return fn;
2085}
Harald Weltee613f962018-04-18 22:38:16 +02002086
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002087/* Tune to a dedicated channel: L1CTL only */
2088private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002089 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002090 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2091 7 /* TODO: mp_tsc */,
2092 mp_trx0_arfcn));
2093 } else {
2094 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2095 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002096 pars.fhp.maio_hsn.hsn,
2097 pars.fhp.maio_hsn.maio,
2098 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002099 }
2100}
2101
Harald Welte70767382018-02-21 12:16:40 +01002102/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002103private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002104 var GsmFrameNumber fn;
2105 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002106 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002107 var integer ra := 23;
2108
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002109 /* Send RACH request and wait for ChanReq */
2110 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002111
2112 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002113 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002114
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002115 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002116 if (g_pars.fhp.enabled) {
2117 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002118 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002119 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002120 }
2121
Harald Welte70767382018-02-21 12:16:40 +01002122 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002123 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 +01002124 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2125
2126 /* receive IMM.ASS on MS side */
2127 var ImmediateAssignment ia_um;
2128 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002129
2130 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2131 if (ch_desc.h != ia_um.chan_desc.h) {
2132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2133 }
2134
Harald Welte70767382018-02-21 12:16:40 +01002135 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002136 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002137 /* enable encryption, if requested */
2138 if (encr_enable) {
2139 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2140 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2141 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002142
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002143 /* Send TCH Mode Request to the L1 if needed */
2144 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2145 var L1ctlTchMode tch_mode;
2146
2147 select (g_pars.chan_mode.coding_alg_rate) {
2148 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2149 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2150 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2151 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2152 case else {
2153 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2154 " is not supported by the L1, falling back to signalling");
2155 tch_mode := L1CTL_CHAN_MODE_SIGN;
2156 }
2157 }
2158
2159 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2160 }
2161
Harald Weltefa45e9e2018-03-10 18:59:03 +01002162 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002163}
2164
2165/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002166private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002167 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002168 RSL.clear;
2169
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002170 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002171 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002172 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002173 }
Harald Welte70767382018-02-21 12:16:40 +01002174
2175 f_est_dchan();
2176
2177 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2178 * RSL measurement reports on Abis side */
2179 timer T := 8.0;
2180 T.start;
2181 alt {
2182 [] as_l1_sacch();
2183 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002184 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002185 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002186 [] L1CTL.receive { repeat; }
2187 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002188 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002189 * of any earlier errors, so if we reach this timeout, we're good */
2190 setverdict(pass);
2191 }
2192 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002194 }
2195 }
2196 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002197 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002198}
Harald Welte0472ab42018-03-12 15:02:26 +01002199
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002200/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2201private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002202 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002203 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2204 timer Tup := 10.0;
2205 Tup.start;
2206 alt {
2207 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2208 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2209 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002210
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002211 if (rx_lvl != max_rx_lvl) {
2212 repeat;
2213 }
2214 Tup.stop;
2215 }
2216 [] L1CTL.receive { repeat; }
2217 [] Tup.timeout {
2218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2219 log2str("Didn't reach full power ", max_rx_lvl));
2220 }
2221 }
2222 return max_rx_lvl;
2223}
2224
2225/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2226private function f_verify_ramp_up() runs on ConnHdlr {
2227 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002228 var integer initial_rx_lvl := -1;
2229 var integer last_rx_lvl := -1;
2230 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2231
2232 timer T := 2.0;
2233 alt {
2234 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2235 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2236 log("Received rx_level=", rx_lvl);
2237 if (initial_rx_lvl == -1) {
2238 initial_rx_lvl := rx_lvl;
2239 last_rx_lvl := rx_lvl;
2240
2241 /* Expect a somehow low value during first received messages */
2242 if (initial_rx_lvl >= max_rx_lvl / 2) {
2243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2244 log2str("Detected high initial tx power during ramp up: ",
2245 initial_rx_lvl , ", full power is", max_rx_lvl));
2246 }
2247 }
2248
2249 /* received Rx level bigger than maximum allowed power by CN */
2250 if (rx_lvl > max_rx_lvl) {
2251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2252 log2str("Detected Tx power higher than full power: ",
2253 rx_lvl , " > ", max_rx_lvl));
2254 }
2255
2256 /* Make sure it never decreases, since we are rumping up */
2257 if (last_rx_lvl > rx_lvl) {
2258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2259 log2str("Detected Tx power decrease during ramp up: ",
2260 last_rx_lvl , " -> ", rx_lvl));
2261 }
2262
2263 if (rx_lvl == max_rx_lvl and not T.running) {
2264 /* We reached the maximum power, start timer and receive
2265 /* a few more to make sure we don't surpass it */
2266 log("Reached full power, wating a bit more until success");
2267 T.start;
2268 }
2269
2270 last_rx_lvl := rx_lvl;
2271 repeat;
2272 }
2273 [] L1CTL.receive { repeat; }
2274 [] T.timeout { }
2275 }
2276
2277 /* We didn't increase tx power during ramp up */
2278 if (initial_rx_lvl < last_rx_lvl) {
2279 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2280 } else {
2281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2282 log2str("No Tx power increase during whole ramp up: ",
2283 initial_rx_lvl , " -> ", last_rx_lvl));
2284 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002285}
2286
2287/* verify BTS ramps power down to rx_level 0 */
2288private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2289 var L1ctlDlMessage l1_dl;
2290 var integer last_rx_lvl := max_rx_lvl;
2291
2292 timer Tdown := 5.0;
2293 Tdown.start;
2294 alt {
2295 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2296 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2297 log("Received rx_level=", rx_lvl);
2298
2299 /* received Rx level bigger than maximum allowed power by CN */
2300 if (rx_lvl > max_rx_lvl) {
2301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2302 log2str("Detected Tx power higher than full power: ",
2303 rx_lvl , " > ", max_rx_lvl));
2304 }
2305
2306 /* Make sure it never increases, since we are rumping down */
2307 if (last_rx_lvl < rx_lvl) {
2308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2309 log2str("Detected Tx power increase during ramp up: ",
2310 last_rx_lvl , " -> ", rx_lvl));
2311 }
2312
2313 last_rx_lvl := rx_lvl;
2314 if (last_rx_lvl != 0) {
2315 repeat;
2316 }
2317 /* we reached power level 0, we are done */
2318 Tdown.stop;
2319 }
2320 [] L1CTL.receive { repeat; }
2321 [] Tdown.timeout { }
2322 }
2323
2324 /* We didn't increase tx power during ramp down */
2325 if (max_rx_lvl > last_rx_lvl) {
2326 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2327 } else {
2328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2329 log2str("No Tx power decrease during whole ramp down: ",
2330 max_rx_lvl , " -> ", last_rx_lvl));
2331 }
2332}
2333
2334/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002335private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002336 f_l1_tune(L1CTL);
2337 RSL.clear;
2338
2339 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002340
2341 setverdict(pass);
2342}
2343testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2344 var ConnHdlr vc_conn;
2345 var ConnHdlrPars pars;
2346 f_init();
2347 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2348 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2349 pcu_comp := false, trxc_comp := true);
2350 vc_conn.done;
2351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2352}
2353
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002354/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002355private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002356 f_connhdlr_init_vty_bsc();
2357
2358 f_l1_tune(L1CTL);
2359 RSL.clear;
2360
2361 /* Wait until BTS is started and at full power */
2362 var integer max_rx_lvl := f_wait_ramp_up();
2363 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2364
2365 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2366 f_verify_ramp_down(max_rx_lvl);
2367
2368 setverdict(pass);
2369}
2370testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2371 var ConnHdlr vc_conn;
2372 var ConnHdlrPars pars;
2373 f_init();
2374 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2375 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2376 pcu_comp := false, trxc_comp := true);
2377 vc_conn.done;
2378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2379}
2380
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002381/* Verify Tx power:
2382 * + ramping down during ADM state UNLOCKED->LOCKED
2383 * + ramping up during ADM state LOCKED->UNLOCKED
2384 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002385private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002386 var L1ctlDlMessage l1_dl;
2387 var integer last_rx_lvl;
2388
2389 f_connhdlr_init_vty_bsc();
2390
2391 f_l1_tune(L1CTL);
2392 RSL.clear;
2393
2394 /* Wait until BTS is started and at full power */
2395 var integer max_rx_lvl := f_wait_ramp_up();
2396 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2397
2398 log("ADM STATE UNLOCKED->LOCKED");
2399 f_vty_enter_cfg_trx(BSCVTY);
2400 f_vty_transceive(BSCVTY, "rf_locked 1");
2401 last_rx_lvl := max_rx_lvl;
2402 f_verify_ramp_down(max_rx_lvl);
2403
2404 /* Let some time after we received 0dBm, then check we don't receive BCCH
2405 * anymore because scheduler has stopped after ramping down */
2406 f_sleep(2.0);
2407 L1CTL.clear;
2408 timer Tlocked := 2.0;
2409 Tlocked.start;
2410 alt {
2411 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2413 log2str("Received data_ind during rf_locked: ", l1_dl));
2414 }
2415 [] L1CTL.receive { repeat; }
2416 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2417 }
2418
2419 log("ADM STATE LOCKED->UNLOCKED");
2420 f_vty_transceive(BSCVTY, "rf_locked 0");
2421 f_verify_ramp_up();
2422 setverdict(pass);
2423}
2424testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2425 var ConnHdlr vc_conn;
2426 var ConnHdlrPars pars;
2427 f_init();
2428 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2429 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2430 pcu_comp := false, trxc_comp := true);
2431 vc_conn.done;
2432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2433}
2434
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002435private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002436 timer T := 8.0;
2437 T.start;
2438 var RSL_Message rsl;
2439 alt {
2440 [] as_l1_sacch();
2441 [] L1CTL.receive { repeat; }
2442 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2443 if (rsl.ies[3].body.bs_power.power_level == level) {
2444 setverdict(pass)
2445 } else {
2446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2447 }
2448 }
2449 [] T.timeout {
2450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2451 }
2452 }
2453}
2454
2455/* see if the rsl meas res contains our expeced bs power level
2456bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002457private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002458 f_l1_tune(L1CTL);
2459 RSL.clear;
2460
2461 if (mp_bts_trxc_port != -1) {
2462 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2463 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2464 }
2465
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002466 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002467 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2468 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2469
2470 f_est_dchan(more_ies :={valueof(pwr)});
2471
2472 f_check_meas_bs_power_level(pwr_var);
2473
2474 f_rsl_chan_deact();
2475 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2476}
2477
2478/* see if the rsl meas res contains our expeced bs power level
2479bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002480private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002481 f_l1_tune(L1CTL);
2482 RSL.clear;
2483
2484 if (mp_bts_trxc_port != -1) {
2485 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2486 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2487 }
2488
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002489 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002490 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2491
2492 f_est_dchan();
2493
2494 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2495
2496 f_check_meas_bs_power_level(pwr_var);
2497
2498 f_rsl_chan_deact();
2499 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2500}
2501
2502testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2503 var ConnHdlr vc_conn;
2504 var ConnHdlrPars pars;
2505 f_init();
2506 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2507 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2508 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2509 pcu_comp := false, trxc_comp := true);
2510 vc_conn.done;
2511 }
2512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2513}
2514
2515testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2516 var ConnHdlr vc_conn;
2517 var ConnHdlrPars pars;
2518 f_init();
2519 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2520 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2521 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2522 pcu_comp := false, trxc_comp := true);
2523 vc_conn.done;
2524 }
2525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2526}
2527
Eric Wild61edb7e2019-06-03 12:38:31 +02002528/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2529second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2530These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002531private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002532 var uint5_t pwr_var := 7;
2533 var L1ctlDlMessage l1_dl;
2534
2535 f_trxc_fake_rssi(rxlev2dbm(10));
2536 f_l1_tune(L1CTL);
2537 RSL.clear;
2538
2539 var RSL_IE_List addl_ies;
2540 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2541
2542 addl_ies := {
2543 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2544 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2545 };
2546
2547 /* establish with power parameters */
2548 f_est_dchan(more_ies := addl_ies);
2549
2550 /* set a high value to ensure L1 power control level increases */
2551 f_trxc_fake_rssi(rxlev2dbm(20));
2552
2553 timer T2 := 6.0;
2554 T2.start;
2555 alt {
2556 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002557 /* Update sent MS power to follow what BTS requests */
2558 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2559 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002560 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002561 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002562 T2.stop;
2563 }
2564 [] L1CTL.receive { repeat; }
2565 [] T2.timeout {
2566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2567 "Power Level in L1 header has not increased sufficiently");
2568 }
2569 }
2570
2571 /* set a low value to ensure L1 power control level decreases */
2572 f_trxc_fake_rssi(rxlev2dbm(0));
2573
2574 timer T4 := 6.0;
2575 T4.start;
2576 alt {
2577 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002578 /* Update sent MS power to follow what BTS requests */
2579 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2580 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002581 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002582 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002583 T4.stop;
2584 setverdict(pass, "Power level in L1 decreased/increased as expected");
2585 }
2586 [] L1CTL.receive { repeat; }
2587 [] T4.timeout {
2588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2589 "Power Level in L1 header has not decreased sufficiently");
2590 }
2591 }
2592
2593 f_rsl_chan_deact();
2594 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2595
2596}
2597
2598/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002599private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002600 var uint5_t pwr_var := 7;
2601 var L1ctlDlMessage l1_dl;
2602
2603 /* set a low value to ensure power increases */
2604 f_trxc_fake_rssi(rxlev2dbm(10));
2605 f_l1_tune(L1CTL);
2606 RSL.clear;
2607
2608 var RSL_IE_List addl_ies;
2609 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2610
2611 addl_ies := {
2612 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2613 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2614 };
2615
2616 /* establish with power parameters */
2617 f_est_dchan(more_ies := addl_ies);
2618
2619 timer T1 := 10.0;
2620 T1.start;
2621 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002622 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2623 /* Update sent MS power to follow what BTS requests */
2624 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2625 repeat;
2626 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002627 [] L1CTL.receive { repeat; }
2628 [] T1.timeout {
2629 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2630 setverdict(fail, "Power level in L1 header should not have changed");
2631 }
2632 }
2633 }
2634
2635 f_rsl_chan_deact();
2636 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2637
2638}
2639
2640/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002641private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002642 var L1ctlDlMessage l1_dl;
2643 var uint5_t pwr_var := 15;
2644 var uint5_t pwr_max_var := f_get_max_power_from_band();
2645
2646 /* set a low value to ensure power increases */
2647 f_trxc_fake_rssi(rxlev2dbm(10));
2648 f_l1_tune(L1CTL);
2649 RSL.clear;
2650
2651 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2652 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2653
2654 /* establish with fixed power level */
2655 f_est_dchan(more_ies :={valueof(pwr)});
2656
2657 /* check our initial power level */
2658 f_wait_for_l1_power_level(pwr_var);
2659
2660 /* update power param to enable power loop
2661 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2662 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2663
2664 /* wait, then check that our power level was reduced */
2665 timer T1 := 10.0;
2666 T1.start;
2667 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002668 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2669 /* Update sent MS power to follow what BTS requests */
2670 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2671 repeat;
2672 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002673 [] L1CTL.receive { repeat; }
2674 [] T1.timeout {
2675 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2676 if( f_power_level_is_highest_dbm(rcv) ){
2677 setverdict(pass, "Power level in L1 header reduced as expected");
2678 } else {
2679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2680 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2681 }
2682 }
2683 }
2684
2685 f_rsl_chan_deact();
2686 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2687
2688}
2689
2690/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002691private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002692 var L1ctlDlMessage l1_dl;
2693
2694 /* set a high value to ensure power decreases */
2695 f_trxc_fake_rssi(rxlev2dbm(50));
2696 f_l1_tune(L1CTL);
2697 RSL.clear;
2698
2699 var uint5_t pwr_var := 5;
2700 var uint5_t pwr_target_val := 15;
2701
2702 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2703 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2704
2705 /* establish with fixed power level */
2706 f_est_dchan(more_ies :={valueof(pwr)});
2707
2708 /* check our initial power level */
2709 f_wait_for_l1_power_level(pwr_var);
2710
2711 /* update power param to enable power loop
2712 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002713 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002714
2715 /* wait, then check that our power level was increased */
2716 timer T1 := 10.0;
2717 T1.start;
2718 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002719 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2720 /* Update sent MS power to follow what BTS requests */
2721 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2722 repeat;
2723 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002724 [] L1CTL.receive { repeat; }
2725 [] T1.timeout {
2726 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2727 setverdict(pass, "Power level in L1 header increased to lowest power value");
2728 } else {
2729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2730 "Power level in L1 header NOT increased to lowest power value");
2731 }
2732 }
2733 }
2734
2735 f_rsl_chan_deact();
2736 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2737
2738}
2739
Eric Wild095024b2019-06-17 15:08:57 +02002740/* see if we change the power level without receiving power parameters, which should not happen
2741rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002742private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002743 var L1ctlDlMessage l1_dl;
2744
2745 /* set a high value to ensure power decreases */
2746 f_trxc_fake_rssi(rxlev2dbm(50));
2747 f_l1_tune(L1CTL);
2748 RSL.clear;
2749
2750 var uint5_t pwr_var := 5;
2751
2752 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2753 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2754
2755 /* establish with fixed power level */
2756 f_est_dchan(more_ies :={valueof(pwr)});
2757
2758 /* check our initial power level */
2759 f_wait_for_l1_power_level(pwr_var);
2760
2761 /* wait, then check that our power level did not change */
2762 timer T1 := 10.0;
2763 T1.start;
2764 alt {
2765 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2766 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2767 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2768 "BS power control should not be active unless we receive a power parameters IE!");
2769 }
2770 repeat;
2771 }
2772 [] L1CTL.receive { repeat; }
2773 [] T1.timeout { setverdict(pass); }
2774 }
2775
2776 f_rsl_chan_deact();
2777 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2778
2779}
2780
Eric Wild095024b2019-06-17 15:08:57 +02002781/* see if we change the power level without receiving power parameters, which should not happen
2782ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002783private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002784 var L1ctlDlMessage l1_dl;
2785
2786 /* set a high value to ensure power decreases */
2787 f_trxc_fake_rssi(rxlev2dbm(50));
2788 f_l1_tune(L1CTL);
2789 RSL.clear;
2790
2791 var uint5_t pwr_var := 5;
2792
2793 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2794 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2795
2796 /* establish with fixed power level */
2797 f_est_dchan(more_ies :={valueof(pwr)});
2798
2799 /* check our initial power level */
2800 f_wait_for_l1_power_level(pwr_var);
2801
2802 /* pwr control without power params IE, should NOT activate MS power control*/
2803 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2804
2805 /* wait, then check that our power level did not change */
2806 timer T1 := 10.0;
2807 T1.start;
2808 alt {
2809 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2810 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2812 "BS power control should not be active unless we receive a power parameters IE!");
2813 }
2814 repeat;
2815 }
2816 [] L1CTL.receive { repeat; }
2817 [] T1.timeout { setverdict(pass); }
2818 }
2819
2820 f_rsl_chan_deact();
2821 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2822
2823}
2824
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002825private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002826 var L1ctlDlMessage l1_dl;
2827 timer T0 := 10.0;
2828 T0.start;
2829 alt {
2830 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2831 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2833 "Power level in L1 header != signaled (RSL) power level.");
2834 }
2835 }
2836 [] L1CTL.receive { repeat; }
2837 [] T0.timeout {
2838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2839 "Timeout waiting for initial power level");
2840 }
2841 }
2842 T0.stop;
2843}
2844
2845private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2846 var IntegerRecord min_dbm_level;
2847 var IntegerRecord max_dbm_level;
2848 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2849
2850 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2851 if (min_dbm_level[i] == level) {
2852 return true;
2853 }
2854 }
2855 return false;
2856}
2857
2858private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2859 var IntegerRecord min_dbm_level;
2860 var IntegerRecord max_dbm_level;
2861 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2862
2863 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2864 if (max_dbm_level[i] == level) {
2865 return true;
2866 }
2867 }
2868 return false;
2869}
2870
2871private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2872 var IntegerRecord min_dbm_level;
2873 var IntegerRecord max_dbm_level;
2874 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2875 return max_dbm_level[0];
2876}
2877
2878type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002879private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002880private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2881 // 45.005 4.1.1
2882 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2883 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2884 2, 1, 0};
2885 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2886 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2887 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2888 var IntegerRecord rv;
2889
2890 select(band){
2891 case (BtsBand_allGSM){
2892 rv := gsm_power;
2893 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2894 max_dbm_level := {2, 1, 0};
2895 }
2896 case("DCS1800"){
2897 rv := dcs_power;
2898 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2899 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2900 }
2901 case("PCS1900"){
2902 rv := pcs_power;
2903 min_dbm_level := {15};
2904 max_dbm_level := {30};
2905 }
Harald Welte194b6912020-10-11 21:01:55 +02002906 case else {
2907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2908 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002909 }
2910
2911 return rv;
2912}
2913
2914private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002915 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 +02002916}
2917
2918testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2919 var ConnHdlr vc_conn;
2920 var ConnHdlrPars pars;
2921 f_init();
2922 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2923 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2924 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2925 pars.bts0_band := f_vty_get_bts0_band();
2926 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2927 vc_conn.done;
2928 }
2929 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2931}
2932
2933testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2934 var ConnHdlr vc_conn;
2935 var ConnHdlrPars pars;
2936 f_init();
2937 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2938 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2939 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2940 pars.bts0_band := f_vty_get_bts0_band();
2941 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2942 vc_conn.done;
2943 }
2944 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2946}
2947
2948testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2949 var ConnHdlr vc_conn;
2950 var ConnHdlrPars pars;
2951 f_init();
2952 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2953 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2954 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2955 pars.bts0_band := f_vty_get_bts0_band();
2956 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2957 vc_conn.done;
2958 }
2959 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2961}
2962
2963testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2964 var ConnHdlr vc_conn;
2965 var ConnHdlrPars pars;
2966 f_init();
2967 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2968 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2969 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2970 pars.bts0_band := f_vty_get_bts0_band();
2971 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2972 vc_conn.done;
2973 }
2974 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2976}
2977
Eric Wild280ccb82019-06-17 11:11:52 +02002978testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2979 var ConnHdlr vc_conn;
2980 var ConnHdlrPars pars;
2981 f_init();
2982 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2983 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2984 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2985 pars.bts0_band := f_vty_get_bts0_band();
2986 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2987 vc_conn.done;
2988 }
2989 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2991}
2992
Eric Wild095024b2019-06-17 15:08:57 +02002993testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2994 var ConnHdlr vc_conn;
2995 var ConnHdlrPars pars;
2996 f_init();
2997 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2998 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2999 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3000 pars.bts0_band := f_vty_get_bts0_band();
3001 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3002 vc_conn.done;
3003 }
3004 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3006}
3007
Philipp Maier149c3922020-10-22 17:29:36 +02003008function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003009 var template RSL_IE_ChannelMode ch_mode;
3010 var ConnHdlr vc_conn;
3011 var ConnHdlrPars pars;
3012 f_init();
3013 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3014 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3015 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003016 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003017 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3018 pcu_comp := false, trxc_comp := true);
3019 vc_conn.done;
3020 }
3021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3022}
Philipp Maier149c3922020-10-22 17:29:36 +02003023
3024testcase TC_meas_res_speech_tchf() runs on test_CT {
3025 f_TC_meas_res_speech_tchf(false);
3026}
3027
3028testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3029 f_TC_meas_res_speech_tchf(true);
3030}
3031
3032function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003033 var template RSL_IE_ChannelMode ch_mode;
3034 var ConnHdlr vc_conn;
3035 var ConnHdlrPars pars;
3036 f_init();
3037 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3038 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3039 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003040 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003041 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3042 pcu_comp := false, trxc_comp := true);
3043 vc_conn.done;
3044 }
3045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3046}
Philipp Maier149c3922020-10-22 17:29:36 +02003047
3048testcase TC_meas_res_speech_tchh() runs on test_CT {
3049 f_TC_meas_res_speech_tchh(false)
3050}
3051
3052testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3053 f_TC_meas_res_speech_tchh(true)
3054}
3055
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003056testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3057 var template RSL_IE_ChannelMode ch_mode;
3058 var ConnHdlr vc_conn;
3059 var ConnHdlrPars pars;
3060 f_init();
3061 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3062 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3063 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3064 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3065 pars.l1_pars.toa256_enabled := true;
3066 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3067 pcu_comp := false, trxc_comp := true);
3068 vc_conn.done;
3069 }
3070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3071}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003072
Harald Welte70767382018-02-21 12:16:40 +01003073testcase TC_meas_res_sign_tchf() runs on test_CT {
3074 var ConnHdlr vc_conn;
3075 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003076 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003077 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003078 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003079 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3080 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003081 vc_conn.done;
3082 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003084}
3085testcase TC_meas_res_sign_tchh() runs on test_CT {
3086 var ConnHdlr vc_conn;
3087 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003088 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003089 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003090 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003091 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3092 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003093 vc_conn.done;
3094 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003096}
3097testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3098 var ConnHdlr vc_conn;
3099 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003100 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003101 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3102 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003103 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3104 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003105 vc_conn.done;
3106 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003108}
3109testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3110 var ConnHdlr vc_conn;
3111 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003112 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003113 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3114 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003115 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3116 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003117 vc_conn.done;
3118 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003120}
Harald Welte685d5982018-02-27 20:42:05 +01003121testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3122 var ConnHdlr vc_conn;
3123 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003124 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003125 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3126 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003127 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003128 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003129 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3130 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003131 vc_conn.done;
3132 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003134}
3135
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003136/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3137 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003138private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003139 var L1ctlDlMessage l1_dl;
3140 var RSL_IE_MS_Power ms_power;
3141 var RSL_Message rsl;
3142 var uint5_t power_level := 0;
3143
3144 f_l1_tune(L1CTL);
3145 RSL.clear;
3146
3147 f_est_dchan();
3148
3149 ms_power.reserved := 0;
3150 ms_power.fpc_epc := false;
3151
3152 /* Send the first power control command. This will disable any BTS/TRX
3153 * internal power control and switch the MS (which is not in scope of
3154 * this test) to a constant power level. We start with a power level
3155 * of 0 */
3156 ms_power.power_level := power_level;
3157 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3158 RSL.send(rsl);
3159
3160 alt {
3161
3162 /* Pick all SACCH blocks for checking */
3163 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3164
3165 /* The first byte of the L1 header contains the power level.
3166 * The reserved bits and the fpc bit is set to 0, so we may
3167 * compare directly. */
3168 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3169 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3170 }
3171
3172 /* Signal a new power level via RSL for the next turn. */
3173 if (power_level < 31) {
3174 power_level := power_level + 1;
3175 ms_power.power_level := power_level;
3176 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3177 RSL.send(rsl);
3178 repeat;
3179 }
3180
3181 }
3182
3183 /* Ignore all other blocks */
3184 [] L1CTL.receive { repeat; }
3185
3186 }
3187
3188 f_rsl_chan_deact();
3189 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3190
3191 setverdict(pass);
3192}
3193
3194testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3195 var ConnHdlr vc_conn;
3196 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003197 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003198
3199 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3200 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3201 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3202 vc_conn.done;
3203 }
3204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3205}
Harald Welte70767382018-02-21 12:16:40 +01003206
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003207/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003208TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003209private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003210 var L1ctlDlMessage l1_dl;
3211 var uint5_t ta_to_test := 16;
3212
3213
3214 f_l1_tune(L1CTL);
3215 RSL.clear;
3216
3217 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003218 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003219
3220 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3221
3222
3223 alt {
3224
3225 /* Pick all SACCH blocks for checking */
3226 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3227
3228 /* The second byte of the L1 header contains the TA. */
3229 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3230 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3231 }
3232
3233 }
3234
3235 /* Ignore all other blocks */
3236 [] L1CTL.receive { repeat; }
3237
3238 }
3239
3240 f_rsl_chan_deact();
3241 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3242
3243 setverdict(pass);
3244}
3245
3246testcase TC_rsl_chan_initial_ta() runs on test_CT {
3247 var ConnHdlr vc_conn;
3248 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003249 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003250 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003251 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3252 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003253 vc_conn.done;
3254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3255}
3256
Eric Wilde57e1a62019-05-28 13:30:55 +02003257/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003258private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003259 var L1ctlDlMessage l1_dl;
3260 var uint5_t ms_power_level := 7;
3261
3262 var RSL_IE_MS_Power ms_power;
3263 ms_power.reserved := 0;
3264 ms_power.fpc_epc := false;
3265 ms_power.power_level := ms_power_level;
3266
3267 f_l1_tune(L1CTL);
3268 RSL.clear;
3269
3270 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3271
3272 timer T := 1.0;
3273 T.start;
3274 alt {
3275 /* Pick all SACCH blocks for checking */
3276 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3277 /* The first byte of the L1 header contains the power level.. */
3278 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3279 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3280 }
3281 }
3282 /* Ignore all other blocks */
3283 [] L1CTL.receive { repeat; }
3284 [] T.timeout {
3285 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3286 }
3287 }
3288
3289 f_rsl_chan_deact();
3290 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3291 setverdict(pass);
3292}
3293
3294testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3295 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3296 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3297}
3298
Harald Welte0472ab42018-03-12 15:02:26 +01003299/* 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 +01003300private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003301 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003302 RSL.clear;
3303
3304 f_est_dchan();
3305 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003306 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003307
3308 timer T := 40.0;
3309 T.start;
3310 alt {
3311 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3312 setverdict(pass)
3313 }
3314 [] RSL.receive { repeat };
3315 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003317 }
3318 }
3319 f_rsl_chan_deact();
3320}
3321testcase TC_conn_fail_crit() runs on test_CT {
3322 var ConnHdlr vc_conn;
3323 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003324 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003325 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3326 pars.t_guard := 60.0;
3327 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3328 vc_conn.done;
3329}
3330
Harald Welte93640c62018-02-25 16:59:33 +01003331/***********************************************************************
3332 * Paging
3333 ***********************************************************************/
3334
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003335private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003336 if (tmsi == 'FFFFFFFF'O) {
3337 return true;
3338 } else {
3339 return false;
3340 }
3341}
Harald Welte70767382018-02-21 12:16:40 +01003342
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003343private type record allowedFn { integer frame_nr }
3344private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3345private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3346private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3347private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3348private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3349private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3350private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3351private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3352private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003353{
3354 var integer frame_nr_51;
3355 frame_nr_51 := frame_nr mod 51
3356
3357 var allowedFn fn_check;
3358 fn_check.frame_nr := frame_nr_51;
3359
3360 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003362 return;
3363 }
3364
3365 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3366 return;
3367 }
3368 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3369 return;
3370 }
3371 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3372 return;
3373 }
3374 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3375 return;
3376 }
3377 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3378 return;
3379 }
3380 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3381 return;
3382 }
3383 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3384 return;
3385 }
3386 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3387 return;
3388 }
3389
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003391 return;
3392}
3393
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003394private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3395 inout integer num_paging_rcv_ids,
3396 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003397runs on test_CT {
3398 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003399 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003400 repeat;
3401 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003402 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003403 var octetstring without_plen :=
3404 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3405 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003406
3407 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3408
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003409 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3410 /* Ignore empty RR Paging Request (PCH filling) messages.
3411 * TODO: does it make sense to count them? */
3412 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003413 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3414 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003415 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003416 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3417 }
3418 } else if (match(rr, tr_PAGING_REQ2)) {
3419 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3420 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3421 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3422 }
3423 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3424 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3425 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003426 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003427 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3428 }
3429 } else if (match(rr, tr_PAGING_REQ3)) {
3430 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3431 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3432 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3433 }
3434 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3435 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3436 }
3437 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3438 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3439 }
3440 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3441 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3442 }
3443 }
3444 repeat;
3445 }
3446}
3447
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003448private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003449 boolean combined_ccch,
3450 integer bs_ag_blks_res,
3451 float load_factor,
3452 boolean exp_load_ind,
3453 boolean exp_overload,
3454 boolean use_tmsi
3455}
3456
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003457private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003458 integer num_paging_sent,
3459 integer num_paging_rcv_msgs,
3460 integer num_paging_rcv_ids,
3461 integer num_overload
3462}
3463
Harald Welte68e495b2018-02-25 00:05:57 +01003464/* Helper function for paging related testing */
3465private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003466 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003467 f_init_l1ctl();
3468 f_l1_tune(L1CTL);
3469
3470 var PagingTestState st := {
3471 num_paging_sent := 0,
3472 num_paging_rcv_msgs := 0,
3473 num_paging_rcv_ids := 0,
3474 num_overload := 0
3475 };
3476
3477 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3478 var float max_pch_imsi_per_sec;
3479 if (cfg.use_tmsi) {
3480 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3481 } else {
3482 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3483 }
3484 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3485 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003486 var float time_total := 20.0;
3487 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3488 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003489
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003490 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3491 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003492
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003493 timer T_itv := 0.0;
3494 T_itv.start;
3495 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003496 alt {
3497 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003498 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003499 st.num_overload := st.num_overload + 1;
3500 repeat;
3501 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003502 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003504 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003505 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003506 log("Rx LOAD_IND");
3507 /* FIXME: analyze/verify interval + contents */
3508 repeat;
3509 }
3510 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003511 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003512 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003513 [] T_itv.timeout {
3514 /* Send paging cmds based on elapsed time */
3515 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3516 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003517 var MobileIdentityV mi;
3518
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003519 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003520 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003521 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003522 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003523 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003524 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003525
3526 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003527 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 +02003528
3529 st.num_paging_sent := st.num_paging_sent + 1;
3530 }
3531 if (st.num_paging_sent < pkt_total) {
3532 /* Wait for interval to next PAGING COMMAND */
3533 var float time_now := T_total.read;
3534 var float next_sched := int2float(st.num_paging_sent)*interval;
3535 if (next_sched > time_now) {
3536 T_itv.start(next_sched - time_now);
3537 } else {
3538 T_itv.start(0.0);
3539 }
3540 } else {
3541 /* We are done, no need to keep counting */
3542 T_total.stop;
3543 }
3544 }
3545 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003546 }
3547 }
3548
3549 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3550 timer T_wait := 18.0;
3551 T_wait.start;
3552 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003553 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003554 [] L1CTL.receive { repeat; }
3555 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003556 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3557 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003558 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003560 }
Harald Welte68e495b2018-02-25 00:05:57 +01003561 }
3562
3563 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3564 " rcvd_ids=", st.num_paging_rcv_ids);
3565 return st;
3566}
3567
3568/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3569 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3570 * - that CCCH LOAD IND (PCH) are being generated
3571 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3572testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003573 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003574 var PagingTestCfg cfg := {
3575 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003576 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003577 load_factor := 0.8,
3578 exp_load_ind := true,
3579 exp_overload := false,
3580 use_tmsi := false
3581 };
3582 var PagingTestState st := f_TC_paging(cfg);
3583 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3585 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003586 } else {
3587 setverdict(pass);
3588 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003590}
3591
3592/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3593 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3594 * - that CCCH LOAD IND (PCH) are being generated
3595 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3596testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003597 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003598 var PagingTestCfg cfg := {
3599 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003600 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003601 load_factor := 0.8,
3602 exp_load_ind := true,
3603 exp_overload := false,
3604 use_tmsi := true
3605 };
3606 var PagingTestState st := f_TC_paging(cfg);
3607 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3609 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003610 } else {
3611 setverdict(pass);
3612 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003614}
3615
3616/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3617 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3618 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3619 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3620testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003621 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003622 var PagingTestCfg cfg := {
3623 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003624 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003625 load_factor := 2.0,
3626 exp_load_ind := true,
3627 exp_overload := true,
3628 use_tmsi := false
3629 };
3630 var PagingTestState st := f_TC_paging(cfg);
3631 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3632 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003633 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003634 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003635 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 +01003636 } else {
3637 setverdict(pass);
3638 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003640}
3641
3642/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3643 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3644 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3645 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3646testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003647 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003648 var PagingTestCfg cfg := {
3649 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003650 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003651 load_factor := 2.0,
3652 exp_load_ind := true,
3653 exp_overload := true,
3654 use_tmsi := true
3655 };
3656 var PagingTestState st := f_TC_paging(cfg);
3657 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3658 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003659 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003660 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003661 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 +01003662 } else {
3663 setverdict(pass);
3664 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003666}
3667
3668
Harald Welte93640c62018-02-25 16:59:33 +01003669/***********************************************************************
3670 * Immediate Assignment / AGCH
3671 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003672private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003673 len := 0,
3674 ma := ''B
3675}
Harald Welte93640c62018-02-25 16:59:33 +01003676
Harald Weltee8d750e2018-06-10 21:41:35 +02003677private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3678 return int2str(num_tx) & " sent, "
3679 & int2str(num_rx) & " received, "
3680 & int2str(num_del) & " deleted";
3681}
3682
3683private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3684 var L1ctlDlMessage l1_dl;
3685 timer T := 10.0;
3686 var integer num_tx := 0;
3687 var integer num_rx := 0;
3688 var integer num_del := 0;
3689 var charstring res_str;
3690 var float rx_ratio;
3691
Harald Welte10474062019-05-30 16:48:17 +02003692 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003693 f_init_l1ctl();
3694 f_l1_tune(L1CTL);
3695
3696 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003697 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003698 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3699 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003700 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003701 num_tx := num_tx+1;
3702 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003703 }
3704 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003705 T.start;
3706 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003707 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003708 num_del := num_del+1;
3709 repeat;
3710 }
3711 [] RSL_CCHAN.receive {
3712 repeat;
3713 }
3714 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003715 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3716 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3717 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003718 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003719 } else {
3720 num_rx := num_rx+1;
3721 }
3722 repeat;
3723 }
3724 [] L1CTL.receive { repeat; }
3725 [] T.timeout { }
3726 }
3727 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3728 log("AGCH test: " & res_str);
3729 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003731 }
3732 rx_ratio := int2float(num_rx) / int2float(num_tx);
3733 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003734 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 +02003735 } else {
3736 setverdict(pass);
3737 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003739}
3740
Harald Weltee8d750e2018-06-10 21:41:35 +02003741/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3742testcase TC_imm_ass_1000_20ms() runs on test_CT {
3743 f_TC_imm_ass(1000, 0.02, 0.25);
3744}
3745
3746/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3747testcase TC_imm_ass_200_0ms() runs on test_CT {
3748 f_TC_imm_ass(200, 0.0, 0.05);
3749}
3750
3751/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3752testcase TC_imm_ass_200_76ms() runs on test_CT {
3753 f_TC_imm_ass(150, 0.076, 1.00);
3754}
3755
3756
3757
Harald Welte48494ca2018-02-25 16:59:50 +01003758/***********************************************************************
3759 * BCCH
3760 ***********************************************************************/
3761
3762/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003763private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003764 GsmFrameNumber frame_number,
3765 SystemInformation si
3766}
3767
3768/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003769private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003770
3771/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003772private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003773
3774/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003775private function f_si_vecslot_contains(SystemInformationVector arr,
3776 RrMessageType key,
3777 boolean bcch_ext := false)
3778return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003779 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3780 var integer fn_mod51 := arr[i].frame_number mod 51;
3781 if (not bcch_ext and fn_mod51 == 2 or
3782 bcch_ext and fn_mod51 == 6) {
3783 if (arr[i].si.header.message_type == key) {
3784 return true;
3785 }
3786 }
3787 }
3788 return false;
3789}
3790
3791/* 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 +07003792private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3793 integer tc, RrMessageType key,
3794 boolean ext_bcch := false)
3795{
Harald Welte48494ca2018-02-25 16:59:50 +01003796 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003798 }
3799}
3800
3801/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003802private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3803 RrMessageType key)
3804return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003805 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3806 if (f_si_vecslot_contains(arr[tc], key) or
3807 f_si_vecslot_contains(arr[tc], key, true)) {
3808 return true;
3809 }
3810 }
3811 return false;
3812}
3813
3814/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003815private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3816 RrMessageType key,
3817 boolean bcch_ext := false,
3818 integer n := 1, integer m := 4)
3819return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003820 var integer count := 0;
3821 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3823 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003824 }
3825 for (var integer i:= 0; i < m; i := i + 1) {
3826 var integer fn_mod51 := arr[i].frame_number mod 51;
3827 if (not bcch_ext and fn_mod51 == 2 or
3828 bcch_ext and fn_mod51 == 6) {
3829 if (arr[i].si.header.message_type == key) {
3830 count := count + 1;
3831 }
3832 }
3833 }
3834 if (count >= n) {
3835 return true;
3836 } else {
3837 return false;
3838 }
3839}
3840
3841/* 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 +07003842private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3843 integer tc, RrMessageType key,
3844 boolean ext_bcch := false,
3845 integer n, integer m)
3846{
Harald Welte48494ca2018-02-25 16:59:50 +01003847 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003849 }
3850}
3851
3852/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003853private function f_si_vecslot_contains_only(SystemInformationVector arr,
3854 RrMessageType key,
3855 boolean bcch_ext := false)
3856return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003857 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3858 var integer fn_mod51 := arr[i].frame_number mod 51;
3859 if (not bcch_ext and fn_mod51 == 2 or
3860 bcch_ext and fn_mod51 == 6) {
3861 if (arr[i].si.header.message_type != key) {
3862 return false;
3863 }
3864 }
3865 }
3866 return true;
3867}
3868
3869/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003870private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3871 integer tc, RrMessageType key,
3872 boolean ext_bcch := false)
3873{
Harald Welte48494ca2018-02-25 16:59:50 +01003874 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003876 }
3877}
3878
3879/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003880private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003881 boolean bcch_extended,
3882 boolean si1_present,
3883 boolean si2bis_present,
3884 boolean si2ter_present,
3885 boolean si2quater_present,
3886 boolean si7_present,
3887 boolean si8_present,
3888 boolean si9_present,
3889 boolean si13_present,
3890 boolean si13alt_present,
3891 boolean si15_present,
3892 boolean si16_present,
3893 boolean si17_present,
3894 boolean si2n_present,
3895 boolean si21_present,
3896 boolean si22_present
3897}
3898
3899/* 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 +07003900private function f_validate_si_scheduling(SystemInformationConfig cfg,
3901 SystemInformationVectorPerTc si_per_tc)
3902{
Harald Welte48494ca2018-02-25 16:59:50 +01003903 var integer i;
3904 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3905 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003907 }
3908 }
3909 if (cfg.si1_present) {
3910 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3911 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3912 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3913 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3914 /* make sure *ALL* contain SI1 */
3915 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3916 }
3917 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3918 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3919 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3920 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3921 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3922 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3923
3924 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3925 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3926 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3927 * consecutive occurrences of TC = 4. */
3928 if (cfg.si2bis_present and not cfg.si2ter_present) {
3929 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3930 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3931 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3932 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3933 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3934 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3935 }
3936
3937 if (cfg.si7_present or cfg.si8_present) {
3938 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3939 * if System Information type 4 does not contain all information needed for cell
3940 * selection and reselection. */
3941 if (not cfg.bcch_extended) {
3942 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3943 }
3944 if (cfg.si7_present) {
3945 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3946 }
3947 if (cfg.si8_present) {
3948 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3949 }
3950 }
3951
3952 if (cfg.si2quater_present) {
3953 /* iii) System information type 2 quater is sent if needed, as determined by the system
3954 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3955 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3956 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3957 * within any of 4 consecutive occurrences of TC = 5. */
3958 if (not (cfg.bcch_extended)) {
3959 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3960 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3961 } else {
3962 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3963 }
3964 } else {
3965 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3966 }
3967 }
3968 if (cfg.si9_present) {
3969 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3970 * in system information type 3 as defined in 3GPP TS 44.018. */
3971 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3972 }
3973 if (cfg.si13_present) {
3974 /* vii) System Information type 13 is only related to the GPRS service. System Information
3975 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3976 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3977 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3978 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3979 * within any of 4 consecutive occurrences of TC=4. */
3980 if (not cfg.bcch_extended) {
3981 log("not-bccch-extended");
3982 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3983 } else {
3984 log("bccch-extended");
3985 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3986 }
3987 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003989 }
3990 }
3991 if (cfg.si16_present or cfg.si17_present) {
3992 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3993 * should not be sent in a cell where network sharing is used (see rule xv). */
3994 if (cfg.si22_present) {
3995 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3996 }
3997 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003999 }
4000 if (not cfg.bcch_extended) {
4001 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4002 }
4003 if (cfg.si16_present) {
4004 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4005 }
4006 if (cfg.si17_present) {
4007 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4008 }
4009 }
4010
4011 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4012 * broadcast information. The frequency with which they are sent is determined by the
4013 * system operator. System Information type 9 identifies the scheduling of System
4014 * Information type 18 and 20 messages. */
4015
4016 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4017 * Information Type 19 is present, then its scheduling shall be indicated in System
4018 * Information Type 9. */
4019
4020 if (cfg.si15_present) {
4021 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4022 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4023 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4024 * 4 consecutive occurrences of TC = 1. */
4025 if (not cfg.bcch_extended) {
4026 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4027 } else {
4028 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4029 }
4030 }
4031 if (cfg.si13alt_present) {
4032 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4033 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4034 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4035 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4036 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4037 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4038 * of TC = 4. */
4039 if (cfg.si13_present) {
4040 testcase.stop("Error: Cannot have SI13alt and SI13");
4041 }
4042 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004044 }
4045 if (not cfg.bcch_extended) {
4046 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4047 } else {
4048 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4049 }
4050 }
4051 if (cfg.si2n_present) {
4052 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4053 * as determined by the system operator. In the case that the message is sent on the
4054 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4055 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4056 * consecutive occurrences of TC = 4. */
4057 if (not cfg.bcch_extended) {
4058 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4059 } else {
4060 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4061 }
4062 }
4063 if (cfg.si21_present) {
4064 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4065 * determined by the system operator. If Extended Access Barring is in use in the cell
4066 * then this message is sent at least once within any of 4 consecutive occurrences of
4067 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4068 * cell then this message shall only be sent on BCCH Ext. */
4069 if (not cfg.bcch_extended) {
4070 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4071 } else {
4072 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4073 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004075 }
4076 }
4077 }
4078 if (cfg.si22_present) {
4079 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4080 * should not be sent in a cell where SoLSA is used (see rule viii). System
4081 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4082 * =2 and TC=6. */
4083 if (cfg.si16_present or cfg.si17_present) {
4084 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4085 }
4086 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4087 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004089 }
4090 if (not cfg.bcch_extended) {
4091 testcase.stop("Error: SI22 requires BCCH Extd!");
4092 } else {
4093 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4094 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4095 }
4096 }
4097}
4098
4099/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004100private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4101return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004102 timer T := duration;
4103 var SystemInformationVectorPerTc si_per_tc;
4104 var L1ctlDlMessage l1_dl;
4105
4106 /* initialize all per-TC vectors empty */
4107 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4108 si_per_tc[i] := {};
4109 }
4110
4111 /* flush all previous L1 queued msgs */
4112 pt.clear;
4113
4114 T.start;
4115 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004116 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004117 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4118 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4119 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004120 repeat;
4121 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004122
Harald Welte48494ca2018-02-25 16:59:50 +01004123 var integer tc := f_gsm_compute_tc(sig.frame_number);
4124 log("SI received at TC=", tc, ": ", sig.si);
4125 /* append to the per-TC bucket */
4126 si_per_tc[tc] := si_per_tc[tc] & { sig };
4127 repeat;
4128 }
4129 [] pt.receive { repeat; }
4130 [] T.timeout { }
4131 }
4132
4133 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4134 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4135 }
4136 log("si_per_tc=", si_per_tc);
4137 return si_per_tc;
4138}
4139
4140/* helper function: Set given SI via RSL + validate scheduling.
4141 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004142private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004143 var SystemInformationVectorPerTc si_per_tc;
4144 f_init_l1ctl();
4145 f_l1_tune(L1CTL);
4146
4147 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004148 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004149 f_validate_si_scheduling(si_cfg, si_per_tc);
4150
4151 setverdict(pass);
4152}
4153
4154testcase TC_si_sched_default() runs on test_CT {
4155 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004156 /* 2+3+4 are mandatory and set in f_init() */
4157 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004159}
4160
4161testcase TC_si_sched_1() runs on test_CT {
4162 f_init();
4163 si_cfg.si1_present := true;
4164 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004165 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004167}
4168
4169testcase TC_si_sched_2bis() runs on test_CT {
4170 f_init();
4171 si_cfg.si2bis_present := true;
4172 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4173 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004175}
4176
4177testcase TC_si_sched_2ter() runs on test_CT {
4178 f_init();
4179 si_cfg.si2ter_present := true;
4180 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4181 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004183}
4184
4185testcase TC_si_sched_2ter_2bis() runs on test_CT {
4186 f_init();
4187 si_cfg.si2bis_present := true;
4188 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4189 si_cfg.si2ter_present := true;
4190 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4191 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004193}
4194
4195testcase TC_si_sched_2quater() runs on test_CT {
4196 f_init();
4197 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004198 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004199 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004201}
4202
4203testcase TC_si_sched_13() runs on test_CT {
4204 f_init();
4205 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004206 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004207 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004209}
4210
4211testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4212 f_init();
4213 si_cfg.si2bis_present := true;
4214 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4215 si_cfg.si2ter_present := true;
4216 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4217 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004218 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004219 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004220 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004221 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004223}
4224
4225
Harald Welte68e495b2018-02-25 00:05:57 +01004226testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004227 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004228 /* FIXME: enable / disable individual BCCH info */
4229 //ts_RSL_BCCH_INFO(si_type, info);
4230 /* expect no ERROR REPORT after either of them *
4231 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004233}
4234
Harald Welte93640c62018-02-25 16:59:33 +01004235/***********************************************************************
4236 * Low-Level Protocol Errors / ERROR REPORT
4237 ***********************************************************************/
4238
Harald Welte01d982c2018-02-25 01:31:40 +01004239private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4240 timer T := 5.0;
4241 T.start;
4242 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004243 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004244 setverdict(pass);
4245 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004246 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004248 }
4249 [] RSL_CCHAN.receive {
4250 repeat;
4251 }
4252 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004254 }
4255 }
4256}
4257
4258/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4259testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004260 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004261 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4262 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004263 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004264
4265 f_exp_err_rep(RSL_ERR_PROTO);
4266}
4267
4268/* Provoke a mandatory IE error and match on ERROR REPORT */
4269testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004270 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004271
4272 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4273 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004274 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004275
4276 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4277}
4278
4279/* Provoke an IE content error and match on ERROR REPORT */
4280testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004281 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004282 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4283 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004284 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004285
4286 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4287}
4288
Harald Welteee25aae2019-05-19 14:32:37 +02004289/* attempt to activate channel with wrong RSL Message Discriminator IE */
4290function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4291 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4292 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4293 RSL.send(rsl);
4294 f_rslem_unregister(0, g_chan_nr);
4295}
4296testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4297 var ConnHdlr vc_conn;
4298 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4299
Harald Welte10474062019-05-30 16:48:17 +02004300 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004301
4302 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4303 vc_conn.done;
4304 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4305
4306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4307}
4308
4309/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004310private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004311 var template (value) RSL_Message rsl_tx;
4312 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4313 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4314 RSL.send(rsl_tx);
4315 f_rslem_unregister(0, g_chan_nr);
4316}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004317private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004318 var template (value) RSL_Message rsl_tx;
4319 /* we first have to activate the dedicated channel */
4320 f_rsl_chan_act(g_pars.chan_mode);
4321 /* ... to then send an invalid RLL message */
4322 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4323 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4324 RSL.send(rsl_tx);
4325 f_rslem_unregister(0, g_chan_nr);
4326}
4327testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4328 var ConnHdlr vc_conn;
4329 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4330 var template (value) RSL_Message rsl_tx;
4331
Harald Welte10474062019-05-30 16:48:17 +02004332 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004333
4334 /* Common Channel with wrong message type */
4335 RSL_CCHAN.clear;
4336 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4337 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004338 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004339 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4340
4341 /* TRX Management */
4342 RSL_CCHAN.clear;
4343 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4344 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004345 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004346 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4347
4348 /* Dedicated Channel */
4349 RSL_CCHAN.clear;
4350 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4351 vc_conn.done;
4352 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4353
4354 /* RLL */
4355 RSL_CCHAN.clear;
4356 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4357 vc_conn.done;
4358 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4359}
4360
4361/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004362private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004363 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4364 f_rslem_unregister(0, g_chan_nr);
4365}
4366testcase TC_err_rep_wrong_sequence() runs on test_CT {
4367 var ConnHdlr vc_conn;
4368 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4369
Harald Welte10474062019-05-30 16:48:17 +02004370 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004371
4372 RSL_CCHAN.clear;
4373 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4374 vc_conn.done;
4375 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4376}
4377
Harald Welte93640c62018-02-25 16:59:33 +01004378/***********************************************************************
4379 * IPA CRCX/MDCX/DLCS media stream handling
4380 ***********************************************************************/
4381
Harald Weltea871a382018-02-25 02:03:14 +01004382/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004383private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004384 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4385 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004386}
4387testcase TC_ipa_dlcx_not_active() runs on test_CT {
4388 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004389 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004390 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4391 vc_conn.done;
4392}
Harald Welte68e495b2018-02-25 00:05:57 +01004393
Harald Weltea3f1df92018-02-25 12:49:55 +01004394/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004395private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004396 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4397 "IPA CRCX ACK");
4398 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4399 "IPA CRCX NACK");
4400}
4401testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4402 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004403 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004404 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4405 vc_conn.done;
4406}
4407
4408/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004409private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004410 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4411 "IPA CRCX ACK");
4412 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4413 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4414 var uint7_t rtp_pt2 := f_rnd_int(127);
4415 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4416 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4417 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4418 "IPA MDCX ACK");
4419 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4420 "IPA DLCX ACK");
4421}
4422testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4423 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004424 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004425 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4426 vc_conn.done;
4427}
4428
Harald Welte3ae11da2018-02-25 13:36:06 +01004429/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004430private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004431 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4432 "IPA CRCX ACK");
4433 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4434 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4435 var uint7_t rtp_pt2 := f_rnd_int(127);
4436 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4437 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4438 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4439 "IPA MDCX ACK");
4440 /* Second MDCX */
4441 remote_ip := f_rnd_int(c_UINT32_MAX);
4442 remote_port := f_rnd_int(c_UINT16_MAX);
4443 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4444 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4445 "IPA MDCX ACK");
4446 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4447 "IPA DLCX ACK");
4448}
4449testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4450 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004451 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004452 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4453 vc_conn.done;
4454}
4455
Harald Welte9912eb52018-02-25 13:30:15 +01004456/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004457private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004458 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4459 "IPA CRCX NACK");
4460}
4461testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4462 var ConnHdlrPars pars;
4463 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004464 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004465
4466 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4467 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4468 vc_conn.done;
4469
4470 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4471 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4472 vc_conn.done;
4473}
4474
Harald Weltea3f1df92018-02-25 12:49:55 +01004475
Harald Welte883340c2018-02-28 18:59:29 +01004476/***********************************************************************
4477 * PCU Socket related tests
4478 ***********************************************************************/
4479
Harald Welte07bd2d22019-05-25 11:03:30 +02004480/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004481friend 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 +01004482runs on test_CT {
4483 timer T := 3.0;
4484
4485 /* we don't expect any RTS.req before PDCH are active */
4486 T.start;
4487 alt {
4488 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004490 }
4491 [] PCU.receive { repeat; }
4492 [] T.timeout { }
4493 }
4494
4495 /* Send PDCH activate request for known PDCH timeslot */
4496 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4497
4498 /* we now expect RTS.req for this timeslot (only) */
4499 T.start;
4500 alt {
4501 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4502 setverdict(pass);
4503 }
4504 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4505 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004507 }
4508 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004510 }
4511 [] PCU.receive { repeat; }
4512 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004514 }
4515 [not exp_success] T.timeout {
4516 setverdict(pass);
4517 }
4518 }
4519}
4520
Harald Welte07bd2d22019-05-25 11:03:30 +02004521/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004522friend 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 +01004523runs on test_CT {
4524 timer T := 3.0;
4525
4526 /* Send PDCH activate request for known PDCH timeslot */
4527 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 +02004528 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4529 * when it will actually have been executed in the BTS */
4530 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004531 PCU.clear;
4532 /* we now expect no RTS.req for this timeslot */
4533 T.start;
4534 alt {
4535 [] 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 +02004536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004537 }
4538 [] PCU.receive { repeat; }
4539 [] T.timeout {
4540 setverdict(pass);
4541 }
4542 }
4543}
4544
Harald Weltead033dc2019-05-25 17:28:16 +02004545friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004546 f_init();
4547 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4548}
4549
Harald Welte883340c2018-02-28 18:59:29 +01004550/* PDCH activation via PCU socket; check for presence of RTS.req */
4551testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004552 f_init_pcu_test();
4553
Harald Welte883340c2018-02-28 18:59:29 +01004554 f_TC_pcu_act_req(0, 0, 7, true);
4555}
4556
4557/* PDCH activation via PCU socket on non-PDCU timeslot */
4558testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004559 f_init_pcu_test();
4560
Harald Welte883340c2018-02-28 18:59:29 +01004561 f_TC_pcu_act_req(0, 0, 1, false);
4562}
4563
4564/* PDCH activation via PCU socket on wrong BTS */
4565testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004566 f_init_pcu_test();
4567
Harald Welte883340c2018-02-28 18:59:29 +01004568 f_TC_pcu_act_req(23, 0, 7, false);
4569}
4570
4571/* PDCH activation via PCU socket on wrong TRX */
4572testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004573 f_init_pcu_test();
4574
Harald Welte883340c2018-02-28 18:59:29 +01004575 f_TC_pcu_act_req(0, 23, 7, false);
4576}
4577
4578/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4579testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004580 f_init_pcu_test();
4581
Harald Welte883340c2018-02-28 18:59:29 +01004582 /* Activate PDCH */
4583 f_TC_pcu_act_req(0, 0, 7, true);
4584 f_sleep(1.0);
4585 /* and De-Activate again */
4586 f_TC_pcu_deact_req(0, 0, 7);
4587}
4588
4589/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4590testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004591 f_init_pcu_test();
4592
Harald Welte883340c2018-02-28 18:59:29 +01004593 f_TC_pcu_deact_req(0, 0, 1);
4594}
4595
4596/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4597testcase TC_pcu_ver_si13() runs on test_CT {
4598 const octetstring si13 := '00010203040506070909'O;
4599 var PCUIF_send_data sd;
4600 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004601 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004602
4603 /* Set SI13 via RSL */
4604 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004605
Harald Welte883340c2018-02-28 18:59:29 +01004606 T.start;
4607 alt {
4608 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4609 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4610 setverdict(pass);
4611 } else {
4612 repeat;
4613 }
4614 }
4615 [] PCU.receive { repeat; }
4616 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004618 }
4619 }
4620}
4621
4622private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4623
4624/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004625friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004626 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4627runs on test_CT
4628{
4629 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4630 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4631}
4632
4633/* 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 +02004634friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4635 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004636runs on test_CT
4637{
4638 var PCUIF_send_data sd;
4639
4640 timer T := 3.0;
4641 T.start;
4642 alt {
4643 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4644 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4645 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4646 sd.data.u.rts_req.fn, sapi, data);
4647 }
4648 [] PCU.receive { repeat; }
4649 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004651 }
4652 }
4653}
4654
4655/* Send DATA.req on invalid BTS */
4656testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004657 var TfiUsfArr tua := f_TfiUsfArrInit();
4658 var octetstring data := '0000'O & f_rnd_octstring(21);
4659
4660 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004661
Harald Welte883340c2018-02-28 18:59:29 +01004662 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004663 f_TfiUsfArrSet(tua, 7, 0);
4664 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4665 f_sleep(1.0);
4666
4667 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004668}
4669
4670/* Send DATA.req on invalid TRX */
4671testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004672 var TfiUsfArr tua := f_TfiUsfArrInit();
4673 var octetstring data := '0000'O & f_rnd_octstring(21);
4674
4675 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004676
Harald Welte883340c2018-02-28 18:59:29 +01004677 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004678 f_TfiUsfArrSet(tua, 7, 0);
4679 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4680 f_sleep(1.0);
4681
4682 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004683}
4684
4685/* Send DATA.req on invalid timeslot */
4686testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004687 var TfiUsfArr tua := f_TfiUsfArrInit();
4688 var octetstring data := '0000'O & f_rnd_octstring(21);
4689
4690 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004691
Harald Welte883340c2018-02-28 18:59:29 +01004692 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004693 f_TfiUsfArrSet(tua, 7, 0);
4694 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4695 f_sleep(1.0);
4696
4697 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004698}
4699
4700/* Send DATA.req on timeslot that hasn't been activated */
4701testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004702 var TfiUsfArr tua := f_TfiUsfArrInit();
4703 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004704
Harald Welte7162a612019-05-26 12:56:09 +02004705 f_virtphy_common();
4706
4707 f_TfiUsfArrSet(tua, 7, 0);
4708 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4709 f_sleep(1.0);
4710
4711 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004712}
4713
Harald Weltead033dc2019-05-25 17:28:16 +02004714private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004715 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4716 boolean wait_rts := true)
4717runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004718 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004719 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004720
4721 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004722 if (wait_rts) {
4723 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4724 } else {
4725 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4726 }
Harald Weltead033dc2019-05-25 17:28:16 +02004727
4728 T.start;
4729 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004730 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004731 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4732 setverdict(pass);
4733 }
Harald Welte7162a612019-05-26 12:56:09 +02004734 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4735 setverdict(fail, "Received unexpected ", rx_dl);
4736 }
Harald Weltead033dc2019-05-25 17:28:16 +02004737 [] L1CTL.receive {
4738 repeat;
4739 }
Harald Welte7162a612019-05-26 12:56:09 +02004740 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004741 setverdict(fail, "Timeout waiting for ", data);
4742 }
Harald Welte7162a612019-05-26 12:56:09 +02004743 [not expect_data] T.timeout {
4744 setverdict(pass);
4745 }
Harald Weltead033dc2019-05-25 17:28:16 +02004746 }
4747}
4748
4749private function f_disable_dynamic_ts() runs on test_CT
4750{
4751 f_init_vty_bsc();
4752 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4753 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4754 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4755 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004756 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004757}
4758
4759private function f_virtphy_common() runs on test_CT {
4760 f_disable_dynamic_ts();
4761 f_init_l1ctl();
4762 f_l1_tune(L1CTL);
4763}
4764
4765testcase TC_pcu_data_req_pdtch() runs on test_CT {
4766 var TfiUsfArr tua := f_TfiUsfArrInit();
4767 var octetstring data := '0000'O & f_rnd_octstring(21);
4768
4769 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004770
Harald Welte883340c2018-02-28 18:59:29 +01004771 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004772 f_TfiUsfArrSet(tua, 7, 0);
4773 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4774 f_sleep(1.0);
4775
4776 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004777}
4778
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004779/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004780testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004781 var TfiUsfArr tua := f_TfiUsfArrInit();
4782 var octetstring data := '0000'O & f_rnd_octstring(21);
4783
4784 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004785
Harald Welte883340c2018-02-28 18:59:29 +01004786 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004787 f_TfiUsfArrSet(tua, 7, 0);
4788 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4789 f_sleep(1.0);
4790
4791 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004792}
4793
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004794private function f_TC_pcu_ptcch_ul(uint16_t ra)
4795runs on test_CT {
4796 var template PCUIF_Message pcu_rach_ind;
4797 var PCUIF_send_data sd;
4798 var GsmFrameNumber fn;
4799 timer T;
4800
4801 /* Send an Access Burst on PTCCH/U over the Um-interface */
4802 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4803 chan_nr := ts_RslChanNr_PDCH(7),
4804 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4805
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004806 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4807 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004808
4809 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4810 T.start(52.0 * 4.615 / 1000.0);
4811 alt {
4812 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4813 log("Rx an Access Burst on the PCU interface: ", sd.data);
4814 setverdict(pass);
4815 T.stop;
4816 }
4817 [] PCU.receive { repeat; }
4818 [] T.timeout {
4819 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4820 /* Keep going, that's not the end of the world */
4821 }
4822 }
4823}
4824
4825testcase TC_pcu_ptcch() runs on test_CT {
4826 var L1ctlDlMessage dl;
4827 var octetstring data;
4828 timer T;
4829
4830 f_init_pcu_test();
4831 f_init_l1ctl();
4832 f_l1_tune(L1CTL);
4833
4834 /* Activate PDCH channel on TS7 */
4835 f_TC_pcu_act_req(0, 0, 7, true);
4836
4837 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004838 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004839 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004840 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004841 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004842
4843 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4844 for (var integer i := 0; i < 16; i := i + 1) {
4845 log("Sending an Access Burst towards the L1CTL interface");
4846 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4847 }
4848
4849 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4850 data := f_rnd_octstring(23);
4851
4852 /* Verify PTCCH/D: send a random data block, make sure it's received */
4853 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4854 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4855
4856 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4857 * let's give it more time in case if we miss the beginning. */
4858 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4859 alt {
4860 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4861 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4862 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4863 frame := data)) -> value dl {
4864 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4865 setverdict(pass);
4866 T.stop;
4867 }
4868 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4869 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4870 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4871 l2_data := data)) -> value dl {
4872 log("Rx PTCCH/D data block on L1CTL: ", dl);
4873 setverdict(pass);
4874 T.stop;
4875 }
4876 [] L1CTL.receive { repeat; }
4877 [] T.timeout {
4878 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4879 }
4880 }
4881}
4882
Harald Welte883340c2018-02-28 18:59:29 +01004883/* Send AGCH from PCU; check it appears on Um side */
4884testcase TC_pcu_data_req_agch() runs on test_CT {
4885 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004886 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004887 f_init_l1ctl();
4888 f_l1_tune(L1CTL);
4889
4890 f_TC_pcu_act_req(0, 0, 7, true);
4891 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4892
4893 T.start;
4894 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004895 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004896 setverdict(pass);
4897 }
4898 [] L1CTL.receive { repeat; }
4899 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004901 }
4902 }
4903}
4904
Harald Welte928622b2019-05-26 13:22:59 +02004905/* Send AGCH from PCU; check it appears on Um side */
4906testcase TC_pcu_data_req_pch() runs on test_CT {
4907 timer T := 3.0;
4908 f_init_pcu_test();
4909 f_init_l1ctl();
4910 f_l1_tune(L1CTL);
4911
4912 f_TC_pcu_act_req(0, 0, 7, true);
4913 /* three characters prefix: last 3 digits of IMSI as ASCII */
4914 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4915
4916 T.start;
4917 alt {
4918 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4919 setverdict(pass);
4920 }
4921 [] L1CTL.receive { repeat; }
4922 [] T.timeout {
4923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4924 }
4925 }
4926}
4927
Harald Welte883340c2018-02-28 18:59:29 +01004928/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4929testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4930 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004931 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004932 f_init_l1ctl();
4933 f_l1_tune(L1CTL);
4934
4935 /* append 3 last imsi digits so BTS can compute pagng group */
4936 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4937
4938 timer T := 0.5;
4939 T.start;
4940 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004941 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004942 /* TODO: verify paging group */
4943 setverdict(pass);
4944 }
4945 [] L1CTL.receive { repeat; }
4946 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004948 }
4949 }
4950}
4951
4952/* Send RACH from Um side, expect it to show up on PCU socket */
4953testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004954 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004955 f_init_l1ctl();
4956 f_l1_tune(L1CTL);
4957
4958 var GsmFrameNumber fn_last := 0;
4959 for (var integer i := 0; i < 1000; i := i+1) {
4960 var OCT1 ra := f_rnd_ra_ps();
4961 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4962 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004964 }
4965 fn_last := fn;
4966
4967 timer T := 2.0;
4968 T.start;
4969 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004970 [] 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 +01004971 T.stop;
4972 }
4973 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004975 }
4976 [] PCU.receive { repeat; }
4977 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004979 }
4980 }
4981 }
4982 setverdict(pass);
4983}
4984
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004985/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4986 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4987testcase TC_pcu_ext_rach_content() runs on test_CT {
4988 var template PCUIF_Message pcu_rach_ind;
4989 var GsmFrameNumber fn_last := 0;
4990 var L1ctlRachSynchSeq synch_seq;
4991 var PCUIF_BurstType pcu_bt;
4992 var GsmFrameNumber fn;
4993 var BIT11 ra11;
4994
4995 f_init_pcu_test();
4996 f_init_l1ctl();
4997 f_l1_tune(L1CTL);
4998
4999 for (var integer i := 0; i < 1000; i := i+1) {
5000 /* We need to test both TS1 & TS2 */
5001 if (i rem 2 == 0) {
5002 synch_seq := RACH_SYNCH_SEQ_TS1;
5003 pcu_bt := BURST_TYPE_1;
5004 } else {
5005 synch_seq := RACH_SYNCH_SEQ_TS2;
5006 pcu_bt := BURST_TYPE_2;
5007 }
5008
5009 ra11 := f_rnd_ra11_ps();
5010 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5011 if (fn == fn_last) {
5012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5013 "Two RACH in same FN?!?");
5014 }
5015 fn_last := fn;
5016
5017 /* Compose the expected message */
5018 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005019 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005020 ra := bit2int(ra11),
5021 is_11bit := 1,
5022 burst_type := pcu_bt,
5023 fn := fn);
5024
5025 timer T := 2.0;
5026 T.start;
5027 alt {
5028 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5029 T.stop;
5030 }
5031 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5033 }
5034 [] PCU.receive { repeat; }
5035 [] T.timeout {
5036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5037 }
5038 }
5039 }
5040 setverdict(pass);
5041}
5042
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005043private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5044runs on test_CT {
5045 var template PCUIF_send_data sdt;
5046 var PCUIF_send_data sd;
5047 var int16_t lqual_cb;
5048 timer T := 1.0;
5049
5050 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5051 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5052
5053 /* Send a random PDTCH frame over Um */
5054 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5055 '0000'O & f_rnd_octstring(21)));
5056
5057 T.start;
5058 alt {
5059 /* If expected link quality is above the threshold */
5060 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5061 lqual_cb := sd.data.u.data_ind.lqual_cb;
5062 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5063
5064 /* Make sure the actual link quality matches the expected value */
5065 if (not match(lqual_cb, lqual_cb_exp)) {
5066 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5067 "expected value ", lqual_cb_exp));
5068 } else {
5069 setverdict(pass);
5070 }
5071 }
5072 /* If expected link quality is below the threshold */
5073 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5075 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5076 }
5077 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5078 [] PCU.receive { repeat; }
5079 [lqual_cb_exp < thresh] T.timeout {
5080 log("Rx nothing, as expected");
5081 setverdict(pass);
5082 }
5083 [lqual_cb_exp >= thresh] T.timeout {
5084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5085 "Timeout waiting for PCUIF_DATA.ind");
5086 }
5087 }
5088}
5089
5090/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5091testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5092 f_init_pcu_test();
5093 PCU.clear;
5094
5095 f_init_l1ctl();
5096 f_l1_tune(L1CTL);
5097
5098 /* Activate a PDCH channel on TS7 */
5099 f_TC_pcu_act_req(0, 0, 7, true);
5100
5101 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005102 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005103 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005104 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005105 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005106
5107 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5108 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5109 var TrxcMessage ret;
5110
5111 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5112 valueof(ts_TRXC_FAKE_CI(i)));
5113
5114 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5115 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5116 }
5117}
5118
Harald Welte883340c2018-02-28 18:59:29 +01005119/* Send PAGING via RSL, expect it to shw up on PCU socket */
5120testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005121 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005122
5123 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005124 var MobileIdentityLV mi_lv;
5125 var octetstring mi_lv_enc;
5126 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005127 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005128
Harald Welte883340c2018-02-28 18:59:29 +01005129 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005130 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005131 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005132 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005133 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005134
5135 /* Fancy encoding for PCUIF */
5136 mi_lv := valueof(ts_MI_LV(mi));
5137 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5138 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005139
5140 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005141 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005142 T.start;
5143 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005144 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005145 }
5146 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005148 }
5149 [] PCU.receive { repeat; }
5150 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005152 }
5153 }
5154 }
5155 setverdict(pass);
5156}
5157
Harald Welted66c9b82019-05-25 09:03:15 +02005158/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5159testcase TC_pcu_time_ind() runs on test_CT {
5160 var PCUIF_send_data pcu_sd;
5161 var integer num_time_ind := 0;
5162 var integer first_fn, last_fn;
5163 var float test_duration := 5.0;
5164 timer T;
5165
5166 f_init_pcu_test();
5167 f_TC_pcu_act_req(0, 0, 7, true);
5168
5169 PCU.clear;
5170 T.start(test_duration);
5171 alt {
5172 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5173 num_time_ind := num_time_ind + 1;
5174 if (not isbound(first_fn)) {
5175 first_fn := pcu_sd.data.u.time_ind.fn;
5176 }
5177 last_fn := pcu_sd.data.u.time_ind.fn;
5178 repeat;
5179 }
5180 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5181 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5182 repeat;
5183 }
5184 [] PCU.receive {
5185 repeat;
5186 }
5187 [] T.timeout {}
5188 }
5189 var integer fn_expired := last_fn - first_fn;
5190 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5191
5192 /* verify the number of frames expired matches our expectation */
5193 const float c_GSM_FN_DURATION_MS := 4.61538;
5194 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005195 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005196 if (not match(fn_expired, t_fn_expected)) {
5197 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5198 }
5199
5200 /* There are three TIME.ind in every fn MOD 13 */
5201 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5202 /* Add some tolerance */
5203 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5204 if (not match(num_time_ind, t_time_ind_exp)) {
5205 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5206 }
5207
5208 setverdict(pass);
5209}
5210
Harald Welte4832c862019-05-25 14:57:18 +02005211/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5212testcase TC_pcu_rts_req() runs on test_CT {
5213 var PCUIF_send_data pcu_sd;
5214 var integer first_fn, last_fn;
5215 var integer num_rts_pdtch := 0;
5216 var integer num_rts_ptcch := 0;
5217 var float test_duration := 5.0;
5218 timer T;
5219
5220 f_init_pcu_test();
5221 f_TC_pcu_act_req(0, 0, 7, true);
5222
5223 PCU.clear;
5224 T.start(test_duration);
5225 alt {
5226 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5227 -> value pcu_sd {
5228 num_rts_pdtch := num_rts_pdtch + 1;
5229 if (not isbound(first_fn)) {
5230 first_fn := pcu_sd.data.u.rts_req.fn;
5231 }
5232 last_fn := pcu_sd.data.u.rts_req.fn;
5233 repeat;
5234 }
5235 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5236 -> value pcu_sd {
5237 num_rts_ptcch := num_rts_ptcch + 1;
5238 if (not isbound(first_fn)) {
5239 first_fn := pcu_sd.data.u.rts_req.fn;
5240 }
5241 last_fn := pcu_sd.data.u.rts_req.fn;
5242 repeat;
5243 }
5244 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5245 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5246 repeat;
5247 }
5248 [] PCU.receive {
5249 repeat;
5250 }
5251 [] T.timeout {}
5252 }
5253 var integer fn_expired := last_fn - first_fn;
5254 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5255 ", num_rts_ptcch=", num_rts_ptcch);
5256
5257 /* verify the number of frames expired matches our expectation */
5258 const float c_GSM_FN_DURATION_MS := 4.61538;
5259 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005260 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005261 if (not match(fn_expired, t_fn_expected)) {
5262 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5263 }
5264
5265 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5266 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5267 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5268 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5269 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5270 t_ptcch_exp);
5271 }
5272
5273 /* We have 12 PDTCH blocks every 52-multiframe */
5274 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5275 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5276 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5277 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5278 t_pdtch_exp);
5279 }
5280
5281 setverdict(pass);
5282}
5283
Harald Welte07bd2d22019-05-25 11:03:30 +02005284/* test for generating Abis side OML ALERT from the PCU */
5285testcase TC_pcu_oml_alert() runs on test_CT {
5286 var PCUIF_send_data pcu_sd;
5287 var integer num_time_ind := 0;
5288 var integer first_fn, last_fn;
5289 var float test_duration := 5.0;
5290 timer T;
5291
5292 f_init_pcu_test();
5293 f_TC_pcu_act_req(0, 0, 7, true);
5294
5295 /* re-connect CTRL port from BTS to BSC */
5296 f_ipa_ctrl_stop();
5297 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5298
5299 /* Send that OML Alert */
5300 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5301
5302 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5303 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5304 setverdict(pass);
5305}
5306
Harald Welteeaa9a862019-05-26 23:01:08 +02005307/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5308private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5309 var PCUIF_Message first_info;
5310 var integer pcu_conn_id := -1;
5311 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5312 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5313 var OCT4 tlli := '01020304'O;
5314 var OCT1 cause := '23'O;
5315 timer T := 5.0;
5316
5317 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5318
5319 f_l1_tune(L1CTL);
5320 RSL.clear;
5321
5322 f_est_dchan();
5323 L1CTL.clear;
5324
5325 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5326
5327 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5328 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5329 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5330
5331 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5332 T.start;
5333 alt {
5334 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5335 setverdict(pass);
5336 }
5337 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5338 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5339 }
5340 [] PCU.receive {
5341 repeat;
5342 }
5343 [] T.timeout {
5344 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5345 }
5346 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005347
5348 /* release the channel */
5349 f_rsl_chan_deact();
5350 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5351 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005352}
5353testcase TC_pcu_rr_suspend() runs on test_CT {
5354 var ConnHdlrPars pars;
5355 var ConnHdlr vc_conn;
5356
5357 f_init();
5358
5359 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5360 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5361 vc_conn.done;
5362}
Harald Welte07bd2d22019-05-25 11:03:30 +02005363
Harald Weltea2e0e942019-05-27 18:12:53 +02005364/* Ensure that PCUIF socket can accept only a single connection */
5365testcase TC_pcu_socket_connect_multi() runs on test_CT {
5366 timer T := 5.0;
5367
5368 /* this (among other things) establishes the first connection to the PCUIF socket */
5369 f_init();
5370
5371 /* try to establish a second connection, expect it to fail */
5372 PCU.send(UD_connect:{mp_pcu_socket, -1});
5373 T.start;
5374 alt {
5375 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5376 setverdict(pass);
5377 }
5378 [] PCU.receive(UD_connect_result:?) {
5379 setverdict(fail, "Unexpected unix domain connect result");
5380 }
5381 [] T.timeout {
5382 setverdict(pass);
5383 }
5384 }
5385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5386}
5387
Harald Weltec8effb72019-05-27 18:23:04 +02005388/* Ensure that PCUIF socket can disconnect + reconnect */
5389testcase TC_pcu_socket_reconnect() runs on test_CT {
5390 /* this (among other things) establishes the first connection to the PCUIF socket */
5391 f_init();
5392
5393 f_sleep(1.0);
5394
5395 f_pcuif_close(PCU, g_pcu_conn_id);
5396 g_pcu_conn_id := -1;
5397
5398 f_sleep(1.0);
5399
5400 /* re-connect */
5401 PCU.clear;
5402 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5403 setverdict(pass);
5404
5405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5406}
5407
Harald Weltebe030482019-05-27 22:29:35 +02005408/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005409private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5410runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005411 var L1ctlDlMessage l1_dl;
5412 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005413 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005414 timer T := 5.0;
5415 T.start;
5416 alt {
5417 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005418 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5419 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005420 repeat;
5421 }
5422 }
5423 [] pt.receive {
5424 repeat;
5425 }
5426 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5428 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005429 }
5430 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005431 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005432}
5433
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005434/* Check if GPRS Indicator is present in RR System Information of a given type */
5435private function f_si_has_gprs_indicator(RrMessageType si_type)
5436runs on test_CT return boolean {
5437 var SystemInformation si := f_get_si(L1CTL, si_type);
5438
5439 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005440 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005441 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005442 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005443 }
5444
5445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5446 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005447}
5448
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005449/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5450private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5451runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005452 /* don't call f_init() as this would connect PCU socket */
5453 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005454
5455 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005456 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005457 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005458
5459 f_init_l1ctl();
5460 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005461 f_sleep(2.0);
5462 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005463
5464 if (f_si_has_gprs_indicator(si_type)) {
5465 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005466 } else {
5467 setverdict(pass);
5468 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005469
Harald Weltebe030482019-05-27 22:29:35 +02005470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5471}
5472
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005473testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5474 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5475}
Harald Weltebe030482019-05-27 22:29:35 +02005476
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005477testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5478 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5479}
5480
5481/* Ensure that GPRS capability is advertised after PCU socket connect */
5482private function f_TC_pcu_socket_connect(RrMessageType si_type)
5483runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005484 /* this (among other things) establishes the first connection to the PCUIF socket */
5485 f_init();
5486 f_init_l1ctl();
5487 f_l1_tune(L1CTL);
5488
5489 f_sleep(2.0);
5490 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005491
5492 if (not f_si_has_gprs_indicator(si_type)) {
5493 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005494 } else {
5495 setverdict(pass);
5496 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005497
Harald Weltebe030482019-05-27 22:29:35 +02005498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5499}
5500
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005501testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5502 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5503}
Harald Weltebe030482019-05-27 22:29:35 +02005504
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005505testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5506 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5507}
5508
5509/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5510private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5511runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005512 /* this (among other things) establishes the first connection to the PCUIF socket */
5513 f_init();
5514 f_init_l1ctl();
5515 f_l1_tune(L1CTL);
5516
5517 f_pcuif_close(PCU, g_pcu_conn_id);
5518 g_pcu_conn_id := -1;
5519
5520 f_sleep(1.0);
5521
5522 /* re-connect */
5523 PCU.clear;
5524 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5525
5526 f_sleep(2.0);
5527 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005528
5529 if (f_si_has_gprs_indicator(si_type)) {
5530 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005531 } else {
5532 setverdict(pass);
5533 }
5534
5535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5536}
5537
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005538testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5539 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5540}
5541
5542testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5543 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5544}
5545
Oliver Smithf5239c72019-08-28 10:01:25 +02005546/* 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) */
5547testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5548 var SystemInformation si3 := valueof(ts_SI3_default);
5549
5550 f_init();
5551
Harald Welte76220222020-10-11 20:32:44 +02005552 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5553 * information */
5554 timer T := 2.0;
5555 T.start;
5556 alt {
5557 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5558 [] T.timeout {}
5559 }
5560
Oliver Smithf5239c72019-08-28 10:01:25 +02005561 /* Verify cell_id */
5562 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5563 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5564 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005565 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5566 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5567 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005568 }
5569
5570 /* Verify LAC */
5571 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5572 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5573 if (lac_si3 != lac_pcu) {
5574 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5575 }
5576
5577 setverdict(pass);
5578}
Harald Welted66c9b82019-05-25 09:03:15 +02005579
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005580/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5581testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5582 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005583 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005584
5585 f_init();
5586
5587 info_ind := g_pcu_last_info.u.info_ind;
5588
5589 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5590 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5591 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5592 /* Skip inactive timeslots */
5593 continue;
5594 }
5595
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005596 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005597 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005598 else
5599 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005600
5601 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005602 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005603 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005604 hsn := fhp.maio_hsn.hsn,
5605 maio := fhp.maio_hsn.maio,
5606 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005607 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005608 } else {
5609 tr_ts := tr_PCUIF_InfoTrxTsH0;
5610 }
5611
5612 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5613 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5614 if (not match(ts, tr_ts)) {
5615 setverdict(fail, "Hopping parameters do not match: ",
5616 "received ", ts, " vs expected ", tr_ts);
5617 } else {
5618 setverdict(pass);
5619 }
5620 }
5621 }
5622}
5623
Alexander Couzens5283f552020-07-28 15:39:04 +02005624/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5625testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5626 f_init_vty_bsc();
5627 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5628 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5629
5630 f_init();
5631
5632 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5633 if (not ischosen(remote_addr.v10)) {
5634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5635 log2str("Unexpected remote_addr: ", remote_addr));
5636 }
5637
5638 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5639 setverdict(fail, "Received address family is not IPv4");
5640 }
5641
5642 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5643 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5644 }
5645
5646 setverdict(pass);
5647}
5648
5649/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5650testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5651 f_init_vty_bsc();
5652 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5653
5654 f_init();
5655
5656 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5657 if (not ischosen(remote_addr.v10)) {
5658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5659 log2str("Unexpected remote_addr: ", remote_addr));
5660 }
5661
5662 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5663 setverdict(fail, "Received address family is not IPv6");
5664 }
5665
5666 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5667 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5668 }
5669
5670 setverdict(pass);
5671}
5672
Harald Welte3d04ae62018-04-04 20:29:05 +02005673/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005674 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005675 ***********************************************************************/
5676
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005677private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5678 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005679runs on ConnHdlr {
5680 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005681
5682 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005683 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005684 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5685 repeat;
5686 }
5687 }
5688}
5689
5690private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5691runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005692 /* Expect BTS to immediately acknowledge activation as PDCH */
5693 PCU.clear;
5694 f_rsl_chan_act(g_pars.chan_mode);
5695 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005696 timer T_wait := 2.0;
5697 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005698 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005699 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005700 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005701 [] T_wait.timeout {
5702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5703 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5704 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005705 }
5706 /* try to activate this PDCH from the PCU point of view */
5707 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5708 /* FIXME: is there a response? */
5709}
5710
5711private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5712runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005713 /* Send RSL CHAN REL (deactivate) */
5714 PCU.clear;
5715 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5716 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005717 timer T_wait := 2.0;
5718 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005719 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005720 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005721 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005722 [] T_wait.timeout {
5723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5724 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5725 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005726 }
5727 /* Emulate PCU asking BTS to deactivate PDCH */
5728 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5729 alt {
5730 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5731 setverdict(pass);
5732 }
5733 [] RSL.receive { repeat; }
5734 }
5735}
5736
5737/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005738private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005739 var PCUIF_Message first_info;
5740 var integer ts_nr := g_chan_nr.tn;
5741 var integer trx_nr := 0;
5742 var integer bts_nr := 0;
5743 var integer pcu_conn_id := -1;
5744
5745 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5746
5747 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5748 f_sleep(3.0);
5749 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5750 setverdict(pass);
5751}
5752testcase TC_dyn_osmo_pdch_act_deact() 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_act_deact), pars, true);
5759 vc_conn.done;
5760}
5761
5762/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005763private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005764 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005765 var integer pcu_conn_id := -1;
5766
5767 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5768
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005769 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5770 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5771 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005772 setverdict(pass);
5773}
5774testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5775 var ConnHdlrPars pars;
5776 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005777 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005778
5779 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5780 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5781 vc_conn.done;
5782}
5783
5784/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005785private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005786 var PCUIF_Message first_info;
5787 var integer ts_nr := g_chan_nr.tn;
5788 var integer trx_nr := 0;
5789 var integer bts_nr := 0;
5790 var integer pcu_conn_id := -1;
5791
5792 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5793
5794 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005795 /* Send a second Chan Activ and expect it to be NACKed */
5796 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5797 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005798 setverdict(pass);
5799}
5800testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5801 var ConnHdlrPars pars;
5802 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005803 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005804
5805 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5806 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5807 vc_conn.done;
5808}
5809
5810/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005811private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005812 var PCUIF_Message first_info;
5813 var integer ts_nr := g_chan_nr.tn;
5814 var integer trx_nr := 0;
5815 var integer bts_nr := 0;
5816 var integer pcu_conn_id := -1;
5817 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5818
5819 /* register for the TCH/F channel number */
5820 f_rslem_register(0, chan_nr);
5821
5822 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5823
5824 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5825 "RSL CHAN ACT");
5826 setverdict(pass);
5827}
5828testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5829 var ConnHdlrPars pars;
5830 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005831 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005832
5833 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5834 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5835 vc_conn.done;
5836}
5837
5838/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005839private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005840 var PCUIF_Message first_info;
5841 var integer ts_nr := g_chan_nr.tn;
5842 var integer trx_nr := 0;
5843 var integer bts_nr := 0;
5844 var integer pcu_conn_id := -1;
5845 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5846 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5847
5848 /* register for the TCH/H channel numbers */
5849 f_rslem_register(0, chan_nr[0]);
5850 f_rslem_register(0, chan_nr[1]);
5851
5852 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5853
5854 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5855 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5856 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5857 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5858 setverdict(pass);
5859}
5860testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5861 var ConnHdlrPars pars;
5862 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005863 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005864
5865 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5866 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5867 vc_conn.done;
5868}
5869
Harald Welte9bbbfb52018-04-05 09:33:19 +02005870/***********************************************************************
5871 * IPA Style Dynamic Timeslot Support
5872 ***********************************************************************/
5873
5874private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5875runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005876 /* Expect BTS to immediately acknowledge activation as PDCH */
5877 PCU.clear;
5878 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5879 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005880 timer T_wait := 2.0;
5881 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005882 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005883 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005884 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005885 [] T_wait.timeout {
5886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5887 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5888 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005889 }
5890 /* try to activate this PDCH from the PCU point of view */
5891 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5892 /* FIXME: is there a response? */
5893
5894 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5895}
5896
5897private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5898runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005899 /* Send RSL CHAN REL (deactivate) */
5900 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5901 PCU.clear;
5902 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005903 timer T_wait := 2.0;
5904 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005905 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005906 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005907 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005908 [] T_wait.timeout {
5909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5910 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5911 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005912 }
5913 /* Emulate PCU asking BTS to deactivate PDCH */
5914 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5915 alt {
5916 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5917 setverdict(pass);
5918 }
5919 [] RSL.receive { repeat; }
5920 }
5921}
5922
5923/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005924private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005925 var PCUIF_Message first_info;
5926 var integer ts_nr := g_chan_nr.tn;
5927 var integer trx_nr := 0;
5928 var integer bts_nr := 0;
5929 var integer pcu_conn_id := -1;
5930
5931 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5932
5933 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5934 f_sleep(3.0);
5935 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5936
5937 setverdict(pass);
5938
5939}
5940testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5941 var ConnHdlrPars pars;
5942 var ConnHdlr vc_conn;
5943 f_init();
5944
5945 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5946 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5947 vc_conn.done;
5948}
5949
5950/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005951private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005952 var PCUIF_Message first_info;
5953 var integer ts_nr := g_chan_nr.tn;
5954 var integer trx_nr := 0;
5955 var integer bts_nr := 0;
5956 var integer pcu_conn_id := -1;
5957
5958 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5959
5960 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5961 "RSL CHAN ACT");
5962 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5963 "RF CHAN REL", true);
5964 setverdict(pass);
5965}
5966testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5967 var ConnHdlrPars pars;
5968 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005969 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005970
5971 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5972 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5973 vc_conn.done;
5974}
5975
5976/* 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 +07005977private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005978 var PCUIF_Message first_info;
5979 var integer ts_nr := g_chan_nr.tn;
5980 var integer trx_nr := 0;
5981 var integer bts_nr := 0;
5982 var integer pcu_conn_id := -1;
5983
5984 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5985
5986 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5987 "RSL CHAN ACT");
5988
5989 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5990 alt {
5991 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5992 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005994 }
5995 [] RSL.receive { repeat; }
5996 }
5997
5998 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5999 "RF CHAN REL", true);
6000 setverdict(pass);
6001}
6002testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6003 var ConnHdlrPars pars;
6004 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006005 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006006
6007 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6008 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6009 vc_conn.done;
6010}
6011
6012/* 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 +07006013private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006014 var PCUIF_Message first_info;
6015 var integer ts_nr := g_chan_nr.tn;
6016 var integer trx_nr := 0;
6017 var integer bts_nr := 0;
6018 var integer pcu_conn_id := -1;
6019
6020 /* register for the TCH/F channel number */
6021 f_rslem_register(0, g_chan_nr);
6022
6023 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6024
6025 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6026
6027 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6028 "RSL CHAN ACT");
6029
6030 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6031
6032 setverdict(pass);
6033}
6034testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6035 var ConnHdlrPars pars;
6036 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006037 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006038
6039 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6040 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6041 vc_conn.done;
6042}
6043
6044
Harald Welte0472ab42018-03-12 15:02:26 +01006045/***********************************************************************
6046 * LAPDm / RLL related
6047 ***********************************************************************/
6048
6049private function f_tx_lapdm(template (value) LapdmFrame l,
6050 template (value) RslLinkId link_id) runs on ConnHdlr {
6051 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006052 var template (value) SacchL1Header l1h;
6053
6054 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006055 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006056 /* Compose dummy L1 header */
6057 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6058 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 +02006059 } else {
6060 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006061 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 +01006062 }
Harald Welte0472ab42018-03-12 15:02:26 +01006063}
6064
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006065private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006066 uint3_t sapi,
6067 RslLinkId link_id,
6068 octetstring l3,
6069 boolean exp
6070}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006071private type record of RllTestCase RllTestCases;
6072private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6073 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006074 sapi := sapi,
6075 link_id := id,
6076 l3 := l3,
6077 exp := exp
6078}
6079
6080/* execute the same callback function with a set of different parameters (tcs) on a
6081 * variety of logical channels */
6082private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6083 var ConnHdlrPars pars;
6084 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006085 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006086
6087 /* test on each of the channels we have */
6088 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6089 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6090
6091 /* test each of the test cases on the current channel */
6092 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6093 pars.spec.rll := tcs[j];
6094 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6095 vc_conn := f_start_handler(fn, pars);
6096 vc_conn.done;
6097 }
6098 }
6099
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006101}
6102
6103/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6104private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6105 var RllTestCase tc := g_pars.spec.rll;
6106 timer T := 3.0;
6107
6108 f_l1_tune(L1CTL);
6109 RSL.clear;
6110
6111 /* activate the logical channel */
6112 f_est_dchan();
6113 L1CTL.clear;
6114
6115 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6116 T.start;
6117 alt {
6118 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6119 if (tc.exp) {
6120 setverdict(pass);
6121 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006123 }
6124 }
6125 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6126 if (tc.exp) {
6127 setverdict(pass);
6128 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006130 }
6131 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006132 /* We also expect to receive the measurements */
6133 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006134 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006136 }
6137 [not tc.exp] T.timeout {
6138 setverdict(pass);
6139 }
6140 }
6141
6142 f_rsl_chan_deact();
6143 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6144 f_rslem_unregister(0, g_chan_nr);
6145}
6146testcase TC_rll_est_ind() runs on test_CT {
6147 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006148 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006149 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006150 /* normal SAPI0 establishment */
6151 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006152 /* SAPI 3 doesn't support contention resolution */
6153 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6154 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6155 /* normal SAPI3 establishment on main DCCH */
6156 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6157 /* normal SAPI3 establishment on SACCH */
6158 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6159 };
6160 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6161}
6162
6163/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6164private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6165 var RllTestCase tc := g_pars.spec.rll;
6166 var L1ctlDlMessage dl;
6167 timer T := 3.0;
6168
6169 f_l1_tune(L1CTL);
6170 RSL.clear;
6171
6172 /* activate the logical channel */
6173 f_est_dchan();
6174 L1CTL.clear;
6175
6176 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6177 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6178 T.start;
6179 alt {
6180 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6181 var LapdmFrame lapdm;
6182 var octetstring l2 := dl.payload.data_ind.payload;
6183 if (dl.dl_info.link_id.c == SACCH) {
6184 /* remove L1 header */
6185 l2 := substr(l2, 2, lengthof(l2)-2);
6186 }
6187 lapdm.ab := dec_LapdmFrameAB(l2);
6188 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6189 setverdict(pass);
6190 } else {
6191 repeat;
6192 }
6193 }
6194 [] L1CTL.receive { repeat; }
6195 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006197 }
6198 }
6199
6200 f_rsl_chan_deact();
6201 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6202 f_rslem_unregister(0, g_chan_nr);
6203}
6204testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6205 var RllTestCases tcs := {
6206 /* normal SAPI3 establishment on main DCCH */
6207 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6208 };
6209 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6210}
6211testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6212 var RllTestCases tcs := {
6213 /* normal SAPI3 establishment on SACCH */
6214 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6215 }
6216 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6217}
6218
6219/* altstep to receive a LAPDm frame matching the given template */
6220private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6221 var L1ctlDlMessage dl;
6222 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6223 var LapdmFrame lapdm;
6224 var octetstring l2 := dl.payload.data_ind.payload;
6225 if (dl.dl_info.link_id.c == SACCH) {
6226 /* remove L1 header */
6227 l2 := substr(l2, 2, lengthof(l2)-2);
6228 }
6229 if (ischosen(exp.ab)) {
6230 lapdm.ab := dec_LapdmFrameAB(l2);
6231 } else if (ischosen(exp.b4)) {
6232 lapdm.b4 := dec_LapdmFrameB4(l2);
6233 } else if (ischosen(exp.bbis)) {
6234 lapdm.bbis := dec_LapdmFrameBbis(l2);
6235 }
6236 log("Rx LAPDm ", lapdm);
6237 if (match(lapdm, exp)) {
6238 setverdict(pass);
6239 } else {
6240 repeat;
6241 }
6242 }
6243 [] L1CTL.receive { repeat; }
6244}
6245private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6246 timer T := t;
6247 T.start;
6248 alt {
6249 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006251 }
6252 [] as_l1_exp_lapdm(exp);
6253 }
6254}
6255
6256/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6257private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6258 /* send SABM from MS -> BTS */
6259 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6260 /* expect RLL EST IND on Abis */
6261 alt {
6262 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6263 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6264 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006266 }
6267 [] RSL.receive { repeat; }
6268 }
6269 /* expect UA from BTS -> MS */
6270 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6271}
6272
6273/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6274private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6275 var RllTestCase tc := g_pars.spec.rll;
6276
6277 f_l1_tune(L1CTL);
6278 RSL.clear;
6279
6280 /* activate the logical channel */
6281 f_est_dchan();
6282 L1CTL.clear;
6283
6284 /* first establish the link-layer */
6285 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6286
6287 /* then send the DISC */
6288 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6289 /* ... and expect the REL IND on the RSL side */
6290 alt {
6291 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6292 setverdict(pass);
6293 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006294 /* We also expect to receive the measurements */
6295 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006296 }
6297
6298 /* release the channel */
6299 f_rsl_chan_deact();
6300 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6301 f_rslem_unregister(0, g_chan_nr);
6302}
6303testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6304 var RllTestCases tcs := {
6305 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6306 };
6307 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6308}
6309
6310testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6311 var RllTestCases tcs := {
6312 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6313 };
6314 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6315}
6316testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6317 var RllTestCases tcs := {
6318 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6319 };
6320 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6321}
6322testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6323 var RllTestCases tcs := {
6324 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6325 };
6326 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6327}
6328
6329/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6330private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6331 var RllTestCase tc := g_pars.spec.rll;
6332 f_l1_tune(L1CTL);
6333 RSL.clear;
6334
6335 /* activate the logical channel */
6336 f_est_dchan();
6337 L1CTL.clear;
6338
6339 /* first establish the link-layer */
6340 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6341
6342 /* then send the REL REQ via RSL */
6343 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6344 /* ... and expect the DISC on the Um side */
6345 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006346 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006347 /* FIXME: send a UA in resposne to the DISC */
6348 }
6349 }
6350
6351 /* release the channel */
6352 f_rsl_chan_deact();
6353 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6354 f_rslem_unregister(0, g_chan_nr);
6355}
6356testcase TC_rll_rel_req() runs on test_CT {
6357 var RllTestCases tcs := {
6358 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6359 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6360 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6361 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6362 };
6363 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6364}
6365
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006366/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006367testcase TC_rll_data_req() runs on test_CT {
6368}
6369
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006370/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006371testcase TC_rll_data_ind() runs on test_CT {
6372}
6373
6374/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6375private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6376 var RllTestCase tc := g_pars.spec.rll;
6377
6378 f_l1_tune(L1CTL);
6379 RSL.clear;
6380
6381 f_est_dchan();
6382 L1CTL.clear;
6383
6384 /* Send UNITDATA REQ on RSL side */
6385 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6386 /* Expect it to arrive on the other side */
6387 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006388 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006389 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006390 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006391 }
6392
6393 /* release the channel */
6394 f_rsl_chan_deact();
6395 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6396 f_rslem_unregister(0, g_chan_nr);
6397}
6398testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6399 var octetstring l3 := f_rnd_octstring(15);
6400 var RllTestCases tcs := {
6401 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6402 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6403 };
6404 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6405}
6406testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6407 var octetstring l3 := f_rnd_octstring(19);
6408 var RllTestCases tcs := {
6409 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6410 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6411 };
6412 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6413}
6414
6415/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6416private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6417 var RllTestCase tc := g_pars.spec.rll;
6418
6419 f_l1_tune(L1CTL);
6420 RSL.clear;
6421
6422 f_est_dchan();
6423 L1CTL.clear;
6424
6425 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006426 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006427 /* Expdct RLL UNITDATA IND on RSL side */
6428 alt {
6429 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6430 setverdict(pass);
6431 }
6432 [] RSL.receive { repeat; }
6433 }
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_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006441 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006442 var RllTestCases tcs := {
6443 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6444 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6445 };
6446 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6447}
6448testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6449 var octetstring l3 := f_rnd_octstring(18);
6450 var RllTestCases tcs := {
6451 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6452 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6453 };
6454 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6455}
6456
Harald Weltee613f962018-04-18 22:38:16 +02006457/***********************************************************************
6458 * Encryption Related
6459 ***********************************************************************/
6460
6461/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006462private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006463 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6464 if (link_id.c == SACCH) {
6465 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6466 } else {
6467 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6468 }
6469}
6470
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006471/* Expect (or not expect) other kinds of messages */
6472private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6473 [exp_any] RSL.receive { repeat; }
6474 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006476 }
6477}
6478
Harald Weltee613f962018-04-18 22:38:16 +02006479/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006480private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006481 RslLinkId link_id,
6482 octetstring l3,
6483 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006484 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006485) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006486 timer T := 3.0;
6487 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6488 T.start;
6489 /* Expect RLL UNITDATA IND on RSL side */
6490 alt {
6491 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6492 setverdict(pass);
6493 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006494 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006495 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006496 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006498 }
Harald Weltee613f962018-04-18 22:38:16 +02006499 }
6500}
6501
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006502/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6503private function f_data_mo(
6504 RslLinkId link_id,
6505 boolean p, uint3_t nr, uint3_t ns,
6506 octetstring l3,
6507 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006508 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006509) runs on ConnHdlr {
6510 timer T := 3.0;
6511 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6512 T.start;
6513 /* Expect RLL DATA IND on RSL side */
6514 alt {
6515 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6516 setverdict(pass);
6517 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006518 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006519 [] as_rsl_any_ind(exp_any);
6520 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006522 }
6523 }
6524}
6525
Harald Weltee613f962018-04-18 22:38:16 +02006526/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006527private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006528 f_l1_tune(L1CTL);
6529 f_est_dchan(true);
6530
6531 /* now we actually need to transmit some data both ways to check if the encryption works */
6532 var L1ctlDlMessage dl;
6533
Stefan Sperling603d98e2018-07-25 16:47:28 +02006534 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006535 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6536
6537 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6538 f_unitdata_mt(link_id, l3);
6539
6540 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6541 f_unitdata_mo(link_id, l3);
6542
6543 /* release the channel */
6544 f_rsl_chan_deact();
6545 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6546 f_rslem_unregister(0, g_chan_nr);
6547}
6548testcase TC_chan_act_a51() runs on test_CT {
6549 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6550 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6551 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6552}
6553testcase TC_chan_act_a52() runs on test_CT {
6554 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6555 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6556 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6557}
6558testcase TC_chan_act_a53() runs on test_CT {
6559 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6560 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6561 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6562}
6563
Eric Wildf1827a72019-05-28 17:37:35 +02006564/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6565 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 +07006566private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006567 f_l1_tune(L1CTL);
6568 f_est_dchan(true);
6569
6570 /* now we actually need to transmit some data both ways to check if the encryption works */
6571 var L1ctlDlMessage dl;
6572
6573 var octetstring l3 := f_rnd_octstring(20);
6574 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6575
6576 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6577 f_unitdata_mt(link_id, l3);
6578
6579 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6580 f_unitdata_mo(link_id, l3);
6581
6582 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006583 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006584
6585 /* modify key to break proper encryption */
6586 g_pars.encr.key := f_rnd_octstring(8);
6587 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6588 rsl.ies := rsl.ies & { ei };
6589 RSL.send(rsl);
6590
6591 timer T0 := 1.0;
6592 T0.start;
6593 /* Expect RSL MODIFY ACK */
6594 alt {
6595 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6596 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6598 }
6599 [] T0.timeout {
6600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6601 }
6602 }
6603
6604 var octetstring l3msg := f_rnd_octstring(15);
6605 timer T1 := 3.0;
6606 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6607 due to broken encryption */
6608 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6609 T1.start;
6610 alt {
6611 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6612 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6613 }
6614 [] T1.timeout {
6615 setverdict(pass);
6616 }
6617 }
6618
6619 /* release the channel */
6620 f_rsl_chan_deact();
6621 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6622 f_rslem_unregister(0, g_chan_nr);
6623}
6624testcase TC_rsl_modify_encr() runs on test_CT {
6625 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6626 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6627 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6628}
Harald Weltee613f962018-04-18 22:38:16 +02006629
6630/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006631private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006632 /* L3 payload doesn't matter, as it is passed transparently */
6633 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6634 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6635 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6636
6637 f_l1_tune(L1CTL);
6638
6639 /* first establish a dedicated channel in the clear */
6640 f_est_dchan(false);
6641
6642 /* Establish ABM */
6643 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6644
6645 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6646 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6647 /* expect the L3 to arrive still unencrypted on the MS side */
6648 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6649
6650 /* configure L1 to apply ciphering */
6651 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6652 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6653
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006654 /* send first ciphered I-frame in response and expect it on RSL */
6655 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006656
6657 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6658 * and hence enable encryption also on the downlink */
6659
6660 /* expect bi-directional communication work in encrypted mode */
6661 f_unitdata_mo(link_id, f_rnd_octstring(15));
6662 f_unitdata_mt(link_id, f_rnd_octstring(15));
6663
6664 /* release the channel */
6665 f_rsl_chan_deact();
6666 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6667 f_rslem_unregister(0, g_chan_nr);
6668}
6669testcase TC_encr_cmd_a51() runs on test_CT {
6670 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6671 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6672 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6673}
6674testcase TC_encr_cmd_a52() runs on test_CT {
6675 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6676 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6677 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6678}
6679testcase TC_encr_cmd_a53() runs on test_CT {
6680 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6681 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6682 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6683}
6684
6685private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6686 var LapdmFrame lf;
6687 var octetstring reenc;
6688
6689 /* decode the LAPDm frame */
6690 if (ischosen(exp_match.ab)) {
6691 lf.ab := dec_LapdmFrameAB(enc);
6692 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006694 }
6695
6696 /* check if decoder result matches expectation */
6697 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006699 } else {
6700 log(name, ": matched");
6701 setverdict(pass);
6702 }
6703
6704 /* test if re-encoded frame equals original input */
6705 reenc := enc_LapdmFrame(lf);
6706 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006708 } else {
6709 setverdict(pass);
6710 }
6711}
6712
6713testcase TC_lapdm_selftest() runs on test_CT {
6714 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6715 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6716 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6717 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6718 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6719 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6720 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6721}
6722
Stefan Sperling4880be42018-08-07 18:12:59 +02006723/***********************************************************************
6724 * DTX Related (see GSM 05.08, section 8.3)
6725 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006726private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006727 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006728 var GsmFrameNumber first_fn;
6729 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006730 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006731 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006732 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6733 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006734 const integer frame_dtx_tchf_mod := 104;
6735 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6736 * which operates in terms of blocks rather than frames. */
6737 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6738 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006739 timer T := 5.0;
6740
6741 f_l1_tune(L1CTL);
6742 RSL.clear;
6743 L1CTL.clear;
6744
6745 /* activate TCHF signalling channel */
6746 f_est_dchan(false);
6747
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006748 /* A template for matching dummy LAPDm func=UA frames */
6749 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6750 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6751 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6752
Stefan Sperling4880be42018-08-07 18:12:59 +02006753 T.start;
6754 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006755 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006756 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006757
6758 if (is_first_frame) {
6759 is_first_frame := false;
6760 first_fn := dl.dl_info.frame_nr;
6761 }
6762
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006763 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006764 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006765 T.stop;
6766 f_rsl_chan_deact();
6767 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006768
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006769 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6770 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006771
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006772 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006773 setverdict(fail, "Not enough fill frames received: ",
6774 nfill_frames, " out of ", expected_fill_frames);
6775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006776 } else {
6777 setverdict(pass);
6778 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006779 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006780 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6781 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6782 * we should only see the subset of frames numbers which correspond to a block boundary.
6783 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6784 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6785 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006786 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006787 repeat;
6788 }
6789 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006790 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6791 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6792 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006793 f_rsl_chan_deact();
6794 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006795 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006796 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006797 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006798 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006799 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006800
6801 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006802 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6803 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006804 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6805 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6806 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006807 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6808 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006809 case else {
6810 /* This shall not happen, just to be sure */
6811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6812 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006813 }
6814
6815 f_rsl_chan_deact();
6816 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006817
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006818 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006819 setverdict(pass);
6820 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006821 setverdict(fail, "Not enough fill frames received: ",
6822 nfill_frames, " out of ", expected_fill_frames);
6823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006824 }
6825 } else {
6826 repeat;
6827 }
6828 }
6829 }
6830 [] L1CTL.receive { repeat; }
6831 [] T.timeout {
6832 f_rsl_chan_deact();
6833 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006835 }
6836 }
6837}
6838
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006839private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006840 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006841 var ConnHdlr vc_conn;
6842 var ConnHdlrPars pars;
6843 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006844 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006845 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006846 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006847 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006848 if (dtxd) {
6849 if (i >= 4) { /* DTX is only allowed on TCH/F */
6850 break;
6851 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006852 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006853 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006854 vc_conn.done;
6855 }
6856}
6857
6858/* Verify that L2 fill frames are sent on TCH in signaling mode if
6859 * there is nothing to transmit while DTX is disabled on downlink. */
6860testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6861 f_tch_sign_l2_fill_frame(false);
6862}
6863
6864/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6865 * there is nothing to transmit while DTX is enabled on downlink. */
6866testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6867 f_tch_sign_l2_fill_frame(true);
6868}
Harald Welte0472ab42018-03-12 15:02:26 +01006869
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006870testcase TC_chopped_ipa_ping() runs on test_CT {
6871 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6872}
6873
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006874testcase TC_chopped_ipa_payload() runs on test_CT {
6875 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6876}
6877
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006878
6879/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6880 * Return value: Measurement Report to be sent (encoded octetstring). */
6881type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6882 runs on ConnHdlr return octetstring;
6883
6884private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6885runs on ConnHdlr {
6886 var L1ctlDlMessage l1_dl;
6887 var SacchL1Header l1h;
6888 var octetstring l2;
6889
6890 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6891 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6892 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6893 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6894
6895 /* Pass it to the user specified call-back function */
6896 l2 := cb.apply(l1h, num_blocks);
6897 /* Send a Measurement Report generated by the call-back */
6898 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6899 l1_dl.dl_info.link_id,
6900 l1h, l2));
6901
6902 /* Shall we keep going? */
6903 num_blocks := num_blocks - 1;
6904 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6905 if (num_blocks > 0) { repeat; }
6906 }
6907 [] L1CTL.receive { repeat; }
6908}
6909
6910private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6911runs on ConnHdlr return octetstring {
6912 /* Command the L1 to apply received parameters */
6913 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6914
6915 /* Dummy measurement report (the results are invalid) */
6916 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6917}
6918
6919private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6920runs on ConnHdlr return octetstring {
6921 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6922 setverdict(fail, "Unexpected MS Power level change: ",
6923 g_pars.l1_pars.ms_power_level, " -> ",
6924 l1h.ms_power_lvl);
6925 }
6926
6927 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6928}
6929
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006930private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6931runs on ConnHdlr return octetstring {
6932 /* UL RSSI oscillation driven by SACCH block number */
6933 if (num_blocks rem 2 == 0) {
6934 f_trxc_fake_rssi(-100);
6935 } else {
6936 f_trxc_fake_rssi(-50);
6937 }
6938
6939 /* Make sure that MS power level remains constant */
6940 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6941}
6942
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006943/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6944private function f_TC_ms_pwr_ctrl_constant(charstring id)
6945runs on ConnHdlr {
6946 var integer num_blocks := 8;
6947 timer T := int2float(num_blocks);
6948
6949 f_l1_tune(L1CTL);
6950 RSL.clear;
6951
6952 /* These IEs are needed for autonomous MS power control */
6953 var template (value) RSL_IE_List ies := {
6954 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6955 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6956 }),
6957 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6958 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6959 })
6960 };
6961
6962 /* Ensure that 'rx-current' equals 'rx-target' */
6963 f_trxc_fake_rssi(mp_uplink_power_target);
6964
6965 /* Establish a dedicated channel */
6966 f_est_dchan(more_ies := valueof(ies));
6967
6968 L1CTL.clear;
6969 T.start;
6970 alt {
6971 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6972 [] T.timeout {
6973 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6974 num_blocks, " were not handled");
6975 }
6976 }
6977}
6978testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6979 var ConnHdlr vc_conn;
6980 var ConnHdlrPars pars;
6981
6982 f_init();
6983
6984 /* Explicitly configure the Uplink power target (in dBm) */
6985 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6986
6987 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6988 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6989 log(testcasename(), ": starting on ", pars.chan_nr);
6990
6991 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6992 pars, trxc_comp := true);
6993 vc_conn.done;
6994 }
6995
6996 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6998}
6999
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007000/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7001private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7002runs on ConnHdlr {
7003 var integer num_blocks := 16;
7004 timer T := int2float(num_blocks);
7005
7006 f_l1_tune(L1CTL);
7007 RSL.clear;
7008
7009 /* These IEs are needed for autonomous MS power control */
7010 var template (value) RSL_IE_List ies := {
7011 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7012 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7013 }),
7014 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7015 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7016 })
7017 };
7018
7019 /* Ensure that 'rx-current' equals 'rx-target' */
7020 f_trxc_fake_rssi(mp_uplink_power_target);
7021
7022 /* Establish a dedicated channel */
7023 f_est_dchan(more_ies := valueof(ies));
7024
7025 L1CTL.clear;
7026 T.start;
7027 alt {
7028 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7029 [] T.timeout {
7030 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7031 num_blocks, " were not handled");
7032 }
7033 }
7034}
7035testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7036 var ConnHdlr vc_conn;
7037 var ConnHdlrPars pars;
7038
7039 f_init();
7040
7041 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7042 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7043 /* Explicitly configure the Uplink power range (target and delte) */
7044 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7045 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7046
7047 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7048 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7049 log(testcasename(), ": starting on ", pars.chan_nr);
7050
7051 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7052 pars, trxc_comp := true);
7053 vc_conn.done;
7054 }
7055
7056 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7057 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7058}
7059
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007060private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7061 var template L1ctlDlMessage tr_bad_frame;
7062 var L1ctlDlMessage l1_dl;
7063 timer T := 8.0;
7064
7065 f_l1_tune(L1CTL);
7066 RSL.clear;
7067
7068 f_est_dchan();
7069
7070 /* There may be a few errors right after the channel activation */
7071 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7072 L1CTL.clear;
7073
7074 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7075 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7076 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7077 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7078 tr_bad_frame.payload := ?;
7079
7080 T.start;
7081 alt {
7082 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7083 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7084 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7085 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7086 }
7087 [] as_l1_sacch();
7088 [] L1CTL.receive { repeat; }
7089 [] T.timeout {
7090 /* We're done, break the loop */
7091 setverdict(pass);
7092 }
7093 }
7094
7095 f_rsl_chan_deact();
7096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7097}
7098testcase TC_speech_no_rtp_tchf() runs on test_CT {
7099 var ConnHdlr vc_conn;
7100 var ConnHdlrPars pars;
7101
7102 f_init();
7103
7104 /* TS1, TCH/F, V1 (FR codec) */
7105 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7106 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7107 vc_conn.done;
7108}
7109testcase TC_speech_no_rtp_tchh() runs on test_CT {
7110 var ConnHdlr vc_conn;
7111 var ConnHdlrPars pars;
7112
7113 f_init();
7114
7115 /* TS5, TCH/H, V1 (HR codec) */
7116 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7117 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7118 vc_conn.done;
7119}
7120
Harald Welte0472ab42018-03-12 15:02:26 +01007121/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7122/* protocol error as per 44.006 */
7123/* link layer failure (repetition of I-frame N200 times without ACK */
7124/* repetition of SABM or DISC N200 times without ACK */
7125/* receptiom of SABM in multi-frame established state */
7126
7127
Harald Welte68e495b2018-02-25 00:05:57 +01007128/* TODO Areas:
7129
7130* channel activation
7131** with BS_Power / MS_Power, bypassing power control loop
7132** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007133** with timing advance from initial activation on
7134* mode modify
7135** encryption
7136** multirate
7137* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007138** unsupported algorithm
7139* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007140* BS Power Control
7141* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007142* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007143* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007144** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007145* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007146** DATA_IND from BTS->PCU
7147** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007148
7149*/
Harald Welte70767382018-02-21 12:16:40 +01007150
7151control {
7152 execute( TC_chan_act_stress() );
7153 execute( TC_chan_act_react() );
7154 execute( TC_chan_deact_not_active() );
7155 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007156 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007157 execute( TC_sacch_filling() );
7158 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007159 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007160 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007161 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007162 execute( TC_sacch_chan_act_ho_async() );
7163 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007164 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007165 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007166 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007167 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007168 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007169 execute( TC_rach_load_idle_thresh0() );
7170 execute( TC_rach_load_idle_below_thresh() );
7171 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007172 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007173 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007174 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007175 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007176 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007177 execute( TC_meas_res_sign_tchf() );
7178 execute( TC_meas_res_sign_tchh() );
7179 execute( TC_meas_res_sign_sdcch4() );
7180 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007181 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007182 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007183 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007184 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007185 execute( TC_rsl_bs_pwr_static_ass() );
7186 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007187 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007188 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007189 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007190 execute( TC_rsl_ms_pwr_dyn_up() );
7191 execute( TC_rsl_ms_pwr_dyn_down() );
7192 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7193 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007194 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007195 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007196 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007197 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007198 execute( TC_paging_imsi_80percent() );
7199 execute( TC_paging_tmsi_80percent() );
7200 execute( TC_paging_imsi_200percent() );
7201 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007202 execute( TC_rsl_protocol_error() );
7203 execute( TC_rsl_mand_ie_error() );
7204 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007205 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007206 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007207 execute( TC_si_sched_2bis() );
7208 execute( TC_si_sched_2ter() );
7209 execute( TC_si_sched_2ter_2bis() );
7210 execute( TC_si_sched_2quater() );
7211 execute( TC_si_sched_13() );
7212 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007213 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007214 execute( TC_ipa_crcx_twice_not_active() );
7215 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007216 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007217 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007218
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007219 if (mp_pcu_socket != "") {
7220 execute( TC_pcu_act_req() );
7221 execute( TC_pcu_act_req_wrong_ts() );
7222 execute( TC_pcu_act_req_wrong_bts() );
7223 execute( TC_pcu_act_req_wrong_trx() );
7224 execute( TC_pcu_deact_req() );
7225 execute( TC_pcu_deact_req_wrong_ts() );
7226 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007227 if (mp_l1_supports_gprs) {
7228 execute( TC_pcu_data_req_pdtch() );
7229 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007230 execute( TC_pcu_data_req_wrong_bts() );
7231 execute( TC_pcu_data_req_wrong_trx() );
7232 execute( TC_pcu_data_req_wrong_ts() );
7233 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007234 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007235 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007236 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007237 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007238 execute( TC_pcu_data_req_imm_ass_pch() );
7239 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007240 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007241 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007242 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007243 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007244 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007245 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007246 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007247 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007248 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007249 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007250 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007251 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007252 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007253 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007254 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007255 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007256 execute( TC_dyn_osmo_pdch_act_deact() );
7257 execute( TC_dyn_osmo_pdch_double_act() );
7258 execute( TC_dyn_ipa_pdch_act_deact() );
7259 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7260
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007261 if (PCUIF_Types.mp_pcuif_version >= 10) {
7262 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007263 execute( TC_pcu_socket_nsvc_ipv4() );
7264 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007265 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007266 } else {
7267 log("PCU socket path not available, skipping PCU tests");
7268 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007269
Harald Welte3d04ae62018-04-04 20:29:05 +02007270 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007271 execute( TC_dyn_osmo_pdch_tchf_act() );
7272 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007273 execute( TC_dyn_ipa_pdch_tchf_act() );
7274 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007275
7276 execute( TC_rll_est_ind() );
7277 execute( TC_rll_est_req_DCCH_3() );
7278 execute( TC_rll_est_req_ACCH_3() );
7279 execute( TC_rll_rel_ind_DCCH_0() );
7280 execute( TC_rll_rel_ind_DCCH_3() );
7281 execute( TC_rll_rel_ind_ACCH_0() );
7282 execute( TC_rll_rel_ind_ACCH_3() );
7283 execute( TC_rll_rel_req() );
7284 execute( TC_rll_unit_data_req_DCCH() );
7285 execute( TC_rll_unit_data_req_ACCH() );
7286 execute( TC_rll_unit_data_ind_DCCH() );
7287 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007288
7289 execute( TC_chan_act_a51() );
7290 execute( TC_chan_act_a52() );
7291 execute( TC_chan_act_a53() );
7292 execute( TC_encr_cmd_a51() );
7293 execute( TC_encr_cmd_a52() );
7294 execute( TC_encr_cmd_a53() );
7295
Harald Welteee25aae2019-05-19 14:32:37 +02007296 execute( TC_err_rep_wrong_mdisc() );
7297 execute( TC_err_rep_wrong_msg_type() );
7298 execute( TC_err_rep_wrong_sequence() );
7299
Harald Weltee613f962018-04-18 22:38:16 +02007300 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007301
7302 execute( TC_tch_sign_l2_fill_frame() );
7303 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007304
7305 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007306 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007307
7308 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007309 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007310
7311 execute( TC_speech_no_rtp_tchf() );
7312 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007313}
7314
7315
7316}