blob: 0ce611a99aab94b67c4e7dff7c2b71e7b16feb71 [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;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100108 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200109 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200110 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200111 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
112 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700113 /* how many transceivers do we expect to connect */
114 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700115 /* frequency hopping status */
116 boolean mp_freq_hop_enabled := false;
117 /* frequency hopping parameters */
118 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100119}
120
Harald Welte629cc6b2018-03-11 17:19:05 +0100121type record of RslChannelNr ChannelNrs;
122
Harald Welte70767382018-02-21 12:16:40 +0100123type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100124 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100125 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100127 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100129 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100130
131 /* L1CTL port (for classic tests) */
132 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100133
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700134 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700135 port TRXC_CODEC_PT BTS_TRXC;
136 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100137
Harald Weltef50e3ae2018-09-10 10:27:56 +0200138 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100139 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100141
Harald Welte883340c2018-02-28 18:59:29 +0100142 /* PCU Interface of BTS */
143 port PCUIF_CODEC_PT PCU;
144 var integer g_pcu_conn_id;
145 /* Last PCU INFO IND we received */
146 var PCUIF_Message g_pcu_last_info;
147
Harald Welte48494ca2018-02-25 16:59:50 +0100148 /* SI configuration */
149 var SystemInformationConfig si_cfg := {
150 bcch_extended := false,
151 si1_present := false,
152 si2bis_present := false,
153 si2ter_present := false,
154 si2quater_present := false,
155 si7_present := false,
156 si8_present := false,
157 si9_present := false,
158 si13_present := false,
159 si13alt_present := false,
160 si15_present := false,
161 si16_present := false,
162 si17_present := false,
163 si2n_present := false,
164 si21_present := false,
165 si22_present := false
166 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100167
168 /* all logical channels available on the BTS */
169 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100170 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100171}
172
173/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200174type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100175 port L1CTL_PT L1CTL;
176
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700177 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700178 port TRXC_CODEC_PT BTS_TRXC;
179 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100180
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200181 /* port to be initialized optionally to access BSC VTY */
182 port TELNETasp_PT BSCVTY;
183
Harald Welte70767382018-02-21 12:16:40 +0100184 timer g_Tguard;
185 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
186
187 var ConnHdlrPars g_pars;
188 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100189 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200190
191 /* PCU Interface of BTS */
192 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100193}
194
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700195private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700196 var bitstring trx_mask := '00000000'B;
197 var integer trx_count := 0;
198 var RSLEm_Event ev;
199 timer T;
200
Harald Welte70767382018-02-21 12:16:40 +0100201 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
202 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
203
204 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
205 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
206 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
207
208 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
209 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700210
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700211 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700212 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700213 T.start(mp_ipa_up_timeout);
214 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700215 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
217 /* Make sure that all transceivers use unique stream ID */
218 if (trx_mask[enum2int(ev.sid)] == '1'B) {
219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
220 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
221 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700222
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 /* This message (RF RESource INDication) is sent by the IUT itself */
224 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
225 trx_mask[enum2int(ev.sid)] := '1'B;
226 trx_count := trx_count + 1;
227
228 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
229 if (trx_count < mp_transceiver_num) { repeat; }
230 }
231 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
232 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
233 [] T.timeout {
234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
235 "Timeout waiting for RSL bring up");
236 }
237 }
Harald Welte70767382018-02-21 12:16:40 +0100238}
239
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700240friend type record FreqHopPars {
241 /* Whether frequency hopping is in use */
242 boolean enabled,
243 /* Mobile Allocation Index Offset / Hopping Sequence Number */
244 MaioHsn maio_hsn,
245 /* MA bitmap to be indicated in RR Immediate Assignment */
246 MobileAllocationLV ma_map,
247 /* The actual Mobile Allocation (ARFCN list) to be used */
248 L1ctlMA ma
249};
250
Harald Welte70767382018-02-21 12:16:40 +0100251type record ConnHdlrPars {
252 RslChannelNr chan_nr,
253 RSL_IE_ChannelMode chan_mode,
254 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100255 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200256 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200257 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700258 BtsBand bts0_band optional,
259
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700260 /* Frequency hopping parameters */
261 FreqHopPars fhp
262};
Harald Welte0472ab42018-03-12 15:02:26 +0100263
264/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700265private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100266 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100267}
268
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700269private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100270 max_retrans := RACH_MAX_RETRANS_7,
271 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100272 cell_barr_access := false,
273 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100274 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100275};
276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700277private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100278 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200279 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100280 acs := '0'B,
281 neci := true,
282 rxlev_access_min := 0
283}
284
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700285private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100286 mcc_mnc := '262F42'H,
287 lac := 42
288}
289
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700290private template (value) GPRSIndicator ts_GPRSIndicator_def := {
291 ra_colour := 0,
292 si13_pos := '0'B
293}
294
295private template (value) SI3RestOctets ts_SI3RestOctets_def
296modifies ts_SI3RestOctets := {
297 gprs_ind := {
298 presence := CSN1_H,
299 ind := ts_GPRSIndicator_def
300 }
301}
302
303private template (value) SI4RestOctets ts_SI4RestOctets_def
304modifies ts_SI4RestOctets := {
305 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700306 presence := CSN1_H,
307 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700308 }
309}
310
Harald Welte7484fc42018-02-24 14:09:45 +0100311/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700312private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100313 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100314 payload := {
315 si3 := {
316 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100317 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100318 ctrl_chan_desc := {
319 msc_r99 := true,
320 att := true,
321 bs_ag_blks_res := 1,
322 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100323 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100324 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
325 spare := '00'B,
326 bs_pa_mfrms := 0, /* 2 multiframes */
327 t3212 := 1 /* 6 minutes */
328 },
Harald Welte82ccef72018-02-25 16:17:33 +0100329 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100330 dn_ind := false,
331 pwrc := false,
332 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100333 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100334 },
Harald Weltef10153f2018-02-25 16:34:05 +0100335 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100336 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200337 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100338 }
339 }
340}
Harald Welte70767382018-02-21 12:16:40 +0100341
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700342private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100343 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100344 payload := {
345 si2 := {
346 bcch_freq_list := '00000000000000000000000000000000'O,
347 ncc_permitted := '11111111'B,
348 rach_control := ts_RachCtrl_default
349 }
350 }
351}
352
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700353private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100354 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100355 payload := {
356 si4 := {
357 lai := ts_LAI_default,
358 cell_sel_par := ts_CellSelPar_default,
359 rach_control := ts_RachCtrl_default,
360 cbch_chan_desc := omit,
361 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200362 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100363 }
364 }
365}
366
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700367private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100368runs on test_CT {
369 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700370 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100371}
372
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700373private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100374runs on test_CT {
375 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
376 log("Setting ", rsl_si_type, ": ", si_dec);
377 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
378}
379
Harald Welte505cf9b2018-09-15 17:47:23 +0300380friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100381 map(self:BTSVTY, system:BTSVTY);
382 f_vty_set_prompts(BTSVTY);
383 f_vty_transceive(BTSVTY, "enable");
384}
385
Harald Welte505cf9b2018-09-15 17:47:23 +0300386friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200387 map(self:BSCVTY, system:BSCVTY);
388 f_vty_set_prompts(BSCVTY, "OsmoBSC");
389 f_vty_transceive(BSCVTY, "enable");
390}
391
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200392friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
393 map(self:BSCVTY, system:BSCVTY);
394 f_vty_set_prompts(BSCVTY, "OsmoBSC");
395 f_vty_transceive(BSCVTY, "enable");
396}
397
Harald Welte883340c2018-02-28 18:59:29 +0100398/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200399private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
400 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100401 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200402 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
403 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100404 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200405 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100407 }
408}
409
Harald Weltef26de0b2018-04-04 20:28:05 +0200410private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
411 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100412 timer T := 2.0;
413 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100414 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200415 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100416 return;
417 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200418 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100419
420 T.start;
421 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200422 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100423 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100425 }
426 }
427}
428
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700429private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
430 out integer trxc_conn_id) {
431 var Result res;
432
433 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
434 "", -1, -1, { udp := {} }, {});
435 if (not ispresent(res.connId)) {
436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
437 "Could not connect to the control (TRXC) interface " &
438 "of FakeTRX, check your configuration");
439 }
440 trxc_conn_id := res.connId;
441}
442
Harald Welte70767382018-02-21 12:16:40 +0100443/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700444friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200445 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100446 g_AllChannels := {
447 /* TS 1..4: TCH/F */
448 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
449 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
450 /* TS 5: TCH/H */
451 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
452 /* TS 0: SDCCH/4 */
453 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
454 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
455 /* TS 6: SDCCH/8 */
456 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
457 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
458 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
459 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
460 };
461
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200462 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700463 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200464 g_AllChanTypes := {
465 /* TS 1..4: TCH/F */
466 valueof(ts_RslChanNr_Bm(1)),
467 /* TS 5: TCH/H */
468 valueof(ts_RslChanNr_Lm(5,1)),
469 /* TS 0: SDCCH/4 */
470 valueof(ts_RslChanNr_SDCCH4(0,2)),
471 /* TS 6: SDCCH/8 */
472 valueof(ts_RslChanNr_SDCCH8(6,4))
473 };
474 } else {
475 g_AllChanTypes := {
476 /* TS 1..4: TCH/F */
477 valueof(ts_RslChanNr_Bm(1)),
478 /* TS 0: SDCCH/4 */
479 valueof(ts_RslChanNr_SDCCH4(0,2)),
480 /* TS 6: SDCCH/8 */
481 valueof(ts_RslChanNr_SDCCH8(6,4))
482 };
483 }
Harald Welte70767382018-02-21 12:16:40 +0100484 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100485 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100486 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200487 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100488
489 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100490 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
491 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
492 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
493 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100494
Harald Weltef26de0b2018-04-04 20:28:05 +0200495 map(self:PCU, system:PCU);
496 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100497
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700498 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100499 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700500
501 /* Init TRXC interface to FakeTRX */
502 map(self:BTS_TRXC, system:BTS_TRXC);
503 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
504
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700505 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700506 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 +0700507 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700508 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
509 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100510 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200511
512 /* Wait some extra time to make sure the BTS emits a stable carrier.
513 * (this is only relevant when running the tests with a physical BTS.) */
514 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100515}
516
Harald Welte68e495b2018-02-25 00:05:57 +0100517/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700518friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100519 map(self:L1CTL, system:L1CTL);
520 f_connect_reset(L1CTL);
521}
522
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700523private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100524
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700525private type record length(8) of FreqHopGroups FreqHopConfig;
526
527private type record of FreqHopGroup FreqHopGroups;
528private type record FreqHopGroup {
529 uint6_t hsn,
530 FreqHopGroupItems trx_maio
531};
532
533private type record of FreqHopGroupItem FreqHopGroupItems;
534private type record FreqHopGroupItem {
535 uint8_t trx_nr,
536 uint6_t maio
537};
538
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700539friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
540 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700541{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700542 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700543 var integer i, j;
544
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700545 fhp.enabled := false;
546
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700547 for (i := 0; i < lengthof(groups); i := i + 1) {
548 var FreqHopGroup g := groups[i];
549 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
550 var FreqHopGroupItem gi := g.trx_maio[j];
551 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700552 fhp.maio_hsn.maio := gi.maio;
553 fhp.maio_hsn.hsn := g.hsn;
554 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700555 break;
556 }
557 }
558
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700559 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700560 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
562 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
563 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700564
565 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
567 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700568 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
569 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700570 }
571
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700572 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700573 break; /* We're done */
574 }
575 }
576}
577
Harald Welte70767382018-02-21 12:16:40 +0100578/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700579friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
580 boolean pcu_comp := false,
581 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100582runs on test_CT return ConnHdlr {
583 var charstring id := testcasename();
584 var ConnHdlr vc_conn;
585
586 vc_conn := ConnHdlr.create(id);
587 /* connect to RSL Emulation main component */
588 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
589 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700590
591 /* The ConnHdlr component may want to talk to some ports directly,
592 * so we disconnect it from the test_CT and connect it to the component.
593 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200594 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200595 unmap(self:PCU, system:PCU);
596 map(vc_conn:PCU, system:PCU);
597 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700598 if (trxc_comp) {
599 unmap(self:BTS_TRXC, system:BTS_TRXC);
600 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
601 }
Harald Welte70767382018-02-21 12:16:40 +0100602
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700603 /* Obtain frequency hopping parameters for a given timeslot */
604 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700605 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700606 }
607
Harald Welte70767382018-02-21 12:16:40 +0100608 vc_conn.start(f_handler_init(fn, id, pars));
609 return vc_conn;
610}
611
Harald Welte70767382018-02-21 12:16:40 +0100612private altstep as_Tguard() runs on ConnHdlr {
613 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100615 }
616}
617
Harald Welte990a3612019-05-27 14:02:13 +0200618friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
619 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100620}
621
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700622private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100623 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700624 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100625}
626
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700627private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100628 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700629 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100630}
631
632/* first function started in ConnHdlr component */
633private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
634runs on ConnHdlr {
635 g_pars := pars;
636 g_chan_nr := pars.chan_nr;
637
638 map(self:L1CTL, system:L1CTL);
639 f_connect_reset(L1CTL);
640
Harald Welted48c0c72019-06-05 10:01:15 +0200641 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700642 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100643 }
Harald Welte70767382018-02-21 12:16:40 +0100644
645 g_Tguard.start(pars.t_guard);
646 activate(as_Tguard());
647
648 f_rslem_register(0, pars.chan_nr);
649
650 /* call the user-supplied test case function */
651 fn.apply(id);
652}
653
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700654private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
655 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200656runs on ConnHdlr return RSL_Message {
657 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100658 timer T := 3.0;
659 RSL.send(tx);
660 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100661 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200662 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100663 T.stop;
664 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100665 }
Harald Welte1eba3742018-02-25 12:48:14 +0100666 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100668 }
Harald Welte21240e62018-03-11 21:43:35 +0100669 [not ignore_other] as_l1_sacch();
670 [not ignore_other] as_meas_res();
671 [not ignore_other] as_l1_dcch();
672 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100674 }
Harald Welte21240e62018-03-11 21:43:35 +0100675 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100676 }
Harald Welteb1726c92018-03-30 11:56:38 +0200677 return rx;
678}
679
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700680friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
681 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200682runs on ConnHdlr {
683 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100684}
685
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700686friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
687 boolean encr_enable := false,
688 RSL_IE_List more_ies := {},
689 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
690runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200691 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200692 if (encr_enable) {
693 /* append encryption related IEs, if requested */
694 var RSL_IE_EncryptionInfo encr_info;
695 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
696 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
697encr_info})) };
698 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200699 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200700 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100701}
702
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700703friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100704 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 +0100705 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100706}
707
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700708/* Default Mobile Allocation to be used for frequency hopping */
709private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
710 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
711
Harald Welte2f2b2b72019-05-31 22:24:57 +0200712friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100713 template RSL_IE_ChannelMode chan_mode,
714 float t_guard := 20.0) := {
715 chan_nr := valueof(chan_nr),
716 chan_mode := valueof(chan_mode),
717 t_guard := t_guard,
718 l1_pars := {
719 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100720 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100721 meas_ul := {
722 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200723 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100724 rxqual := 0
725 },
726 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200727 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100728 rxqual := 0
729 }
730 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200731 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100732 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200733 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200734 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100735 },
Harald Weltee613f962018-04-18 22:38:16 +0200736 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200737 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700738 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700739 fhp := {
740 enabled := false,
741 maio_hsn := ts_HsnMaio(0, 0),
742 ma_map := c_MA_null,
743 ma := l1ctl_ma_def
744 }
Harald Welte70767382018-02-21 12:16:40 +0100745}
746
Harald Welte93640c62018-02-25 16:59:33 +0100747/***********************************************************************
748 * Channel Activation / Deactivation
749 ***********************************************************************/
750
Harald Welte70767382018-02-21 12:16:40 +0100751/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700752private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100753 for (var integer i := 0; i < 500; i := i+1) {
754 f_rsl_chan_act(g_pars.chan_mode);
755 f_rsl_chan_deact();
756 }
757 setverdict(pass);
758}
759testcase TC_chan_act_stress() runs on test_CT {
760 var ConnHdlr vc_conn;
761 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200762 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100763 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
764 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100766}
767
768/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700769private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100770 f_rsl_chan_act(g_pars.chan_mode);
771 /* attempt to activate the same lchan again -> expect reject */
772 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
773 alt {
774 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100776 }
777 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
778 setverdict(pass);
779 }
780 }
781 f_rsl_chan_deact();
782}
783testcase TC_chan_act_react() runs on test_CT {
784 var ConnHdlr vc_conn;
785 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100786 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100787 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
788 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100790}
791
792/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700793private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100794 timer T := 3.0;
795 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
796 T.start;
797 alt {
798 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
799 setverdict(pass);
800 }
801 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100803 }
804 }
805}
806testcase TC_chan_deact_not_active() runs on test_CT {
807 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100808 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100809 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
810 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100812}
813
814/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700815private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100816 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
817 alt {
818 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100820 }
821 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
822 setverdict(pass);
823 }
824 }
825}
826private type record WrongChanNrCase {
827 RslChannelNr chan_nr,
828 charstring description
829}
830private type record of WrongChanNrCase WrongChanNrCases;
831private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
832 chan_nr := chan_nr,
833 description := desc
834}
835
836testcase TC_chan_act_wrong_nr() runs on test_CT {
837 var ConnHdlr vc_conn;
838 var ConnHdlrPars pars;
839
Harald Welte294b0a22018-03-10 23:26:48 +0100840 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100841
842 var WrongChanNrCases wrong := {
843 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
844 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
845 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
846 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
847 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
848 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
849 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
850 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
851 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
852 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
853 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
854 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
855 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
856 };
857
858 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
859 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
860 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
861 vc_conn.done;
862 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100864}
865
Harald Weltee613f962018-04-18 22:38:16 +0200866/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200867friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200868 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200869 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200870
871 /* test on each of the channels we have */
872 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
873 pars.chan_nr := valueof(g_AllChanTypes[i]);
874
875 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
876 vc_conn := f_start_handler(fn, pars);
877 vc_conn.done;
878 }
879
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200881}
882
Harald Welte93640c62018-02-25 16:59:33 +0100883/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100884 * SACCH handling
885 ***********************************************************************/
886
887private function f_exp_sacch(boolean exp) runs on ConnHdlr {
888 timer T_sacch := 3.0;
889 T_sacch.start;
890 alt {
891 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100893 }
894 [not exp] T_sacch.timeout {
895 setverdict(pass);
896 }
897 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
898 setverdict(pass);
899 }
900 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100902 }
903 [] L1CTL.receive { repeat; }
904 [] RSL.receive { repeat; }
905 }
906}
907
908/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
909private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
910 f_l1_tune(L1CTL);
911 RSL.clear;
912
913 /* activate the logical channel */
914 f_est_dchan();
915 L1CTL.clear;
916
917 /* check that SACCH actually are received as expected */
918 f_exp_sacch(true);
919
920 /* deactivate SACCH on the logical channel */
921 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
922 f_sleep(1.0);
923 L1CTL.clear;
924
925 /* check that no SACCH are received anymore */
926 f_exp_sacch(false);
927
928 /* release the channel */
929 f_rsl_chan_deact();
930 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
931}
932testcase TC_deact_sacch() runs on test_CT {
933 var ConnHdlr vc_conn;
934 var ConnHdlrPars pars;
935 f_init();
936 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
937 //for (var integer i := 0; i < 1; i := i+1) {
938 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
939 log(testcasename(), ": Starting for ", g_AllChannels[i]);
940 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
941 vc_conn.done;
942 }
943 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100945}
946
Harald Welte55700662018-03-12 13:15:43 +0100947/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100948private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
949 var L1ctlDlMessage dl;
950 /* check that the specified SI5 value is actually sent */
951 timer T_sacch := 3.0;
952 L1CTL.clear;
953 T_sacch.start;
954 alt {
955 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
956 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
957 if (match(l3, l3_exp)) {
958 setverdict(pass);
959 } else {
960 repeat;
961 }
962 }
963 [] L1CTL.receive { repeat; }
964 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100966 }
967 }
968}
969
Harald Welte55700662018-03-12 13:15:43 +0100970/* verify that given SACCH payload is not present */
971private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
972 var L1ctlDlMessage dl;
973 /* check that the specified SI5 value is actually sent */
974 timer T_sacch := 3.0;
975 L1CTL.clear;
976 T_sacch.start;
977 alt {
978 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
979 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
980 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100982 } else {
983 repeat;
984 }
985 }
986 [] L1CTL.receive { repeat; }
987 [] T_sacch.timeout {
988 setverdict(pass);
989 }
990 }
991}
992
Harald Welte629cc6b2018-03-11 17:19:05 +0100993/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100994private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
995 /* Set a known default SACCH filling for SI5 */
996 var octetstring si5 := f_rnd_octstring(19);
997 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
998
999 f_l1_tune(L1CTL);
1000 RSL.clear;
1001
1002 /* activate the logical channel */
1003 f_est_dchan();
1004
1005 /* check that the specified SI5 value is actually sent */
1006 f_sacch_present(si5);
1007
1008 /* release the channel */
1009 RSL.clear;
1010 f_rsl_chan_deact();
1011 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1012}
1013testcase TC_sacch_filling() runs on test_CT {
1014 var ConnHdlr vc_conn;
1015 var ConnHdlrPars pars;
1016 f_init();
1017 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1018 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1019 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1020 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1021 vc_conn.done;
1022 }
1023 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001025}
1026
Harald Welte629cc6b2018-03-11 17:19:05 +01001027/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001028private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1029 /* Set a known default SACCH filling for SI5 */
1030 var octetstring si5 := f_rnd_octstring(19);
1031 var octetstring si5_diff := f_rnd_octstring(19);
1032 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1033
1034 f_l1_tune(L1CTL);
1035 RSL.clear;
1036
1037 log("Activating channel, expecting standard SI5");
1038 /* activate the logical channel */
1039 f_est_dchan();
1040 /* check that the specified SI5 value is actually sent */
1041 f_sacch_present(si5);
1042
1043 /* set channel-specific different SI5 */
1044 log("Setting channel specific SACCH INFO, expecting it");
1045 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1046 /* check that the specified lchan-specific value is now used */
1047 f_sacch_present(si5_diff);
1048
1049 /* deactivate the channel and re-activate it, this should result in default SI5 */
1050 log("De-activating and re-activating channel, expecting standard SI5");
1051 f_rsl_chan_deact();
1052 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1053 /* Verify that the TRX-wide default SACCH filling is present again */
1054 f_sacch_present(si5);
1055
1056 /* release the channel */
1057 RSL.clear;
1058 f_rsl_chan_deact();
1059 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1060}
1061testcase TC_sacch_info_mod() runs on test_CT {
1062 var ConnHdlr vc_conn;
1063 var ConnHdlrPars pars;
1064 f_init();
1065 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1066 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1067 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1068 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1069 vc_conn.done;
1070 }
1071 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001073}
1074
Harald Welte075d84c2018-03-12 13:07:24 +01001075/* Test SACCH scheduling of multiple different SI message types */
1076private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1077 var octetstring si5 := f_rnd_octstring(19);
1078 var octetstring si5bis := f_rnd_octstring(19);
1079 var octetstring si5ter := f_rnd_octstring(19);
1080 var octetstring si6 := f_rnd_octstring(19);
1081
1082 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1083 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1084 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1085 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1086
1087 f_l1_tune(L1CTL);
1088 RSL.clear;
1089
1090 /* activate the logical channel */
1091 f_est_dchan();
1092 L1CTL.clear;
1093
1094 /* check that SACCH actually are received as expected */
1095 f_sacch_present(si5);
1096 f_sacch_present(si5bis);
1097 f_sacch_present(si5ter);
1098 f_sacch_present(si6);
1099
1100 /* release the channel */
1101 f_rsl_chan_deact();
1102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1103}
1104testcase TC_sacch_multi() runs on test_CT {
1105 var ConnHdlr vc_conn;
1106 var ConnHdlrPars pars;
1107 f_init();
1108 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1109 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1110 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1111 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1112 vc_conn.done;
1113 }
1114 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001116}
1117
Harald Welte55700662018-03-12 13:15:43 +01001118/* Test if SACH information is modified as expected */
1119private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1120 var octetstring si5 := f_rnd_octstring(19);
1121 var octetstring si6 := f_rnd_octstring(19);
1122
1123 /* First, configure both SI5 and SI6 to be transmitted */
1124 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1125 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1126
1127 f_l1_tune(L1CTL);
1128 RSL.clear;
1129
1130 /* activate the logical channel */
1131 f_est_dchan();
1132 L1CTL.clear;
1133
1134 /* check that SACCH actually are received as expected */
1135 f_sacch_present(si5);
1136 f_sacch_present(si6);
1137
1138 /* disable SI6 */
1139 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1140
1141 /* check that SI5 is still transmitted */
1142 f_sacch_present(si5);
1143 /* check if SI6 is now gone */
1144 f_sacch_missing(si6);
1145
1146 /* release the channel */
1147 f_rsl_chan_deact();
1148 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1149}
1150testcase TC_sacch_multi_chg() runs on test_CT {
1151 var ConnHdlr vc_conn;
1152 var ConnHdlrPars pars;
1153 f_init();
1154 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1155 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1156 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1157 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1158 vc_conn.done;
1159 }
1160 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001162}
1163
Harald Weltec8d363c2019-05-19 20:36:48 +02001164/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1165private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1166 var octetstring si5 := f_rnd_octstring(19);
1167 var octetstring si6 := f_rnd_octstring(19);
1168 var octetstring si5_specific := f_rnd_octstring(19);
1169 var octetstring si6_specific := f_rnd_octstring(19);
1170
1171 /* First, configure both SI5 and SI6 to be transmitted */
1172 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1173 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1174
1175 f_l1_tune(L1CTL);
1176 RSL.clear;
1177
1178 /* activate channel with different SACCH filling */
1179 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1180 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1181 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1182 }));
1183 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1184 RSL_IE_Body:{sacch_info := sacch_info})) };
1185 f_est_dchan(more_ies := addl_ies);
1186
1187 /* check that SACCH actually are received as expected */
1188 f_sacch_present(si5_specific);
1189 f_sacch_present(si6_specific);
1190
1191 /* release the channel */
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_chan_act() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199
1200 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1201 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1202 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1203 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1204 vc_conn.done;
1205 }
1206 /* TODO: do the above in parallel, rather than sequentially? */
1207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1208}
1209
Harald Welte8b01c792019-05-19 22:51:25 +02001210/* verify that SACCH DL transmission is started only if MS power IE present
1211 * see section 4.1.3 of 3GPP TS 48.058 */
1212private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1213 var octetstring si5 := f_rnd_octstring(19);
1214
1215 f_l1_tune(L1CTL);
1216 RSL.clear;
1217
1218 /* Step 1: Activate ASYNC HO channel without MS power IE */
1219
1220 /* Activate channel on BTS side */
1221 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1222 /* don't perform immediate assignment here, as we're testing non-IA case */
1223 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001224 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001225
1226 /* Verify that no DL SACCH is being received */
1227 f_sacch_missing(?);
1228
1229 f_rsl_chan_deact();
1230 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1231
1232
1233 /* Step 2: Activate ASYNC HO channel with MS power IE */
1234
1235 /* Activate channel on BTS side */
1236 var RSL_IE_List addl_ies := {
1237 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1238 };
1239 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1240 /* don't perform immediate assignment here, as we're testing non-IA case */
1241 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001242 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001243
1244 /* Verify that DL SACCH is being received */
1245 f_sacch_present(si5);
1246
1247 f_rsl_chan_deact();
1248 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1249}
1250testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1251 var ConnHdlr vc_conn;
1252 var ConnHdlrPars pars;
1253 f_init();
1254
1255 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1256 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1257 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1258 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1259 vc_conn.done;
1260 }
1261 /* TODO: do the above in parallel, rather than sequentially? */
1262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1263}
1264
1265/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1266 * see section 4.1.4 of 3GPP TS 48.058 */
1267private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1268 var octetstring si5 := f_rnd_octstring(19);
1269 var RSL_IE_List addl_ies;
1270
1271 f_l1_tune(L1CTL);
1272 RSL.clear;
1273
1274 /* Step 1: Activate SYNC HO channel without MS power IE */
1275
1276 /* Activate channel on BTS side */
1277 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1278 /* don't perform immediate assignment here, as we're testing non-IA case */
1279 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001280 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001281
1282 /* Verify that no DL SACCH is being received */
1283 f_sacch_missing(?);
1284
1285 f_rsl_chan_deact();
1286 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1287
1288
1289 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1290
1291 /* Activate channel on BTS side */
1292 addl_ies := {
1293 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1294 };
1295 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1296 /* don't perform immediate assignment here, as we're testing non-IA case */
1297 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001298 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001299
1300 /* Verify that no DL SACCH is being received */
1301 f_sacch_missing(?);
1302
1303 f_rsl_chan_deact();
1304 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1305
1306
1307 /* Step 2b: Activate SYNC HO channel with TA IE */
1308
1309 /* Activate channel on BTS side */
1310 addl_ies := {
1311 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1312 };
1313 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1314 /* don't perform immediate assignment here, as we're testing non-IA case */
1315 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001316 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001317
1318 /* Verify that no DL SACCH is being received */
1319 f_sacch_missing(?);
1320
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323
1324
1325 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1326
1327 /* Activate channel on BTS side */
1328 addl_ies := {
1329 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1330 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 DL SACCH is being received */
1338 f_sacch_present(si5);
1339
1340 f_rsl_chan_deact();
1341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1342}
1343testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1344 var ConnHdlr vc_conn;
1345 var ConnHdlrPars pars;
1346 f_init();
1347
1348 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1349 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1350 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1351 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1352 vc_conn.done;
1353 }
1354 /* TODO: do the above in parallel, rather than sequentially? */
1355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1356}
Harald Welte629cc6b2018-03-11 17:19:05 +01001357
1358
1359/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001360 * RACH Handling
1361 ***********************************************************************/
1362
Harald Welte8c24c2b2018-02-26 08:31:31 +01001363/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001364private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001365 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001366 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001367 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001368
Harald Welte8c24c2b2018-02-26 08:31:31 +01001369 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001370 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001371 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001372 var OCT1 ra := f_rnd_ra_emerg();
1373 if (emerg == true) {
1374 ra := f_rnd_ra_emerg();
1375 } else {
1376 ra := f_rnd_ra_cs();
1377 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001378 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1379 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381 }
1382 fn_last := fn;
1383
1384 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001385 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001387 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001388 T.stop;
1389 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001390 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001392 }
1393 [] RSL_CCHAN.receive { repeat; }
1394 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001395 test_failed := true;
1396 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001397 }
1398 }
1399 }
Maxba06feb2019-03-05 10:52:46 +01001400 if (test_failed) {
1401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001402 }
Maxba06feb2019-03-05 10:52:46 +01001403 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001405}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406
Philipp Maier16ade782020-07-08 21:36:00 +02001407/* Normal variant */
1408testcase TC_rach_content() runs on test_CT {
1409 f_TC_rach_content(emerg := false);
1410}
1411
1412/* Emergency call variant */
1413testcase TC_rach_content_emerg() runs on test_CT {
1414 f_TC_rach_content(emerg := true);
1415}
1416
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1418testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001419 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001420 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001421 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001422 f_l1_tune(L1CTL);
1423
1424 var GsmFrameNumber fn_last := 0;
1425 for (var integer i := 0; i < 1000; i := i+1) {
1426 var OCT1 ra := f_rnd_ra_cs();
1427 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1428 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001430 }
1431 fn_last := fn;
1432 }
1433 var integer rsl_chrqd := 0;
1434 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001435 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001436 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001437 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001439 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 repeat;
1441 }
1442 [] RSL_CCHAN.receive { repeat; }
1443 [] T.timeout { }
1444 }
1445 if (rsl_chrqd == 1000) {
1446 setverdict(pass);
1447 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001449 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001451}
1452
Harald Welte3453ab42019-05-24 21:19:58 +02001453private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1454 var charstring bts_str := "bts " & int2str(bts_nr);
1455 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1456}
1457
1458/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1459private template integer tr_rach_slots_per_interval := (90 .. 130);
1460
1461/* Expect 0 RACH load on an idle BTS that has just started up */
1462testcase TC_rach_load_idle_thresh0() runs on test_CT {
1463 var ASP_RSL_Unitdata rx_ud;
1464
1465 f_init_vty_bsc();
1466 /* send load indications even at 0% load */
1467 f_vty_load_ind_thresh(0);
1468 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1469 f_sleep(2.0);
1470
1471 f_init();
1472
Harald Weltee37f9a52020-10-11 20:45:23 +02001473 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1474 alt {
1475 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1476 [] RSL_CCHAN.receive { repeat }
1477 }
1478
Harald Welte3453ab42019-05-24 21:19:58 +02001479 timer T := 5.0;
1480 T.start;
1481 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001482 [] 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 +02001483 setverdict(pass);
1484 repeat;
1485 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001486 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001487 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1488 repeat;
1489 }
1490 [] RSL_CCHAN.receive {
1491 repeat;
1492 }
1493 [] T.timeout { }
1494 }
1495
1496 f_vty_load_ind_thresh(10);
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
1499
1500/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1501testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1502 var ASP_RSL_Unitdata rx_ud;
1503
1504 f_init_vty_bsc();
1505 f_init();
1506
1507 timer T := 5.0;
1508 T.start;
1509 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001510 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001511 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1512 repeat;
1513 }
1514 [] RSL_CCHAN.receive {
1515 repeat;
1516 }
1517 [] T.timeout {
1518 setverdict(pass);
1519 }
1520 }
1521
1522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1523}
1524
1525/* Expect 0 RACH load on an idle BTS that has just started up */
1526testcase TC_rach_load_count() runs on test_CT {
1527 var ASP_RSL_Unitdata rx_ud;
1528 var integer load_access_count := 0;
1529
1530 f_init_vty_bsc();
1531 /* send load indications even at 0% load */
1532 f_vty_load_ind_thresh(0);
1533 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1534 f_sleep(2.0);
1535 f_init();
1536
1537 f_init_l1ctl();
1538 f_sleep(1.0);
1539 f_l1_tune(L1CTL);
1540
Harald Welte52ae1682020-10-11 20:45:55 +02001541 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1542 alt {
1543 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1544 [] RSL_CCHAN.receive { repeat }
1545 }
1546
Harald Welte3453ab42019-05-24 21:19:58 +02001547 var GsmFrameNumber fn_last := 0;
1548 for (var integer i := 0; i < 1000; i := i+1) {
1549 var OCT1 ra := f_rnd_ra_cs();
1550 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1551 if (fn == fn_last) {
1552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1553 }
1554 fn_last := fn;
1555 }
1556
1557 timer T := 5.0;
1558 T.start;
1559 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001560 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001561 -> value rx_ud {
1562 var RSL_IE_Body ie;
1563 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1564 load_access_count := load_access_count + ie.rach_load.access_count;
1565 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1566 setverdict(fail, "Access count cannot be < Busy count");
1567 }
1568 repeat;
1569 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001570 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001571 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1572 repeat;
1573 }
1574 [] RSL_CCHAN.receive {
1575 repeat;
1576 }
1577 [] T.timeout { }
1578 }
1579 if (load_access_count == 1000) {
1580 setverdict(pass);
1581 } else {
1582 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1583 }
1584
1585 f_vty_load_ind_thresh(10);
1586 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1587}
1588
Harald Welte54a2a2d2018-02-26 09:14:05 +01001589private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001590 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001591 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001592 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001593 f_sleep(0.5);
1594
1595 /* Transmit RACH request + wait for confirmation */
1596 var OCT1 ra := f_rnd_ra_cs();
1597 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1598
1599 /* Check for expected result */
1600 timer T := 1.5;
1601 T.start;
1602 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001603 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001604 setverdict(pass);
1605 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001606 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608 }
1609 [] RSL_CCHAN.receive { repeat; }
1610 [not expect_pass] T.timeout {
1611 setverdict(pass);
1612 }
1613 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001615 }
1616 }
1617}
1618
1619/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1620testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001621 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001622 f_init_l1ctl();
1623 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001624 f_sleep(1.0);
1625
1626 /* default max-ta is 63 (full range of GSM timing advance */
1627
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001628 /* We allow early arrival up to 2 symbols */
1629 f_rach_toffs(-1*256, true);
1630 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001631 f_rach_toffs(-10*256, false);
1632
1633 /* 0 / 32 / 63 bits is legal / permitted */
1634 f_rach_toffs(0, true);
1635 f_rach_toffs(32*256, true);
1636 f_rach_toffs(63*256, true);
1637
1638 /* more than 63 bits is not legal / permitted */
1639 f_rach_toffs(64*256, false);
1640 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001643
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001644private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001645 var GsmFrameNumber fn;
1646 var RSL_Message rm;
1647
1648 f_l1_tune(L1CTL);
1649 RSL.clear;
1650
1651 /* Generate a random Handover Reference */
1652 var integer ho_ref := oct2int(f_rnd_octstring(1));
1653
1654 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1655 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1656 RSL_IE_Body:{ handover_ref := ho_ref }));
1657
1658 /* Activate a channel on the BTS side (no encryption) */
1659 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1660 act_type := t_RSL_IE_ActType_HO_SYNC);
1661
1662 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1663 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001664 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001665
1666 /* Send handover Access Burst */
1667 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1668
1669 /* TODO: test mismatching Handover Reference, and missing IE */
1670
1671 /* Wait for handover detection */
1672 timer T := 3.0;
1673 T.start;
1674 alt {
1675 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1676 log("Handover RACH has been detected: ", rm);
1677 setverdict(pass);
1678 }
1679 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1681 log2str("RSL_CHAN_RQD was not expected: ", rm));
1682 }
1683 [] RSL.receive { repeat; }
1684 [] T.timeout {
1685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1686 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1687 }
1688 }
1689
1690 /* Release the channel */
1691 f_rsl_chan_deact();
1692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1693}
1694
1695/* Test handover RACH detection */
1696testcase TC_ho_rach() runs on test_CT {
1697 var ConnHdlrPars pars;
1698 var ConnHdlr vc_conn;
1699
1700 f_init();
1701
1702 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1703 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1704 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1705 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1706 vc_conn.done;
1707 }
1708
1709 /* TODO: do the above in parallel, rather than sequentially? */
1710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1711}
1712
Harald Welte93640c62018-02-25 16:59:33 +01001713/***********************************************************************
1714 * Measurement Processing / Reporting
1715 ***********************************************************************/
1716
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001717private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001718 spare := '0'B,
1719 lpd := 0,
1720 sapi := sapi,
1721 c_r := c_r,
1722 ea := true
1723}
1724
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001725private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001726 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001727 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001728 len := 0, /* overwritten */
1729 m := false,
1730 el := 1,
1731 payload := pl
1732}
1733
1734/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001735private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001736 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001737 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001738 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001739 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 +01001740 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001741 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001742
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001743 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1744 g_pars.l1_pars.ms_power_level, false,
1745 g_pars.l1_pars.ms_actual_ta);
1746
1747 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1748 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1749
1750 log("Sending Measurement Report: ", l1h, l2);
1751 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001752 repeat;
1753 }
1754}
1755
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001756private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001757 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001758 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001759 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1760 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001761 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1762 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001763 repeat;
1764 }
1765}
1766
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001767private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001768 uint6_t rxlev,
1769 uint3_t rxqual
1770}
1771
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001772private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001773 MeasElem full,
1774 MeasElem sub
1775}
1776
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001777private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001778 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001779 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001780 MeasElemFS meas_ul,
1781 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001782 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001783 uint5_t ms_power_level,
1784 uint8_t ms_actual_ta
1785}
1786
1787/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1788private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1789 return 63 + (toffs256s/256);
1790}
1791
Harald Welted5684392018-03-10 18:22:04 +01001792private function f_max(integer a, integer b) return integer {
1793 if (a > b) {
1794 return a;
1795 } else {
1796 return b;
1797 }
1798}
1799
1800private function f_min(integer a, integer b) return integer {
1801 if (a < b) {
1802 return a;
1803 } else {
1804 return b;
1805 }
1806}
1807
1808/* compute negative tolerance val-tolerance, ensure >= min */
1809private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1810 val := val - tolerance;
1811 return f_max(val, min);
1812}
1813
1814/* compute positive tolerance val+tolerance, ensure <= max */
1815private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1816 val := val + tolerance;
1817 return f_min(val, max);
1818}
1819
1820/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1821private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1822return template integer {
1823 var template integer ret;
1824 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1825 return ret;
1826}
1827
1828
Harald Welte70767382018-02-21 12:16:40 +01001829/* build a template for matching measurement results against */
1830private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1831 var ConnL1Pars l1p := g_pars.l1_pars;
1832 var template RSL_IE_UplinkMeas ul_meas := {
1833 len := 3,
1834 rfu := '0'B,
1835 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001836 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001837 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001838 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001839 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001840 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1841 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001842 supp_meas_info := omit
1843 };
Harald Welte685d5982018-02-27 20:42:05 +01001844 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001845 ul_meas.len := (3+8);
1846 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001847 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001848 toa256_min := ?,
1849 toa256_max := ?,
1850 toa256_std_dev := ?
1851 }
Harald Welte685d5982018-02-27 20:42:05 +01001852 }
Harald Welte70767382018-02-21 12:16:40 +01001853 var template RSL_IE_BS_Power bs_power := {
1854 reserved := 0,
1855 epc := false,
1856 fpc := false,
1857 power_level := l1p.bs_power_level
1858 };
1859 var template RSL_IE_L1Info l1_info := {
1860 ms_power_lvl := l1p.ms_power_level,
1861 fpc := false,
1862 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001863 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001864 };
1865 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001866 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001867 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1868 ?, t_toffs);
1869}
1870
Philipp Maierdd841d32019-12-17 14:44:54 +01001871/* build a template for matching measurement results that do not contain any
1872 * MS related measurement (l1_info, l3_info and ms timing offset). */
1873private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1874 var ConnL1Pars l1p := g_pars.l1_pars;
1875 var template RSL_IE_UplinkMeas ul_meas := {
1876 len := 3,
1877 rfu := '0'B,
1878 dtx_d := l1p.dtx_enabled,
1879 rxlev_f_u := ?,
1880 reserved1 := '00'B,
1881 rxlev_s_u := ?,
1882 reserved2 := '00'B,
1883 rxq_f_u := ?,
1884 rxq_s_u := ?,
1885 supp_meas_info := omit
1886 };
1887 if (l1p.toa256_enabled) {
1888 ul_meas.len := (3+8);
1889 ul_meas.supp_meas_info := {
1890 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1891 toa256_min := ?,
1892 toa256_max := ?,
1893 toa256_std_dev := ?
1894 }
1895 }
1896 var template RSL_IE_BS_Power bs_power := {
1897 reserved := 0,
1898 epc := false,
1899 fpc := false,
1900 power_level := l1p.bs_power_level
1901 };
1902
1903 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1904}
1905
Harald Welte70767382018-02-21 12:16:40 +01001906/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001907private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001908 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001909 var boolean chan_est := false;
1910
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001911 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001912
1913 /* Receive osmocom specific measurement reports. This is the normal
1914 * case. Here we verify that the measurement reports we sent are
1915 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001916 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1917 /* increment counter of next to-be-expected meas rep */
1918 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1919 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001920 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001921
1922 /* The following two cases may only happen in the beginning
1923 * of the channel establishment phase. Once we have received
1924 * the "our" measurement report the first time, the channel
1925 * is established and empty or hardcoded TRXCON reports must
1926 * not occur anymore. */
1927 chan_est := true;
1928
1929 repeat;
1930 }
1931
1932 /* When the BTS has established the channel, the MS might need slightly
1933 * more time to establish the channel and actually start sending. The
1934 * result is then a measurement report that just lacks the measurement
1935 * information of the MS. This is normal and we tolerate this behavior. */
1936 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1937 /* increment counter of next to-be-expected meas rep */
1938 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1939 /* Re-start the timer expecting the next MEAS RES */
1940 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001941 repeat;
1942 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001943
1944 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1945 * measurements if the TTCN3 side does not supply measurement input in
1946 * time. In those cases TRXCON will either use a cached measurement
1947 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1948 * report the templates above will not match. We tolerate this
1949 * behavior, but only once. */
1950 [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 +01001951 /* increment counter of next to-be-expected meas rep */
1952 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1953 if (g_first_meas_res) {
1954 g_first_meas_res := false;
1955 repeat;
1956 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001958 }
Harald Welte70767382018-02-21 12:16:40 +01001959 }
1960 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001962 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001963 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001965 }
1966}
1967
Harald Weltee613f962018-04-18 22:38:16 +02001968private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1969 select (rsl_alg_id) {
1970 case (RSL_ALG_ID_A5_0) { return 0; }
1971 case (RSL_ALG_ID_A5_1) { return 1; }
1972 case (RSL_ALG_ID_A5_2) { return 2; }
1973 case (RSL_ALG_ID_A5_3) { return 3; }
1974 case (RSL_ALG_ID_A5_4) { return 4; }
1975 case (RSL_ALG_ID_A5_5) { return 5; }
1976 case (RSL_ALG_ID_A5_6) { return 6; }
1977 case (RSL_ALG_ID_A5_7) { return 7; }
1978 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1980 /* Make compiler happy by calling mtc.stop here. It is already
1981 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001982 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001983 }
1984 }
1985}
1986
1987private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1988 select (rsl_alg_id) {
1989 case (RSL_ALG_ID_A5_1) { return '000'B; }
1990 case (RSL_ALG_ID_A5_2) { return '001'B; }
1991 case (RSL_ALG_ID_A5_3) { return '010'B; }
1992 case (RSL_ALG_ID_A5_4) { return '011'B; }
1993 case (RSL_ALG_ID_A5_5) { return '100'B; }
1994 case (RSL_ALG_ID_A5_6) { return '101'B; }
1995 case (RSL_ALG_ID_A5_7) { return '110'B; }
1996 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1998 /* Make compiler happy by calling mtc.stop here. It is already
1999 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002000 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002001 }
2002 }
2003}
2004
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002005/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2006private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2007 var GsmFrameNumber fn;
2008 timer T := 8.0;
2009
2010 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2011 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2012
2013 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2014 /* Send the actual RACH */
2015 fn := f_L1CTL_RACH(L1CTL, ra);
2016
2017 T.start;
2018 alt {
2019 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2020 [] T.timeout {
2021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2022 }
2023 }
2024 T.stop
2025 return fn;
2026}
Harald Weltee613f962018-04-18 22:38:16 +02002027
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002028/* Tune to a dedicated channel: L1CTL only */
2029private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002030 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002031 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2032 7 /* TODO: mp_tsc */,
2033 mp_trx0_arfcn));
2034 } else {
2035 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2036 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002037 pars.fhp.maio_hsn.hsn,
2038 pars.fhp.maio_hsn.maio,
2039 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002040 }
2041}
2042
Harald Welte70767382018-02-21 12:16:40 +01002043/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002044private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002045 var GsmFrameNumber fn;
2046 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002047 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002048 var integer ra := 23;
2049
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002050 /* Send RACH request and wait for ChanReq */
2051 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002052
2053 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002054 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002055
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002056 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002057 if (g_pars.fhp.enabled) {
2058 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002059 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002060 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002061 }
2062
Harald Welte70767382018-02-21 12:16:40 +01002063 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002064 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 +01002065 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2066
2067 /* receive IMM.ASS on MS side */
2068 var ImmediateAssignment ia_um;
2069 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002070
2071 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2072 if (ch_desc.h != ia_um.chan_desc.h) {
2073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2074 }
2075
Harald Welte70767382018-02-21 12:16:40 +01002076 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002077 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002078 /* enable encryption, if requested */
2079 if (encr_enable) {
2080 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2081 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2082 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002083
2084 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002085}
2086
2087/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002088private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002089 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002090 RSL.clear;
2091
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002092 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002093 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002094 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002095 }
Harald Welte70767382018-02-21 12:16:40 +01002096
2097 f_est_dchan();
2098
2099 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2100 * RSL measurement reports on Abis side */
2101 timer T := 8.0;
2102 T.start;
2103 alt {
2104 [] as_l1_sacch();
2105 [] as_meas_res();
2106 [] as_l1_dcch();
2107 [] L1CTL.receive { repeat; }
2108 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002109 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002110 * of any earlier errors, so if we reach this timeout, we're good */
2111 setverdict(pass);
2112 }
2113 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002115 }
2116 }
2117 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002119}
Harald Welte0472ab42018-03-12 15:02:26 +01002120
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002121/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2122private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002123 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002124 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2125 timer Tup := 10.0;
2126 Tup.start;
2127 alt {
2128 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2129 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2130 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002131
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002132 if (rx_lvl != max_rx_lvl) {
2133 repeat;
2134 }
2135 Tup.stop;
2136 }
2137 [] L1CTL.receive { repeat; }
2138 [] Tup.timeout {
2139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2140 log2str("Didn't reach full power ", max_rx_lvl));
2141 }
2142 }
2143 return max_rx_lvl;
2144}
2145
2146/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2147private function f_verify_ramp_up() runs on ConnHdlr {
2148 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002149 var integer initial_rx_lvl := -1;
2150 var integer last_rx_lvl := -1;
2151 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2152
2153 timer T := 2.0;
2154 alt {
2155 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2156 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2157 log("Received rx_level=", rx_lvl);
2158 if (initial_rx_lvl == -1) {
2159 initial_rx_lvl := rx_lvl;
2160 last_rx_lvl := rx_lvl;
2161
2162 /* Expect a somehow low value during first received messages */
2163 if (initial_rx_lvl >= max_rx_lvl / 2) {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 log2str("Detected high initial tx power during ramp up: ",
2166 initial_rx_lvl , ", full power is", max_rx_lvl));
2167 }
2168 }
2169
2170 /* received Rx level bigger than maximum allowed power by CN */
2171 if (rx_lvl > max_rx_lvl) {
2172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2173 log2str("Detected Tx power higher than full power: ",
2174 rx_lvl , " > ", max_rx_lvl));
2175 }
2176
2177 /* Make sure it never decreases, since we are rumping up */
2178 if (last_rx_lvl > rx_lvl) {
2179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2180 log2str("Detected Tx power decrease during ramp up: ",
2181 last_rx_lvl , " -> ", rx_lvl));
2182 }
2183
2184 if (rx_lvl == max_rx_lvl and not T.running) {
2185 /* We reached the maximum power, start timer and receive
2186 /* a few more to make sure we don't surpass it */
2187 log("Reached full power, wating a bit more until success");
2188 T.start;
2189 }
2190
2191 last_rx_lvl := rx_lvl;
2192 repeat;
2193 }
2194 [] L1CTL.receive { repeat; }
2195 [] T.timeout { }
2196 }
2197
2198 /* We didn't increase tx power during ramp up */
2199 if (initial_rx_lvl < last_rx_lvl) {
2200 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2201 } else {
2202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2203 log2str("No Tx power increase during whole ramp up: ",
2204 initial_rx_lvl , " -> ", last_rx_lvl));
2205 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002206}
2207
2208/* verify BTS ramps power down to rx_level 0 */
2209private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2210 var L1ctlDlMessage l1_dl;
2211 var integer last_rx_lvl := max_rx_lvl;
2212
2213 timer Tdown := 5.0;
2214 Tdown.start;
2215 alt {
2216 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2217 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2218 log("Received rx_level=", rx_lvl);
2219
2220 /* received Rx level bigger than maximum allowed power by CN */
2221 if (rx_lvl > max_rx_lvl) {
2222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2223 log2str("Detected Tx power higher than full power: ",
2224 rx_lvl , " > ", max_rx_lvl));
2225 }
2226
2227 /* Make sure it never increases, since we are rumping down */
2228 if (last_rx_lvl < rx_lvl) {
2229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2230 log2str("Detected Tx power increase during ramp up: ",
2231 last_rx_lvl , " -> ", rx_lvl));
2232 }
2233
2234 last_rx_lvl := rx_lvl;
2235 if (last_rx_lvl != 0) {
2236 repeat;
2237 }
2238 /* we reached power level 0, we are done */
2239 Tdown.stop;
2240 }
2241 [] L1CTL.receive { repeat; }
2242 [] Tdown.timeout { }
2243 }
2244
2245 /* We didn't increase tx power during ramp down */
2246 if (max_rx_lvl > last_rx_lvl) {
2247 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2248 } else {
2249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2250 log2str("No Tx power decrease during whole ramp down: ",
2251 max_rx_lvl , " -> ", last_rx_lvl));
2252 }
2253}
2254
2255/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002256private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002257 f_l1_tune(L1CTL);
2258 RSL.clear;
2259
2260 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002261
2262 setverdict(pass);
2263}
2264testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2265 var ConnHdlr vc_conn;
2266 var ConnHdlrPars pars;
2267 f_init();
2268 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2269 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2270 pcu_comp := false, trxc_comp := true);
2271 vc_conn.done;
2272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2273}
2274
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002275/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002276private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002277 f_connhdlr_init_vty_bsc();
2278
2279 f_l1_tune(L1CTL);
2280 RSL.clear;
2281
2282 /* Wait until BTS is started and at full power */
2283 var integer max_rx_lvl := f_wait_ramp_up();
2284 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2285
2286 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2287 f_verify_ramp_down(max_rx_lvl);
2288
2289 setverdict(pass);
2290}
2291testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2292 var ConnHdlr vc_conn;
2293 var ConnHdlrPars pars;
2294 f_init();
2295 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2296 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2297 pcu_comp := false, trxc_comp := true);
2298 vc_conn.done;
2299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2300}
2301
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002302/* Verify Tx power:
2303 * + ramping down during ADM state UNLOCKED->LOCKED
2304 * + ramping up during ADM state LOCKED->UNLOCKED
2305 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002306private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002307 var L1ctlDlMessage l1_dl;
2308 var integer last_rx_lvl;
2309
2310 f_connhdlr_init_vty_bsc();
2311
2312 f_l1_tune(L1CTL);
2313 RSL.clear;
2314
2315 /* Wait until BTS is started and at full power */
2316 var integer max_rx_lvl := f_wait_ramp_up();
2317 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2318
2319 log("ADM STATE UNLOCKED->LOCKED");
2320 f_vty_enter_cfg_trx(BSCVTY);
2321 f_vty_transceive(BSCVTY, "rf_locked 1");
2322 last_rx_lvl := max_rx_lvl;
2323 f_verify_ramp_down(max_rx_lvl);
2324
2325 /* Let some time after we received 0dBm, then check we don't receive BCCH
2326 * anymore because scheduler has stopped after ramping down */
2327 f_sleep(2.0);
2328 L1CTL.clear;
2329 timer Tlocked := 2.0;
2330 Tlocked.start;
2331 alt {
2332 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2334 log2str("Received data_ind during rf_locked: ", l1_dl));
2335 }
2336 [] L1CTL.receive { repeat; }
2337 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2338 }
2339
2340 log("ADM STATE LOCKED->UNLOCKED");
2341 f_vty_transceive(BSCVTY, "rf_locked 0");
2342 f_verify_ramp_up();
2343 setverdict(pass);
2344}
2345testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2346 var ConnHdlr vc_conn;
2347 var ConnHdlrPars pars;
2348 f_init();
2349 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2350 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2351 pcu_comp := false, trxc_comp := true);
2352 vc_conn.done;
2353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2354}
2355
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002356private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002357 timer T := 8.0;
2358 T.start;
2359 var RSL_Message rsl;
2360 alt {
2361 [] as_l1_sacch();
2362 [] L1CTL.receive { repeat; }
2363 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2364 if (rsl.ies[3].body.bs_power.power_level == level) {
2365 setverdict(pass)
2366 } else {
2367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2368 }
2369 }
2370 [] T.timeout {
2371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2372 }
2373 }
2374}
2375
2376/* see if the rsl meas res contains our expeced bs power level
2377bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002378private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002379 f_l1_tune(L1CTL);
2380 RSL.clear;
2381
2382 if (mp_bts_trxc_port != -1) {
2383 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2384 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2385 }
2386
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002387 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002388 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2389 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2390
2391 f_est_dchan(more_ies :={valueof(pwr)});
2392
2393 f_check_meas_bs_power_level(pwr_var);
2394
2395 f_rsl_chan_deact();
2396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2397}
2398
2399/* see if the rsl meas res contains our expeced bs power level
2400bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002401private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002402 f_l1_tune(L1CTL);
2403 RSL.clear;
2404
2405 if (mp_bts_trxc_port != -1) {
2406 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2407 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2408 }
2409
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002410 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002411 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2412
2413 f_est_dchan();
2414
2415 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2416
2417 f_check_meas_bs_power_level(pwr_var);
2418
2419 f_rsl_chan_deact();
2420 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2421}
2422
2423testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2424 var ConnHdlr vc_conn;
2425 var ConnHdlrPars pars;
2426 f_init();
2427 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2428 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2429 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2430 pcu_comp := false, trxc_comp := true);
2431 vc_conn.done;
2432 }
2433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2434}
2435
2436testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2437 var ConnHdlr vc_conn;
2438 var ConnHdlrPars pars;
2439 f_init();
2440 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2441 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2442 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2443 pcu_comp := false, trxc_comp := true);
2444 vc_conn.done;
2445 }
2446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2447}
2448
Eric Wild61edb7e2019-06-03 12:38:31 +02002449/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2450second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2451These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002452private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002453 var uint5_t pwr_var := 7;
2454 var L1ctlDlMessage l1_dl;
2455
2456 f_trxc_fake_rssi(rxlev2dbm(10));
2457 f_l1_tune(L1CTL);
2458 RSL.clear;
2459
2460 var RSL_IE_List addl_ies;
2461 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2462
2463 addl_ies := {
2464 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2465 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2466 };
2467
2468 /* establish with power parameters */
2469 f_est_dchan(more_ies := addl_ies);
2470
2471 /* set a high value to ensure L1 power control level increases */
2472 f_trxc_fake_rssi(rxlev2dbm(20));
2473
2474 timer T2 := 6.0;
2475 T2.start;
2476 alt {
2477 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002478 /* Update sent MS power to follow what BTS requests */
2479 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2480 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002481 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002482 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002483 T2.stop;
2484 }
2485 [] L1CTL.receive { repeat; }
2486 [] T2.timeout {
2487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2488 "Power Level in L1 header has not increased sufficiently");
2489 }
2490 }
2491
2492 /* set a low value to ensure L1 power control level decreases */
2493 f_trxc_fake_rssi(rxlev2dbm(0));
2494
2495 timer T4 := 6.0;
2496 T4.start;
2497 alt {
2498 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002499 /* Update sent MS power to follow what BTS requests */
2500 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2501 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002502 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002503 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002504 T4.stop;
2505 setverdict(pass, "Power level in L1 decreased/increased as expected");
2506 }
2507 [] L1CTL.receive { repeat; }
2508 [] T4.timeout {
2509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2510 "Power Level in L1 header has not decreased sufficiently");
2511 }
2512 }
2513
2514 f_rsl_chan_deact();
2515 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2516
2517}
2518
2519/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002520private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002521 var uint5_t pwr_var := 7;
2522 var L1ctlDlMessage l1_dl;
2523
2524 /* set a low value to ensure power increases */
2525 f_trxc_fake_rssi(rxlev2dbm(10));
2526 f_l1_tune(L1CTL);
2527 RSL.clear;
2528
2529 var RSL_IE_List addl_ies;
2530 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2531
2532 addl_ies := {
2533 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2534 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2535 };
2536
2537 /* establish with power parameters */
2538 f_est_dchan(more_ies := addl_ies);
2539
2540 timer T1 := 10.0;
2541 T1.start;
2542 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002543 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2544 /* Update sent MS power to follow what BTS requests */
2545 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2546 repeat;
2547 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002548 [] L1CTL.receive { repeat; }
2549 [] T1.timeout {
2550 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2551 setverdict(fail, "Power level in L1 header should not have changed");
2552 }
2553 }
2554 }
2555
2556 f_rsl_chan_deact();
2557 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2558
2559}
2560
2561/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002562private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 var L1ctlDlMessage l1_dl;
2564 var uint5_t pwr_var := 15;
2565 var uint5_t pwr_max_var := f_get_max_power_from_band();
2566
2567 /* set a low value to ensure power increases */
2568 f_trxc_fake_rssi(rxlev2dbm(10));
2569 f_l1_tune(L1CTL);
2570 RSL.clear;
2571
2572 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2573 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2574
2575 /* establish with fixed power level */
2576 f_est_dchan(more_ies :={valueof(pwr)});
2577
2578 /* check our initial power level */
2579 f_wait_for_l1_power_level(pwr_var);
2580
2581 /* update power param to enable power loop
2582 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2583 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2584
2585 /* wait, then check that our power level was reduced */
2586 timer T1 := 10.0;
2587 T1.start;
2588 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002589 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2590 /* Update sent MS power to follow what BTS requests */
2591 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2592 repeat;
2593 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002594 [] L1CTL.receive { repeat; }
2595 [] T1.timeout {
2596 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2597 if( f_power_level_is_highest_dbm(rcv) ){
2598 setverdict(pass, "Power level in L1 header reduced as expected");
2599 } else {
2600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2601 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2602 }
2603 }
2604 }
2605
2606 f_rsl_chan_deact();
2607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2608
2609}
2610
2611/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002612private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002613 var L1ctlDlMessage l1_dl;
2614
2615 /* set a high value to ensure power decreases */
2616 f_trxc_fake_rssi(rxlev2dbm(50));
2617 f_l1_tune(L1CTL);
2618 RSL.clear;
2619
2620 var uint5_t pwr_var := 5;
2621 var uint5_t pwr_target_val := 15;
2622
2623 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2624 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2625
2626 /* establish with fixed power level */
2627 f_est_dchan(more_ies :={valueof(pwr)});
2628
2629 /* check our initial power level */
2630 f_wait_for_l1_power_level(pwr_var);
2631
2632 /* update power param to enable power loop
2633 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002634 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002635
2636 /* wait, then check that our power level was increased */
2637 timer T1 := 10.0;
2638 T1.start;
2639 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002640 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2641 /* Update sent MS power to follow what BTS requests */
2642 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2643 repeat;
2644 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002645 [] L1CTL.receive { repeat; }
2646 [] T1.timeout {
2647 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2648 setverdict(pass, "Power level in L1 header increased to lowest power value");
2649 } else {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 "Power level in L1 header NOT increased to lowest power value");
2652 }
2653 }
2654 }
2655
2656 f_rsl_chan_deact();
2657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2658
2659}
2660
Eric Wild095024b2019-06-17 15:08:57 +02002661/* see if we change the power level without receiving power parameters, which should not happen
2662rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002663private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002664 var L1ctlDlMessage l1_dl;
2665
2666 /* set a high value to ensure power decreases */
2667 f_trxc_fake_rssi(rxlev2dbm(50));
2668 f_l1_tune(L1CTL);
2669 RSL.clear;
2670
2671 var uint5_t pwr_var := 5;
2672
2673 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2674 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2675
2676 /* establish with fixed power level */
2677 f_est_dchan(more_ies :={valueof(pwr)});
2678
2679 /* check our initial power level */
2680 f_wait_for_l1_power_level(pwr_var);
2681
2682 /* wait, then check that our power level did not change */
2683 timer T1 := 10.0;
2684 T1.start;
2685 alt {
2686 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2687 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2689 "BS power control should not be active unless we receive a power parameters IE!");
2690 }
2691 repeat;
2692 }
2693 [] L1CTL.receive { repeat; }
2694 [] T1.timeout { setverdict(pass); }
2695 }
2696
2697 f_rsl_chan_deact();
2698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2699
2700}
2701
Eric Wild095024b2019-06-17 15:08:57 +02002702/* see if we change the power level without receiving power parameters, which should not happen
2703ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002704private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002705 var L1ctlDlMessage l1_dl;
2706
2707 /* set a high value to ensure power decreases */
2708 f_trxc_fake_rssi(rxlev2dbm(50));
2709 f_l1_tune(L1CTL);
2710 RSL.clear;
2711
2712 var uint5_t pwr_var := 5;
2713
2714 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2715 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2716
2717 /* establish with fixed power level */
2718 f_est_dchan(more_ies :={valueof(pwr)});
2719
2720 /* check our initial power level */
2721 f_wait_for_l1_power_level(pwr_var);
2722
2723 /* pwr control without power params IE, should NOT activate MS power control*/
2724 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2725
2726 /* wait, then check that our power level did not change */
2727 timer T1 := 10.0;
2728 T1.start;
2729 alt {
2730 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2731 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2733 "BS power control should not be active unless we receive a power parameters IE!");
2734 }
2735 repeat;
2736 }
2737 [] L1CTL.receive { repeat; }
2738 [] T1.timeout { setverdict(pass); }
2739 }
2740
2741 f_rsl_chan_deact();
2742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2743
2744}
2745
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002746private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002747 var L1ctlDlMessage l1_dl;
2748 timer T0 := 10.0;
2749 T0.start;
2750 alt {
2751 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2752 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2754 "Power level in L1 header != signaled (RSL) power level.");
2755 }
2756 }
2757 [] L1CTL.receive { repeat; }
2758 [] T0.timeout {
2759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2760 "Timeout waiting for initial power level");
2761 }
2762 }
2763 T0.stop;
2764}
2765
2766private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2767 var IntegerRecord min_dbm_level;
2768 var IntegerRecord max_dbm_level;
2769 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2770
2771 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2772 if (min_dbm_level[i] == level) {
2773 return true;
2774 }
2775 }
2776 return false;
2777}
2778
2779private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2780 var IntegerRecord min_dbm_level;
2781 var IntegerRecord max_dbm_level;
2782 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2783
2784 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2785 if (max_dbm_level[i] == level) {
2786 return true;
2787 }
2788 }
2789 return false;
2790}
2791
2792private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2793 var IntegerRecord min_dbm_level;
2794 var IntegerRecord max_dbm_level;
2795 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2796 return max_dbm_level[0];
2797}
2798
2799type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002800private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002801private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2802 // 45.005 4.1.1
2803 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2804 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2805 2, 1, 0};
2806 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2807 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2808 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2809 var IntegerRecord rv;
2810
2811 select(band){
2812 case (BtsBand_allGSM){
2813 rv := gsm_power;
2814 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2815 max_dbm_level := {2, 1, 0};
2816 }
2817 case("DCS1800"){
2818 rv := dcs_power;
2819 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2820 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2821 }
2822 case("PCS1900"){
2823 rv := pcs_power;
2824 min_dbm_level := {15};
2825 max_dbm_level := {30};
2826 }
Harald Welte194b6912020-10-11 21:01:55 +02002827 case else {
2828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2829 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002830 }
2831
2832 return rv;
2833}
2834
2835private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002836 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 +02002837}
2838
2839testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2840 var ConnHdlr vc_conn;
2841 var ConnHdlrPars pars;
2842 f_init();
2843 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2844 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2845 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2846 pars.bts0_band := f_vty_get_bts0_band();
2847 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2848 vc_conn.done;
2849 }
2850 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2852}
2853
2854testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2855 var ConnHdlr vc_conn;
2856 var ConnHdlrPars pars;
2857 f_init();
2858 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2859 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2860 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2861 pars.bts0_band := f_vty_get_bts0_band();
2862 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2863 vc_conn.done;
2864 }
2865 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2867}
2868
2869testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2870 var ConnHdlr vc_conn;
2871 var ConnHdlrPars pars;
2872 f_init();
2873 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2874 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2875 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2876 pars.bts0_band := f_vty_get_bts0_band();
2877 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2878 vc_conn.done;
2879 }
2880 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2882}
2883
2884testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2885 var ConnHdlr vc_conn;
2886 var ConnHdlrPars pars;
2887 f_init();
2888 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2889 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2890 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2891 pars.bts0_band := f_vty_get_bts0_band();
2892 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2893 vc_conn.done;
2894 }
2895 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2897}
2898
Eric Wild280ccb82019-06-17 11:11:52 +02002899testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2900 var ConnHdlr vc_conn;
2901 var ConnHdlrPars pars;
2902 f_init();
2903 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2904 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2905 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2906 pars.bts0_band := f_vty_get_bts0_band();
2907 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2908 vc_conn.done;
2909 }
2910 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2912}
2913
Eric Wild095024b2019-06-17 15:08:57 +02002914testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2915 var ConnHdlr vc_conn;
2916 var ConnHdlrPars pars;
2917 f_init();
2918 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2919 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2920 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2921 pars.bts0_band := f_vty_get_bts0_band();
2922 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2923 vc_conn.done;
2924 }
2925 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2927}
2928
Harald Welte70767382018-02-21 12:16:40 +01002929testcase TC_meas_res_sign_tchf() runs on test_CT {
2930 var ConnHdlr vc_conn;
2931 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002932 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002933 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2934 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002935 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2936 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002937 vc_conn.done;
2938 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002940}
2941testcase TC_meas_res_sign_tchh() runs on test_CT {
2942 var ConnHdlr vc_conn;
2943 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002944 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002945 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2946 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002947 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2948 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002949 vc_conn.done;
2950 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002952}
2953testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2954 var ConnHdlr vc_conn;
2955 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002956 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002957 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2958 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002959 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2960 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002961 vc_conn.done;
2962 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002964}
2965testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2966 var ConnHdlr vc_conn;
2967 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002968 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002969 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2970 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002971 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2972 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002973 vc_conn.done;
2974 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002976}
Harald Welte685d5982018-02-27 20:42:05 +01002977testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2978 var ConnHdlr vc_conn;
2979 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002980 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002981 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2982 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2983 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2984 pars.l1_pars.toa256_enabled := true;
2985 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2986 vc_conn.done;
2987 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002989}
2990
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002991/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2992 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002993private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002994 var L1ctlDlMessage l1_dl;
2995 var RSL_IE_MS_Power ms_power;
2996 var RSL_Message rsl;
2997 var uint5_t power_level := 0;
2998
2999 f_l1_tune(L1CTL);
3000 RSL.clear;
3001
3002 f_est_dchan();
3003
3004 ms_power.reserved := 0;
3005 ms_power.fpc_epc := false;
3006
3007 /* Send the first power control command. This will disable any BTS/TRX
3008 * internal power control and switch the MS (which is not in scope of
3009 * this test) to a constant power level. We start with a power level
3010 * of 0 */
3011 ms_power.power_level := power_level;
3012 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3013 RSL.send(rsl);
3014
3015 alt {
3016
3017 /* Pick all SACCH blocks for checking */
3018 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3019
3020 /* The first byte of the L1 header contains the power level.
3021 * The reserved bits and the fpc bit is set to 0, so we may
3022 * compare directly. */
3023 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3024 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3025 }
3026
3027 /* Signal a new power level via RSL for the next turn. */
3028 if (power_level < 31) {
3029 power_level := power_level + 1;
3030 ms_power.power_level := power_level;
3031 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3032 RSL.send(rsl);
3033 repeat;
3034 }
3035
3036 }
3037
3038 /* Ignore all other blocks */
3039 [] L1CTL.receive { repeat; }
3040
3041 }
3042
3043 f_rsl_chan_deact();
3044 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3045
3046 setverdict(pass);
3047}
3048
3049testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3050 var ConnHdlr vc_conn;
3051 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003052 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003053
3054 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3055 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3056 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3057 vc_conn.done;
3058 }
3059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3060}
Harald Welte70767382018-02-21 12:16:40 +01003061
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003062/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003063TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003064private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003065 var L1ctlDlMessage l1_dl;
3066 var uint5_t ta_to_test := 16;
3067
3068
3069 f_l1_tune(L1CTL);
3070 RSL.clear;
3071
3072 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003073 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003074
3075 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3076
3077
3078 alt {
3079
3080 /* Pick all SACCH blocks for checking */
3081 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3082
3083 /* The second byte of the L1 header contains the TA. */
3084 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3085 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3086 }
3087
3088 }
3089
3090 /* Ignore all other blocks */
3091 [] L1CTL.receive { repeat; }
3092
3093 }
3094
3095 f_rsl_chan_deact();
3096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3097
3098 setverdict(pass);
3099}
3100
3101testcase TC_rsl_chan_initial_ta() runs on test_CT {
3102 var ConnHdlr vc_conn;
3103 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003104 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003105 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003106 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3107 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003108 vc_conn.done;
3109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3110}
3111
Eric Wilde57e1a62019-05-28 13:30:55 +02003112/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003113private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003114 var L1ctlDlMessage l1_dl;
3115 var uint5_t ms_power_level := 7;
3116
3117 var RSL_IE_MS_Power ms_power;
3118 ms_power.reserved := 0;
3119 ms_power.fpc_epc := false;
3120 ms_power.power_level := ms_power_level;
3121
3122 f_l1_tune(L1CTL);
3123 RSL.clear;
3124
3125 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3126
3127 timer T := 1.0;
3128 T.start;
3129 alt {
3130 /* Pick all SACCH blocks for checking */
3131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3132 /* The first byte of the L1 header contains the power level.. */
3133 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3134 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3135 }
3136 }
3137 /* Ignore all other blocks */
3138 [] L1CTL.receive { repeat; }
3139 [] T.timeout {
3140 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3141 }
3142 }
3143
3144 f_rsl_chan_deact();
3145 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3146 setverdict(pass);
3147}
3148
3149testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3150 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3151 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3152}
3153
Harald Welte0472ab42018-03-12 15:02:26 +01003154/* 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 +01003155private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003156 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003157 RSL.clear;
3158
3159 f_est_dchan();
3160 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003161 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003162
3163 timer T := 40.0;
3164 T.start;
3165 alt {
3166 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3167 setverdict(pass)
3168 }
3169 [] RSL.receive { repeat };
3170 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003172 }
3173 }
3174 f_rsl_chan_deact();
3175}
3176testcase TC_conn_fail_crit() runs on test_CT {
3177 var ConnHdlr vc_conn;
3178 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003179 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003180 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3181 pars.t_guard := 60.0;
3182 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3183 vc_conn.done;
3184}
3185
Harald Welte93640c62018-02-25 16:59:33 +01003186/***********************************************************************
3187 * Paging
3188 ***********************************************************************/
3189
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003190private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003191 if (tmsi == 'FFFFFFFF'O) {
3192 return true;
3193 } else {
3194 return false;
3195 }
3196}
Harald Welte70767382018-02-21 12:16:40 +01003197
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003198private type record allowedFn { integer frame_nr }
3199private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3200private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3201private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3202private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3203private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3204private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3205private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3206private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3207private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003208{
3209 var integer frame_nr_51;
3210 frame_nr_51 := frame_nr mod 51
3211
3212 var allowedFn fn_check;
3213 fn_check.frame_nr := frame_nr_51;
3214
3215 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003217 return;
3218 }
3219
3220 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3221 return;
3222 }
3223 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3224 return;
3225 }
3226 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3227 return;
3228 }
3229 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3230 return;
3231 }
3232 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3233 return;
3234 }
3235 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3236 return;
3237 }
3238 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3239 return;
3240 }
3241 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3242 return;
3243 }
3244
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003246 return;
3247}
3248
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003249private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3250 inout integer num_paging_rcv_ids,
3251 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003252runs on test_CT {
3253 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003254 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003255 repeat;
3256 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003257 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003258 var octetstring without_plen :=
3259 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3260 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003261
3262 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3263
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003264 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3265 /* Ignore empty RR Paging Request (PCH filling) messages.
3266 * TODO: does it make sense to count them? */
3267 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003268 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3269 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003270 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003271 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3272 }
3273 } else if (match(rr, tr_PAGING_REQ2)) {
3274 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3275 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3276 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3277 }
3278 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3279 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3280 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003281 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003282 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3283 }
3284 } else if (match(rr, tr_PAGING_REQ3)) {
3285 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3286 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3287 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3288 }
3289 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3290 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3291 }
3292 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3293 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3294 }
3295 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3296 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3297 }
3298 }
3299 repeat;
3300 }
3301}
3302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003303private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 boolean combined_ccch,
3305 integer bs_ag_blks_res,
3306 float load_factor,
3307 boolean exp_load_ind,
3308 boolean exp_overload,
3309 boolean use_tmsi
3310}
3311
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003312private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003313 integer num_paging_sent,
3314 integer num_paging_rcv_msgs,
3315 integer num_paging_rcv_ids,
3316 integer num_overload
3317}
3318
Harald Welte68e495b2018-02-25 00:05:57 +01003319/* Helper function for paging related testing */
3320private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003321 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003322 f_init_l1ctl();
3323 f_l1_tune(L1CTL);
3324
3325 var PagingTestState st := {
3326 num_paging_sent := 0,
3327 num_paging_rcv_msgs := 0,
3328 num_paging_rcv_ids := 0,
3329 num_overload := 0
3330 };
3331
3332 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3333 var float max_pch_imsi_per_sec;
3334 if (cfg.use_tmsi) {
3335 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3336 } else {
3337 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3338 }
3339 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3340 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003341 var float time_total := 20.0;
3342 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3343 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003344
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003345 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3346 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003347
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003348 timer T_itv := 0.0;
3349 T_itv.start;
3350 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003351 alt {
3352 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003353 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003354 st.num_overload := st.num_overload + 1;
3355 repeat;
3356 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003357 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003359 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003360 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003361 log("Rx LOAD_IND");
3362 /* FIXME: analyze/verify interval + contents */
3363 repeat;
3364 }
3365 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003366 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003367 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003368 [] T_itv.timeout {
3369 /* Send paging cmds based on elapsed time */
3370 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3371 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003372 var MobileIdentityV mi;
3373
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003374 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003375 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003376 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003377 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003378 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003379 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003380
3381 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003382 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 +02003383
3384 st.num_paging_sent := st.num_paging_sent + 1;
3385 }
3386 if (st.num_paging_sent < pkt_total) {
3387 /* Wait for interval to next PAGING COMMAND */
3388 var float time_now := T_total.read;
3389 var float next_sched := int2float(st.num_paging_sent)*interval;
3390 if (next_sched > time_now) {
3391 T_itv.start(next_sched - time_now);
3392 } else {
3393 T_itv.start(0.0);
3394 }
3395 } else {
3396 /* We are done, no need to keep counting */
3397 T_total.stop;
3398 }
3399 }
3400 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003401 }
3402 }
3403
3404 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3405 timer T_wait := 18.0;
3406 T_wait.start;
3407 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003408 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003409 [] L1CTL.receive { repeat; }
3410 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003411 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3412 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003413 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003415 }
Harald Welte68e495b2018-02-25 00:05:57 +01003416 }
3417
3418 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3419 " rcvd_ids=", st.num_paging_rcv_ids);
3420 return st;
3421}
3422
3423/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3424 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3425 * - that CCCH LOAD IND (PCH) are being generated
3426 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3427testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003428 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003429 var PagingTestCfg cfg := {
3430 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003431 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003432 load_factor := 0.8,
3433 exp_load_ind := true,
3434 exp_overload := false,
3435 use_tmsi := false
3436 };
3437 var PagingTestState st := f_TC_paging(cfg);
3438 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3440 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003441 } else {
3442 setverdict(pass);
3443 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003445}
3446
3447/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3448 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3449 * - that CCCH LOAD IND (PCH) are being generated
3450 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3451testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003452 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003453 var PagingTestCfg cfg := {
3454 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003455 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003456 load_factor := 0.8,
3457 exp_load_ind := true,
3458 exp_overload := false,
3459 use_tmsi := true
3460 };
3461 var PagingTestState st := f_TC_paging(cfg);
3462 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3464 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003465 } else {
3466 setverdict(pass);
3467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003469}
3470
3471/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3472 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3473 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3474 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3475testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003476 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003477 var PagingTestCfg cfg := {
3478 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003479 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003480 load_factor := 2.0,
3481 exp_load_ind := true,
3482 exp_overload := true,
3483 use_tmsi := false
3484 };
3485 var PagingTestState st := f_TC_paging(cfg);
3486 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3487 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003488 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003489 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003490 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 +01003491 } else {
3492 setverdict(pass);
3493 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003495}
3496
3497/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3498 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3499 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3500 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3501testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003502 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003503 var PagingTestCfg cfg := {
3504 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003505 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003506 load_factor := 2.0,
3507 exp_load_ind := true,
3508 exp_overload := true,
3509 use_tmsi := true
3510 };
3511 var PagingTestState st := f_TC_paging(cfg);
3512 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3513 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003514 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003515 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003516 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 +01003517 } else {
3518 setverdict(pass);
3519 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003521}
3522
3523
Harald Welte93640c62018-02-25 16:59:33 +01003524/***********************************************************************
3525 * Immediate Assignment / AGCH
3526 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003527private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003528 len := 0,
3529 ma := ''B
3530}
Harald Welte93640c62018-02-25 16:59:33 +01003531
Harald Weltee8d750e2018-06-10 21:41:35 +02003532private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3533 return int2str(num_tx) & " sent, "
3534 & int2str(num_rx) & " received, "
3535 & int2str(num_del) & " deleted";
3536}
3537
3538private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3539 var L1ctlDlMessage l1_dl;
3540 timer T := 10.0;
3541 var integer num_tx := 0;
3542 var integer num_rx := 0;
3543 var integer num_del := 0;
3544 var charstring res_str;
3545 var float rx_ratio;
3546
Harald Welte10474062019-05-30 16:48:17 +02003547 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003548 f_init_l1ctl();
3549 f_l1_tune(L1CTL);
3550
3551 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003552 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003553 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3554 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003555 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003556 num_tx := num_tx+1;
3557 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003558 }
3559 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003560 T.start;
3561 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003562 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003563 num_del := num_del+1;
3564 repeat;
3565 }
3566 [] RSL_CCHAN.receive {
3567 repeat;
3568 }
3569 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003570 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3571 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3572 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003573 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003574 } else {
3575 num_rx := num_rx+1;
3576 }
3577 repeat;
3578 }
3579 [] L1CTL.receive { repeat; }
3580 [] T.timeout { }
3581 }
3582 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3583 log("AGCH test: " & res_str);
3584 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003586 }
3587 rx_ratio := int2float(num_rx) / int2float(num_tx);
3588 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003589 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 +02003590 } else {
3591 setverdict(pass);
3592 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003594}
3595
Harald Weltee8d750e2018-06-10 21:41:35 +02003596/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3597testcase TC_imm_ass_1000_20ms() runs on test_CT {
3598 f_TC_imm_ass(1000, 0.02, 0.25);
3599}
3600
3601/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3602testcase TC_imm_ass_200_0ms() runs on test_CT {
3603 f_TC_imm_ass(200, 0.0, 0.05);
3604}
3605
3606/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3607testcase TC_imm_ass_200_76ms() runs on test_CT {
3608 f_TC_imm_ass(150, 0.076, 1.00);
3609}
3610
3611
3612
Harald Welte48494ca2018-02-25 16:59:50 +01003613/***********************************************************************
3614 * BCCH
3615 ***********************************************************************/
3616
3617/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003618private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003619 GsmFrameNumber frame_number,
3620 SystemInformation si
3621}
3622
3623/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003624private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003625
3626/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003627private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003628
3629/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003630private function f_si_vecslot_contains(SystemInformationVector arr,
3631 RrMessageType key,
3632 boolean bcch_ext := false)
3633return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003634 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3635 var integer fn_mod51 := arr[i].frame_number mod 51;
3636 if (not bcch_ext and fn_mod51 == 2 or
3637 bcch_ext and fn_mod51 == 6) {
3638 if (arr[i].si.header.message_type == key) {
3639 return true;
3640 }
3641 }
3642 }
3643 return false;
3644}
3645
3646/* 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 +07003647private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3648 integer tc, RrMessageType key,
3649 boolean ext_bcch := false)
3650{
Harald Welte48494ca2018-02-25 16:59:50 +01003651 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003653 }
3654}
3655
3656/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003657private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3658 RrMessageType key)
3659return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003660 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3661 if (f_si_vecslot_contains(arr[tc], key) or
3662 f_si_vecslot_contains(arr[tc], key, true)) {
3663 return true;
3664 }
3665 }
3666 return false;
3667}
3668
3669/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003670private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3671 RrMessageType key,
3672 boolean bcch_ext := false,
3673 integer n := 1, integer m := 4)
3674return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003675 var integer count := 0;
3676 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3678 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003679 }
3680 for (var integer i:= 0; i < m; i := i + 1) {
3681 var integer fn_mod51 := arr[i].frame_number mod 51;
3682 if (not bcch_ext and fn_mod51 == 2 or
3683 bcch_ext and fn_mod51 == 6) {
3684 if (arr[i].si.header.message_type == key) {
3685 count := count + 1;
3686 }
3687 }
3688 }
3689 if (count >= n) {
3690 return true;
3691 } else {
3692 return false;
3693 }
3694}
3695
3696/* 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 +07003697private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3698 integer tc, RrMessageType key,
3699 boolean ext_bcch := false,
3700 integer n, integer m)
3701{
Harald Welte48494ca2018-02-25 16:59:50 +01003702 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003704 }
3705}
3706
3707/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003708private function f_si_vecslot_contains_only(SystemInformationVector arr,
3709 RrMessageType key,
3710 boolean bcch_ext := false)
3711return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003712 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3713 var integer fn_mod51 := arr[i].frame_number mod 51;
3714 if (not bcch_ext and fn_mod51 == 2 or
3715 bcch_ext and fn_mod51 == 6) {
3716 if (arr[i].si.header.message_type != key) {
3717 return false;
3718 }
3719 }
3720 }
3721 return true;
3722}
3723
3724/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003725private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3726 integer tc, RrMessageType key,
3727 boolean ext_bcch := false)
3728{
Harald Welte48494ca2018-02-25 16:59:50 +01003729 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003731 }
3732}
3733
3734/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003735private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003736 boolean bcch_extended,
3737 boolean si1_present,
3738 boolean si2bis_present,
3739 boolean si2ter_present,
3740 boolean si2quater_present,
3741 boolean si7_present,
3742 boolean si8_present,
3743 boolean si9_present,
3744 boolean si13_present,
3745 boolean si13alt_present,
3746 boolean si15_present,
3747 boolean si16_present,
3748 boolean si17_present,
3749 boolean si2n_present,
3750 boolean si21_present,
3751 boolean si22_present
3752}
3753
3754/* 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 +07003755private function f_validate_si_scheduling(SystemInformationConfig cfg,
3756 SystemInformationVectorPerTc si_per_tc)
3757{
Harald Welte48494ca2018-02-25 16:59:50 +01003758 var integer i;
3759 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3760 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003762 }
3763 }
3764 if (cfg.si1_present) {
3765 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3766 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3767 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3768 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3769 /* make sure *ALL* contain SI1 */
3770 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3771 }
3772 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3773 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3774 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3775 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3776 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3777 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3778
3779 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3780 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3781 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3782 * consecutive occurrences of TC = 4. */
3783 if (cfg.si2bis_present and not cfg.si2ter_present) {
3784 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3785 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3786 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3787 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3788 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3789 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3790 }
3791
3792 if (cfg.si7_present or cfg.si8_present) {
3793 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3794 * if System Information type 4 does not contain all information needed for cell
3795 * selection and reselection. */
3796 if (not cfg.bcch_extended) {
3797 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3798 }
3799 if (cfg.si7_present) {
3800 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3801 }
3802 if (cfg.si8_present) {
3803 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3804 }
3805 }
3806
3807 if (cfg.si2quater_present) {
3808 /* iii) System information type 2 quater is sent if needed, as determined by the system
3809 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3810 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3811 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3812 * within any of 4 consecutive occurrences of TC = 5. */
3813 if (not (cfg.bcch_extended)) {
3814 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3815 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3816 } else {
3817 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3818 }
3819 } else {
3820 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3821 }
3822 }
3823 if (cfg.si9_present) {
3824 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3825 * in system information type 3 as defined in 3GPP TS 44.018. */
3826 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3827 }
3828 if (cfg.si13_present) {
3829 /* vii) System Information type 13 is only related to the GPRS service. System Information
3830 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3831 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3832 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3833 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3834 * within any of 4 consecutive occurrences of TC=4. */
3835 if (not cfg.bcch_extended) {
3836 log("not-bccch-extended");
3837 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3838 } else {
3839 log("bccch-extended");
3840 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3841 }
3842 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003844 }
3845 }
3846 if (cfg.si16_present or cfg.si17_present) {
3847 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3848 * should not be sent in a cell where network sharing is used (see rule xv). */
3849 if (cfg.si22_present) {
3850 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3851 }
3852 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003854 }
3855 if (not cfg.bcch_extended) {
3856 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3857 }
3858 if (cfg.si16_present) {
3859 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3860 }
3861 if (cfg.si17_present) {
3862 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3863 }
3864 }
3865
3866 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3867 * broadcast information. The frequency with which they are sent is determined by the
3868 * system operator. System Information type 9 identifies the scheduling of System
3869 * Information type 18 and 20 messages. */
3870
3871 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3872 * Information Type 19 is present, then its scheduling shall be indicated in System
3873 * Information Type 9. */
3874
3875 if (cfg.si15_present) {
3876 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3877 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3878 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3879 * 4 consecutive occurrences of TC = 1. */
3880 if (not cfg.bcch_extended) {
3881 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3882 } else {
3883 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3884 }
3885 }
3886 if (cfg.si13alt_present) {
3887 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3888 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3889 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3890 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3891 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3892 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3893 * of TC = 4. */
3894 if (cfg.si13_present) {
3895 testcase.stop("Error: Cannot have SI13alt and SI13");
3896 }
3897 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003899 }
3900 if (not cfg.bcch_extended) {
3901 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3902 } else {
3903 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3904 }
3905 }
3906 if (cfg.si2n_present) {
3907 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3908 * as determined by the system operator. In the case that the message is sent on the
3909 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3910 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3911 * consecutive occurrences of TC = 4. */
3912 if (not cfg.bcch_extended) {
3913 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3914 } else {
3915 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3916 }
3917 }
3918 if (cfg.si21_present) {
3919 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3920 * determined by the system operator. If Extended Access Barring is in use in the cell
3921 * then this message is sent at least once within any of 4 consecutive occurrences of
3922 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3923 * cell then this message shall only be sent on BCCH Ext. */
3924 if (not cfg.bcch_extended) {
3925 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3926 } else {
3927 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3928 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003930 }
3931 }
3932 }
3933 if (cfg.si22_present) {
3934 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3935 * should not be sent in a cell where SoLSA is used (see rule viii). System
3936 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3937 * =2 and TC=6. */
3938 if (cfg.si16_present or cfg.si17_present) {
3939 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3940 }
3941 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3942 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003944 }
3945 if (not cfg.bcch_extended) {
3946 testcase.stop("Error: SI22 requires BCCH Extd!");
3947 } else {
3948 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3949 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3950 }
3951 }
3952}
3953
3954/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003955private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3956return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003957 timer T := duration;
3958 var SystemInformationVectorPerTc si_per_tc;
3959 var L1ctlDlMessage l1_dl;
3960
3961 /* initialize all per-TC vectors empty */
3962 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3963 si_per_tc[i] := {};
3964 }
3965
3966 /* flush all previous L1 queued msgs */
3967 pt.clear;
3968
3969 T.start;
3970 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003971 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003972 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3973 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3974 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003975 repeat;
3976 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003977
Harald Welte48494ca2018-02-25 16:59:50 +01003978 var integer tc := f_gsm_compute_tc(sig.frame_number);
3979 log("SI received at TC=", tc, ": ", sig.si);
3980 /* append to the per-TC bucket */
3981 si_per_tc[tc] := si_per_tc[tc] & { sig };
3982 repeat;
3983 }
3984 [] pt.receive { repeat; }
3985 [] T.timeout { }
3986 }
3987
3988 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3989 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3990 }
3991 log("si_per_tc=", si_per_tc);
3992 return si_per_tc;
3993}
3994
3995/* helper function: Set given SI via RSL + validate scheduling.
3996 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02003997private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003998 var SystemInformationVectorPerTc si_per_tc;
3999 f_init_l1ctl();
4000 f_l1_tune(L1CTL);
4001
4002 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004003 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004004 f_validate_si_scheduling(si_cfg, si_per_tc);
4005
4006 setverdict(pass);
4007}
4008
4009testcase TC_si_sched_default() runs on test_CT {
4010 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004011 /* 2+3+4 are mandatory and set in f_init() */
4012 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004014}
4015
4016testcase TC_si_sched_1() runs on test_CT {
4017 f_init();
4018 si_cfg.si1_present := true;
4019 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004020 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004022}
4023
4024testcase TC_si_sched_2bis() runs on test_CT {
4025 f_init();
4026 si_cfg.si2bis_present := true;
4027 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4028 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004030}
4031
4032testcase TC_si_sched_2ter() runs on test_CT {
4033 f_init();
4034 si_cfg.si2ter_present := true;
4035 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4036 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004038}
4039
4040testcase TC_si_sched_2ter_2bis() runs on test_CT {
4041 f_init();
4042 si_cfg.si2bis_present := true;
4043 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4044 si_cfg.si2ter_present := true;
4045 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4046 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004048}
4049
4050testcase TC_si_sched_2quater() runs on test_CT {
4051 f_init();
4052 si_cfg.si2quater_present := true;
4053 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004054 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004056}
4057
4058testcase TC_si_sched_13() runs on test_CT {
4059 f_init();
4060 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004061 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004062 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004064}
4065
4066testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4067 f_init();
4068 si_cfg.si2bis_present := true;
4069 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4070 si_cfg.si2ter_present := true;
4071 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4072 si_cfg.si2quater_present := true;
4073 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4074 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004075 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004076 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004078}
4079
4080
Harald Welte68e495b2018-02-25 00:05:57 +01004081testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004082 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004083 /* FIXME: enable / disable individual BCCH info */
4084 //ts_RSL_BCCH_INFO(si_type, info);
4085 /* expect no ERROR REPORT after either of them *
4086 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004088}
4089
Harald Welte93640c62018-02-25 16:59:33 +01004090/***********************************************************************
4091 * Low-Level Protocol Errors / ERROR REPORT
4092 ***********************************************************************/
4093
Harald Welte01d982c2018-02-25 01:31:40 +01004094private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4095 timer T := 5.0;
4096 T.start;
4097 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004098 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004099 setverdict(pass);
4100 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004101 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004103 }
4104 [] RSL_CCHAN.receive {
4105 repeat;
4106 }
4107 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004109 }
4110 }
4111}
4112
4113/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4114testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004115 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004116 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4117 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004118 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004119
4120 f_exp_err_rep(RSL_ERR_PROTO);
4121}
4122
4123/* Provoke a mandatory IE error and match on ERROR REPORT */
4124testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004125 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004126
4127 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4128 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004129 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004130
4131 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4132}
4133
4134/* Provoke an IE content error and match on ERROR REPORT */
4135testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004136 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004137 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4138 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004139 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004140
4141 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4142}
4143
Harald Welteee25aae2019-05-19 14:32:37 +02004144/* attempt to activate channel with wrong RSL Message Discriminator IE */
4145function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4146 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4147 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4148 RSL.send(rsl);
4149 f_rslem_unregister(0, g_chan_nr);
4150}
4151testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4152 var ConnHdlr vc_conn;
4153 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4154
Harald Welte10474062019-05-30 16:48:17 +02004155 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004156
4157 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4158 vc_conn.done;
4159 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4160
4161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4162}
4163
4164/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004165private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004166 var template (value) RSL_Message rsl_tx;
4167 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4168 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4169 RSL.send(rsl_tx);
4170 f_rslem_unregister(0, g_chan_nr);
4171}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004172private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004173 var template (value) RSL_Message rsl_tx;
4174 /* we first have to activate the dedicated channel */
4175 f_rsl_chan_act(g_pars.chan_mode);
4176 /* ... to then send an invalid RLL message */
4177 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4178 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4179 RSL.send(rsl_tx);
4180 f_rslem_unregister(0, g_chan_nr);
4181}
4182testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4183 var ConnHdlr vc_conn;
4184 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4185 var template (value) RSL_Message rsl_tx;
4186
Harald Welte10474062019-05-30 16:48:17 +02004187 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004188
4189 /* Common Channel with wrong message type */
4190 RSL_CCHAN.clear;
4191 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4192 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004193 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004194 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4195
4196 /* TRX Management */
4197 RSL_CCHAN.clear;
4198 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4199 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004200 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004201 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4202
4203 /* Dedicated Channel */
4204 RSL_CCHAN.clear;
4205 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4206 vc_conn.done;
4207 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4208
4209 /* RLL */
4210 RSL_CCHAN.clear;
4211 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4212 vc_conn.done;
4213 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4214}
4215
4216/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004217private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004218 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4219 f_rslem_unregister(0, g_chan_nr);
4220}
4221testcase TC_err_rep_wrong_sequence() runs on test_CT {
4222 var ConnHdlr vc_conn;
4223 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4224
Harald Welte10474062019-05-30 16:48:17 +02004225 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004226
4227 RSL_CCHAN.clear;
4228 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4229 vc_conn.done;
4230 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4231}
4232
Harald Welte93640c62018-02-25 16:59:33 +01004233/***********************************************************************
4234 * IPA CRCX/MDCX/DLCS media stream handling
4235 ***********************************************************************/
4236
Harald Weltea871a382018-02-25 02:03:14 +01004237/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004238private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004239 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4240 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004241}
4242testcase TC_ipa_dlcx_not_active() runs on test_CT {
4243 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004244 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004245 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4246 vc_conn.done;
4247}
Harald Welte68e495b2018-02-25 00:05:57 +01004248
Harald Weltea3f1df92018-02-25 12:49:55 +01004249/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004250private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004251 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4252 "IPA CRCX ACK");
4253 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4254 "IPA CRCX NACK");
4255}
4256testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4257 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004258 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004259 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4260 vc_conn.done;
4261}
4262
4263/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004264private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004265 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4266 "IPA CRCX ACK");
4267 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4268 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4269 var uint7_t rtp_pt2 := f_rnd_int(127);
4270 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4271 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4272 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4273 "IPA MDCX ACK");
4274 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4275 "IPA DLCX ACK");
4276}
4277testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4278 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004279 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004280 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4281 vc_conn.done;
4282}
4283
Harald Welte3ae11da2018-02-25 13:36:06 +01004284/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004285private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004286 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4287 "IPA CRCX ACK");
4288 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4289 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4290 var uint7_t rtp_pt2 := f_rnd_int(127);
4291 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4292 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4293 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4294 "IPA MDCX ACK");
4295 /* Second MDCX */
4296 remote_ip := f_rnd_int(c_UINT32_MAX);
4297 remote_port := f_rnd_int(c_UINT16_MAX);
4298 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4299 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4300 "IPA MDCX ACK");
4301 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4302 "IPA DLCX ACK");
4303}
4304testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4305 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004306 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004307 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4308 vc_conn.done;
4309}
4310
Harald Welte9912eb52018-02-25 13:30:15 +01004311/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004312private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004313 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4314 "IPA CRCX NACK");
4315}
4316testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4317 var ConnHdlrPars pars;
4318 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004319 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004320
4321 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4322 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4323 vc_conn.done;
4324
4325 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4326 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4327 vc_conn.done;
4328}
4329
Harald Weltea3f1df92018-02-25 12:49:55 +01004330
Harald Welte883340c2018-02-28 18:59:29 +01004331/***********************************************************************
4332 * PCU Socket related tests
4333 ***********************************************************************/
4334
Harald Welte07bd2d22019-05-25 11:03:30 +02004335/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004336friend 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 +01004337runs on test_CT {
4338 timer T := 3.0;
4339
4340 /* we don't expect any RTS.req before PDCH are active */
4341 T.start;
4342 alt {
4343 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004345 }
4346 [] PCU.receive { repeat; }
4347 [] T.timeout { }
4348 }
4349
4350 /* Send PDCH activate request for known PDCH timeslot */
4351 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4352
4353 /* we now expect RTS.req for this timeslot (only) */
4354 T.start;
4355 alt {
4356 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4357 setverdict(pass);
4358 }
4359 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4360 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004362 }
4363 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004365 }
4366 [] PCU.receive { repeat; }
4367 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004369 }
4370 [not exp_success] T.timeout {
4371 setverdict(pass);
4372 }
4373 }
4374}
4375
Harald Welte07bd2d22019-05-25 11:03:30 +02004376/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004377friend 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 +01004378runs on test_CT {
4379 timer T := 3.0;
4380
4381 /* Send PDCH activate request for known PDCH timeslot */
4382 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 +02004383 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4384 * when it will actually have been executed in the BTS */
4385 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004386 PCU.clear;
4387 /* we now expect no RTS.req for this timeslot */
4388 T.start;
4389 alt {
4390 [] 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 +02004391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004392 }
4393 [] PCU.receive { repeat; }
4394 [] T.timeout {
4395 setverdict(pass);
4396 }
4397 }
4398}
4399
Harald Weltead033dc2019-05-25 17:28:16 +02004400friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004401 f_init();
4402 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4403}
4404
Harald Welte883340c2018-02-28 18:59:29 +01004405/* PDCH activation via PCU socket; check for presence of RTS.req */
4406testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004407 f_init_pcu_test();
4408
Harald Welte883340c2018-02-28 18:59:29 +01004409 f_TC_pcu_act_req(0, 0, 7, true);
4410}
4411
4412/* PDCH activation via PCU socket on non-PDCU timeslot */
4413testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004414 f_init_pcu_test();
4415
Harald Welte883340c2018-02-28 18:59:29 +01004416 f_TC_pcu_act_req(0, 0, 1, false);
4417}
4418
4419/* PDCH activation via PCU socket on wrong BTS */
4420testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004421 f_init_pcu_test();
4422
Harald Welte883340c2018-02-28 18:59:29 +01004423 f_TC_pcu_act_req(23, 0, 7, false);
4424}
4425
4426/* PDCH activation via PCU socket on wrong TRX */
4427testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004428 f_init_pcu_test();
4429
Harald Welte883340c2018-02-28 18:59:29 +01004430 f_TC_pcu_act_req(0, 23, 7, false);
4431}
4432
4433/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4434testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004435 f_init_pcu_test();
4436
Harald Welte883340c2018-02-28 18:59:29 +01004437 /* Activate PDCH */
4438 f_TC_pcu_act_req(0, 0, 7, true);
4439 f_sleep(1.0);
4440 /* and De-Activate again */
4441 f_TC_pcu_deact_req(0, 0, 7);
4442}
4443
4444/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4445testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004446 f_init_pcu_test();
4447
Harald Welte883340c2018-02-28 18:59:29 +01004448 f_TC_pcu_deact_req(0, 0, 1);
4449}
4450
4451/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4452testcase TC_pcu_ver_si13() runs on test_CT {
4453 const octetstring si13 := '00010203040506070909'O;
4454 var PCUIF_send_data sd;
4455 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004456 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004457
4458 /* Set SI13 via RSL */
4459 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004460
Harald Welte883340c2018-02-28 18:59:29 +01004461 T.start;
4462 alt {
4463 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4464 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4465 setverdict(pass);
4466 } else {
4467 repeat;
4468 }
4469 }
4470 [] PCU.receive { repeat; }
4471 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004473 }
4474 }
4475}
4476
4477private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4478
4479/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004480friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004481 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4482runs on test_CT
4483{
4484 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4485 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4486}
4487
4488/* 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 +02004489friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4490 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004491runs on test_CT
4492{
4493 var PCUIF_send_data sd;
4494
4495 timer T := 3.0;
4496 T.start;
4497 alt {
4498 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4499 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4500 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4501 sd.data.u.rts_req.fn, sapi, data);
4502 }
4503 [] PCU.receive { repeat; }
4504 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004506 }
4507 }
4508}
4509
4510/* Send DATA.req on invalid BTS */
4511testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004512 var TfiUsfArr tua := f_TfiUsfArrInit();
4513 var octetstring data := '0000'O & f_rnd_octstring(21);
4514
4515 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004516
Harald Welte883340c2018-02-28 18:59:29 +01004517 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004518 f_TfiUsfArrSet(tua, 7, 0);
4519 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4520 f_sleep(1.0);
4521
4522 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004523}
4524
4525/* Send DATA.req on invalid TRX */
4526testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004527 var TfiUsfArr tua := f_TfiUsfArrInit();
4528 var octetstring data := '0000'O & f_rnd_octstring(21);
4529
4530 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004531
Harald Welte883340c2018-02-28 18:59:29 +01004532 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004533 f_TfiUsfArrSet(tua, 7, 0);
4534 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4535 f_sleep(1.0);
4536
4537 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004538}
4539
4540/* Send DATA.req on invalid timeslot */
4541testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004542 var TfiUsfArr tua := f_TfiUsfArrInit();
4543 var octetstring data := '0000'O & f_rnd_octstring(21);
4544
4545 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004546
Harald Welte883340c2018-02-28 18:59:29 +01004547 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004548 f_TfiUsfArrSet(tua, 7, 0);
4549 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4550 f_sleep(1.0);
4551
4552 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004553}
4554
4555/* Send DATA.req on timeslot that hasn't been activated */
4556testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004557 var TfiUsfArr tua := f_TfiUsfArrInit();
4558 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004559
Harald Welte7162a612019-05-26 12:56:09 +02004560 f_virtphy_common();
4561
4562 f_TfiUsfArrSet(tua, 7, 0);
4563 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4564 f_sleep(1.0);
4565
4566 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004567}
4568
Harald Weltead033dc2019-05-25 17:28:16 +02004569private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004570 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4571 boolean wait_rts := true)
4572runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004573 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004574 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004575
4576 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004577 if (wait_rts) {
4578 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4579 } else {
4580 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4581 }
Harald Weltead033dc2019-05-25 17:28:16 +02004582
4583 T.start;
4584 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004585 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004586 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4587 setverdict(pass);
4588 }
Harald Welte7162a612019-05-26 12:56:09 +02004589 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4590 setverdict(fail, "Received unexpected ", rx_dl);
4591 }
Harald Weltead033dc2019-05-25 17:28:16 +02004592 [] L1CTL.receive {
4593 repeat;
4594 }
Harald Welte7162a612019-05-26 12:56:09 +02004595 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004596 setverdict(fail, "Timeout waiting for ", data);
4597 }
Harald Welte7162a612019-05-26 12:56:09 +02004598 [not expect_data] T.timeout {
4599 setverdict(pass);
4600 }
Harald Weltead033dc2019-05-25 17:28:16 +02004601 }
4602}
4603
4604private function f_disable_dynamic_ts() runs on test_CT
4605{
4606 f_init_vty_bsc();
4607 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4608 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4609 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4610 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004611 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004612}
4613
4614private function f_virtphy_common() runs on test_CT {
4615 f_disable_dynamic_ts();
4616 f_init_l1ctl();
4617 f_l1_tune(L1CTL);
4618}
4619
4620testcase TC_pcu_data_req_pdtch() runs on test_CT {
4621 var TfiUsfArr tua := f_TfiUsfArrInit();
4622 var octetstring data := '0000'O & f_rnd_octstring(21);
4623
4624 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004625
Harald Welte883340c2018-02-28 18:59:29 +01004626 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004627 f_TfiUsfArrSet(tua, 7, 0);
4628 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4629 f_sleep(1.0);
4630
4631 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004632}
4633
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004634/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004635testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004636 var TfiUsfArr tua := f_TfiUsfArrInit();
4637 var octetstring data := '0000'O & f_rnd_octstring(21);
4638
4639 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004640
Harald Welte883340c2018-02-28 18:59:29 +01004641 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004642 f_TfiUsfArrSet(tua, 7, 0);
4643 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4644 f_sleep(1.0);
4645
4646 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004647}
4648
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004649private function f_TC_pcu_ptcch_ul(uint16_t ra)
4650runs on test_CT {
4651 var template PCUIF_Message pcu_rach_ind;
4652 var PCUIF_send_data sd;
4653 var GsmFrameNumber fn;
4654 timer T;
4655
4656 /* Send an Access Burst on PTCCH/U over the Um-interface */
4657 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4658 chan_nr := ts_RslChanNr_PDCH(7),
4659 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4660
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004661 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4662 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004663
4664 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4665 T.start(52.0 * 4.615 / 1000.0);
4666 alt {
4667 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4668 log("Rx an Access Burst on the PCU interface: ", sd.data);
4669 setverdict(pass);
4670 T.stop;
4671 }
4672 [] PCU.receive { repeat; }
4673 [] T.timeout {
4674 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4675 /* Keep going, that's not the end of the world */
4676 }
4677 }
4678}
4679
4680testcase TC_pcu_ptcch() runs on test_CT {
4681 var L1ctlDlMessage dl;
4682 var octetstring data;
4683 timer T;
4684
4685 f_init_pcu_test();
4686 f_init_l1ctl();
4687 f_l1_tune(L1CTL);
4688
4689 /* Activate PDCH channel on TS7 */
4690 f_TC_pcu_act_req(0, 0, 7, true);
4691
4692 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004693 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004694 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004695 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004696 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004697
4698 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4699 for (var integer i := 0; i < 16; i := i + 1) {
4700 log("Sending an Access Burst towards the L1CTL interface");
4701 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4702 }
4703
4704 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4705 data := f_rnd_octstring(23);
4706
4707 /* Verify PTCCH/D: send a random data block, make sure it's received */
4708 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4709 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4710
4711 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4712 * let's give it more time in case if we miss the beginning. */
4713 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4714 alt {
4715 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4716 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4717 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4718 frame := data)) -> value dl {
4719 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4720 setverdict(pass);
4721 T.stop;
4722 }
4723 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4724 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4725 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4726 l2_data := data)) -> value dl {
4727 log("Rx PTCCH/D data block on L1CTL: ", dl);
4728 setverdict(pass);
4729 T.stop;
4730 }
4731 [] L1CTL.receive { repeat; }
4732 [] T.timeout {
4733 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4734 }
4735 }
4736}
4737
Harald Welte883340c2018-02-28 18:59:29 +01004738/* Send AGCH from PCU; check it appears on Um side */
4739testcase TC_pcu_data_req_agch() runs on test_CT {
4740 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004741 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004742 f_init_l1ctl();
4743 f_l1_tune(L1CTL);
4744
4745 f_TC_pcu_act_req(0, 0, 7, true);
4746 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4747
4748 T.start;
4749 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004750 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004751 setverdict(pass);
4752 }
4753 [] L1CTL.receive { repeat; }
4754 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004756 }
4757 }
4758}
4759
Harald Welte928622b2019-05-26 13:22:59 +02004760/* Send AGCH from PCU; check it appears on Um side */
4761testcase TC_pcu_data_req_pch() runs on test_CT {
4762 timer T := 3.0;
4763 f_init_pcu_test();
4764 f_init_l1ctl();
4765 f_l1_tune(L1CTL);
4766
4767 f_TC_pcu_act_req(0, 0, 7, true);
4768 /* three characters prefix: last 3 digits of IMSI as ASCII */
4769 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4770
4771 T.start;
4772 alt {
4773 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4774 setverdict(pass);
4775 }
4776 [] L1CTL.receive { repeat; }
4777 [] T.timeout {
4778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4779 }
4780 }
4781}
4782
Harald Welte883340c2018-02-28 18:59:29 +01004783/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4784testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4785 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004786 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004787 f_init_l1ctl();
4788 f_l1_tune(L1CTL);
4789
4790 /* append 3 last imsi digits so BTS can compute pagng group */
4791 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4792
4793 timer T := 0.5;
4794 T.start;
4795 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004796 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004797 /* TODO: verify paging group */
4798 setverdict(pass);
4799 }
4800 [] L1CTL.receive { repeat; }
4801 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004803 }
4804 }
4805}
4806
4807/* Send RACH from Um side, expect it to show up on PCU socket */
4808testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004809 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004810 f_init_l1ctl();
4811 f_l1_tune(L1CTL);
4812
4813 var GsmFrameNumber fn_last := 0;
4814 for (var integer i := 0; i < 1000; i := i+1) {
4815 var OCT1 ra := f_rnd_ra_ps();
4816 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4817 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004819 }
4820 fn_last := fn;
4821
4822 timer T := 2.0;
4823 T.start;
4824 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004825 [] 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 +01004826 T.stop;
4827 }
4828 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004830 }
4831 [] PCU.receive { repeat; }
4832 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004834 }
4835 }
4836 }
4837 setverdict(pass);
4838}
4839
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004840/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4841 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4842testcase TC_pcu_ext_rach_content() runs on test_CT {
4843 var template PCUIF_Message pcu_rach_ind;
4844 var GsmFrameNumber fn_last := 0;
4845 var L1ctlRachSynchSeq synch_seq;
4846 var PCUIF_BurstType pcu_bt;
4847 var GsmFrameNumber fn;
4848 var BIT11 ra11;
4849
4850 f_init_pcu_test();
4851 f_init_l1ctl();
4852 f_l1_tune(L1CTL);
4853
4854 for (var integer i := 0; i < 1000; i := i+1) {
4855 /* We need to test both TS1 & TS2 */
4856 if (i rem 2 == 0) {
4857 synch_seq := RACH_SYNCH_SEQ_TS1;
4858 pcu_bt := BURST_TYPE_1;
4859 } else {
4860 synch_seq := RACH_SYNCH_SEQ_TS2;
4861 pcu_bt := BURST_TYPE_2;
4862 }
4863
4864 ra11 := f_rnd_ra11_ps();
4865 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4866 if (fn == fn_last) {
4867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4868 "Two RACH in same FN?!?");
4869 }
4870 fn_last := fn;
4871
4872 /* Compose the expected message */
4873 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004874 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004875 ra := bit2int(ra11),
4876 is_11bit := 1,
4877 burst_type := pcu_bt,
4878 fn := fn);
4879
4880 timer T := 2.0;
4881 T.start;
4882 alt {
4883 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4884 T.stop;
4885 }
4886 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4888 }
4889 [] PCU.receive { repeat; }
4890 [] T.timeout {
4891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4892 }
4893 }
4894 }
4895 setverdict(pass);
4896}
4897
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004898private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4899runs on test_CT {
4900 var template PCUIF_send_data sdt;
4901 var PCUIF_send_data sd;
4902 var int16_t lqual_cb;
4903 timer T := 1.0;
4904
4905 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4906 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4907
4908 /* Send a random PDTCH frame over Um */
4909 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4910 '0000'O & f_rnd_octstring(21)));
4911
4912 T.start;
4913 alt {
4914 /* If expected link quality is above the threshold */
4915 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4916 lqual_cb := sd.data.u.data_ind.lqual_cb;
4917 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4918
4919 /* Make sure the actual link quality matches the expected value */
4920 if (not match(lqual_cb, lqual_cb_exp)) {
4921 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4922 "expected value ", lqual_cb_exp));
4923 } else {
4924 setverdict(pass);
4925 }
4926 }
4927 /* If expected link quality is below the threshold */
4928 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4930 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4931 }
4932 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4933 [] PCU.receive { repeat; }
4934 [lqual_cb_exp < thresh] T.timeout {
4935 log("Rx nothing, as expected");
4936 setverdict(pass);
4937 }
4938 [lqual_cb_exp >= thresh] T.timeout {
4939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4940 "Timeout waiting for PCUIF_DATA.ind");
4941 }
4942 }
4943}
4944
4945/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4946testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4947 f_init_pcu_test();
4948 PCU.clear;
4949
4950 f_init_l1ctl();
4951 f_l1_tune(L1CTL);
4952
4953 /* Activate a PDCH channel on TS7 */
4954 f_TC_pcu_act_req(0, 0, 7, true);
4955
4956 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004957 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004958 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004959 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004960 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004961
4962 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4963 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4964 var TrxcMessage ret;
4965
4966 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4967 valueof(ts_TRXC_FAKE_CI(i)));
4968
4969 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4970 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4971 }
4972}
4973
Harald Welte883340c2018-02-28 18:59:29 +01004974/* Send PAGING via RSL, expect it to shw up on PCU socket */
4975testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004976 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004977
4978 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004979 var MobileIdentityLV mi_lv;
4980 var octetstring mi_lv_enc;
4981 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004982 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004983
Harald Welte883340c2018-02-28 18:59:29 +01004984 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004985 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004986 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004987 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004988 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004989
4990 /* Fancy encoding for PCUIF */
4991 mi_lv := valueof(ts_MI_LV(mi));
4992 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4993 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004994
4995 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004996 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004997 T.start;
4998 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004999 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005000 }
5001 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005003 }
5004 [] PCU.receive { repeat; }
5005 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005007 }
5008 }
5009 }
5010 setverdict(pass);
5011}
5012
Harald Welted66c9b82019-05-25 09:03:15 +02005013/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5014testcase TC_pcu_time_ind() runs on test_CT {
5015 var PCUIF_send_data pcu_sd;
5016 var integer num_time_ind := 0;
5017 var integer first_fn, last_fn;
5018 var float test_duration := 5.0;
5019 timer T;
5020
5021 f_init_pcu_test();
5022 f_TC_pcu_act_req(0, 0, 7, true);
5023
5024 PCU.clear;
5025 T.start(test_duration);
5026 alt {
5027 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5028 num_time_ind := num_time_ind + 1;
5029 if (not isbound(first_fn)) {
5030 first_fn := pcu_sd.data.u.time_ind.fn;
5031 }
5032 last_fn := pcu_sd.data.u.time_ind.fn;
5033 repeat;
5034 }
5035 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5036 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5037 repeat;
5038 }
5039 [] PCU.receive {
5040 repeat;
5041 }
5042 [] T.timeout {}
5043 }
5044 var integer fn_expired := last_fn - first_fn;
5045 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5046
5047 /* verify the number of frames expired matches our expectation */
5048 const float c_GSM_FN_DURATION_MS := 4.61538;
5049 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005050 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005051 if (not match(fn_expired, t_fn_expected)) {
5052 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5053 }
5054
5055 /* There are three TIME.ind in every fn MOD 13 */
5056 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5057 /* Add some tolerance */
5058 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5059 if (not match(num_time_ind, t_time_ind_exp)) {
5060 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5061 }
5062
5063 setverdict(pass);
5064}
5065
Harald Welte4832c862019-05-25 14:57:18 +02005066/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5067testcase TC_pcu_rts_req() runs on test_CT {
5068 var PCUIF_send_data pcu_sd;
5069 var integer first_fn, last_fn;
5070 var integer num_rts_pdtch := 0;
5071 var integer num_rts_ptcch := 0;
5072 var float test_duration := 5.0;
5073 timer T;
5074
5075 f_init_pcu_test();
5076 f_TC_pcu_act_req(0, 0, 7, true);
5077
5078 PCU.clear;
5079 T.start(test_duration);
5080 alt {
5081 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5082 -> value pcu_sd {
5083 num_rts_pdtch := num_rts_pdtch + 1;
5084 if (not isbound(first_fn)) {
5085 first_fn := pcu_sd.data.u.rts_req.fn;
5086 }
5087 last_fn := pcu_sd.data.u.rts_req.fn;
5088 repeat;
5089 }
5090 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5091 -> value pcu_sd {
5092 num_rts_ptcch := num_rts_ptcch + 1;
5093 if (not isbound(first_fn)) {
5094 first_fn := pcu_sd.data.u.rts_req.fn;
5095 }
5096 last_fn := pcu_sd.data.u.rts_req.fn;
5097 repeat;
5098 }
5099 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5100 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5101 repeat;
5102 }
5103 [] PCU.receive {
5104 repeat;
5105 }
5106 [] T.timeout {}
5107 }
5108 var integer fn_expired := last_fn - first_fn;
5109 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5110 ", num_rts_ptcch=", num_rts_ptcch);
5111
5112 /* verify the number of frames expired matches our expectation */
5113 const float c_GSM_FN_DURATION_MS := 4.61538;
5114 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005115 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005116 if (not match(fn_expired, t_fn_expected)) {
5117 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5118 }
5119
5120 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5121 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5122 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5123 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5124 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5125 t_ptcch_exp);
5126 }
5127
5128 /* We have 12 PDTCH blocks every 52-multiframe */
5129 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5130 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5131 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5132 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5133 t_pdtch_exp);
5134 }
5135
5136 setverdict(pass);
5137}
5138
Harald Welte07bd2d22019-05-25 11:03:30 +02005139/* test for generating Abis side OML ALERT from the PCU */
5140testcase TC_pcu_oml_alert() runs on test_CT {
5141 var PCUIF_send_data pcu_sd;
5142 var integer num_time_ind := 0;
5143 var integer first_fn, last_fn;
5144 var float test_duration := 5.0;
5145 timer T;
5146
5147 f_init_pcu_test();
5148 f_TC_pcu_act_req(0, 0, 7, true);
5149
5150 /* re-connect CTRL port from BTS to BSC */
5151 f_ipa_ctrl_stop();
5152 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5153
5154 /* Send that OML Alert */
5155 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5156
5157 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5158 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5159 setverdict(pass);
5160}
5161
Harald Welteeaa9a862019-05-26 23:01:08 +02005162/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5163private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5164 var PCUIF_Message first_info;
5165 var integer pcu_conn_id := -1;
5166 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5167 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5168 var OCT4 tlli := '01020304'O;
5169 var OCT1 cause := '23'O;
5170 timer T := 5.0;
5171
5172 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5173
5174 f_l1_tune(L1CTL);
5175 RSL.clear;
5176
5177 f_est_dchan();
5178 L1CTL.clear;
5179
5180 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5181
5182 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5183 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5184 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5185
5186 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5187 T.start;
5188 alt {
5189 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5190 setverdict(pass);
5191 }
5192 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5193 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5194 }
5195 [] PCU.receive {
5196 repeat;
5197 }
5198 [] T.timeout {
5199 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5200 }
5201 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005202
5203 /* release the channel */
5204 f_rsl_chan_deact();
5205 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5206 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005207}
5208testcase TC_pcu_rr_suspend() runs on test_CT {
5209 var ConnHdlrPars pars;
5210 var ConnHdlr vc_conn;
5211
5212 f_init();
5213
5214 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5215 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5216 vc_conn.done;
5217}
Harald Welte07bd2d22019-05-25 11:03:30 +02005218
Harald Weltea2e0e942019-05-27 18:12:53 +02005219/* Ensure that PCUIF socket can accept only a single connection */
5220testcase TC_pcu_socket_connect_multi() runs on test_CT {
5221 timer T := 5.0;
5222
5223 /* this (among other things) establishes the first connection to the PCUIF socket */
5224 f_init();
5225
5226 /* try to establish a second connection, expect it to fail */
5227 PCU.send(UD_connect:{mp_pcu_socket, -1});
5228 T.start;
5229 alt {
5230 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5231 setverdict(pass);
5232 }
5233 [] PCU.receive(UD_connect_result:?) {
5234 setverdict(fail, "Unexpected unix domain connect result");
5235 }
5236 [] T.timeout {
5237 setverdict(pass);
5238 }
5239 }
5240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5241}
5242
Harald Weltec8effb72019-05-27 18:23:04 +02005243/* Ensure that PCUIF socket can disconnect + reconnect */
5244testcase TC_pcu_socket_reconnect() runs on test_CT {
5245 /* this (among other things) establishes the first connection to the PCUIF socket */
5246 f_init();
5247
5248 f_sleep(1.0);
5249
5250 f_pcuif_close(PCU, g_pcu_conn_id);
5251 g_pcu_conn_id := -1;
5252
5253 f_sleep(1.0);
5254
5255 /* re-connect */
5256 PCU.clear;
5257 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5258 setverdict(pass);
5259
5260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5261}
5262
Harald Weltebe030482019-05-27 22:29:35 +02005263/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005264private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5265runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005266 var L1ctlDlMessage l1_dl;
5267 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005268 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005269 timer T := 5.0;
5270 T.start;
5271 alt {
5272 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005273 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5274 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005275 repeat;
5276 }
5277 }
5278 [] pt.receive {
5279 repeat;
5280 }
5281 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5283 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005284 }
5285 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005286 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005287}
5288
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005289/* Check if GPRS Indicator is present in RR System Information of a given type */
5290private function f_si_has_gprs_indicator(RrMessageType si_type)
5291runs on test_CT return boolean {
5292 var SystemInformation si := f_get_si(L1CTL, si_type);
5293
5294 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005295 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005296 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005297 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005298 }
5299
5300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5301 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005302}
5303
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005304/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5305private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5306runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005307 /* don't call f_init() as this would connect PCU socket */
5308 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005309
5310 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005311 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005312 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005313
5314 f_init_l1ctl();
5315 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005316 f_sleep(2.0);
5317 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005318
5319 if (f_si_has_gprs_indicator(si_type)) {
5320 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005321 } else {
5322 setverdict(pass);
5323 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005324
Harald Weltebe030482019-05-27 22:29:35 +02005325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5326}
5327
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005328testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5329 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5330}
Harald Weltebe030482019-05-27 22:29:35 +02005331
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005332testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5333 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5334}
5335
5336/* Ensure that GPRS capability is advertised after PCU socket connect */
5337private function f_TC_pcu_socket_connect(RrMessageType si_type)
5338runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005339 /* this (among other things) establishes the first connection to the PCUIF socket */
5340 f_init();
5341 f_init_l1ctl();
5342 f_l1_tune(L1CTL);
5343
5344 f_sleep(2.0);
5345 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005346
5347 if (not f_si_has_gprs_indicator(si_type)) {
5348 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005349 } else {
5350 setverdict(pass);
5351 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005352
Harald Weltebe030482019-05-27 22:29:35 +02005353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5354}
5355
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005356testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5357 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5358}
Harald Weltebe030482019-05-27 22:29:35 +02005359
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005360testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5361 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5362}
5363
5364/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5365private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5366runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005367 /* this (among other things) establishes the first connection to the PCUIF socket */
5368 f_init();
5369 f_init_l1ctl();
5370 f_l1_tune(L1CTL);
5371
5372 f_pcuif_close(PCU, g_pcu_conn_id);
5373 g_pcu_conn_id := -1;
5374
5375 f_sleep(1.0);
5376
5377 /* re-connect */
5378 PCU.clear;
5379 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5380
5381 f_sleep(2.0);
5382 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005383
5384 if (f_si_has_gprs_indicator(si_type)) {
5385 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005386 } else {
5387 setverdict(pass);
5388 }
5389
5390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5391}
5392
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005393testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5394 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5395}
5396
5397testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5398 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5399}
5400
Oliver Smithf5239c72019-08-28 10:01:25 +02005401/* 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) */
5402testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5403 var SystemInformation si3 := valueof(ts_SI3_default);
5404
5405 f_init();
5406
Harald Welte76220222020-10-11 20:32:44 +02005407 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5408 * information */
5409 timer T := 2.0;
5410 T.start;
5411 alt {
5412 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5413 [] T.timeout {}
5414 }
5415
Oliver Smithf5239c72019-08-28 10:01:25 +02005416 /* Verify cell_id */
5417 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5418 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5419 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005420 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5421 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5422 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005423 }
5424
5425 /* Verify LAC */
5426 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5427 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5428 if (lac_si3 != lac_pcu) {
5429 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5430 }
5431
5432 setverdict(pass);
5433}
Harald Welted66c9b82019-05-25 09:03:15 +02005434
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005435/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5436testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5437 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005438 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005439
5440 f_init();
5441
5442 info_ind := g_pcu_last_info.u.info_ind;
5443
5444 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5445 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5446 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5447 /* Skip inactive timeslots */
5448 continue;
5449 }
5450
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005451 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005452 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005453 else
5454 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005455
5456 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005457 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005458 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005459 hsn := fhp.maio_hsn.hsn,
5460 maio := fhp.maio_hsn.maio,
5461 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005462 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005463 } else {
5464 tr_ts := tr_PCUIF_InfoTrxTsH0;
5465 }
5466
5467 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5468 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5469 if (not match(ts, tr_ts)) {
5470 setverdict(fail, "Hopping parameters do not match: ",
5471 "received ", ts, " vs expected ", tr_ts);
5472 } else {
5473 setverdict(pass);
5474 }
5475 }
5476 }
5477}
5478
Alexander Couzens5283f552020-07-28 15:39:04 +02005479/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5480testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5481 f_init_vty_bsc();
5482 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5483 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5484
5485 f_init();
5486
5487 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5488 if (not ischosen(remote_addr.v10)) {
5489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5490 log2str("Unexpected remote_addr: ", remote_addr));
5491 }
5492
5493 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5494 setverdict(fail, "Received address family is not IPv4");
5495 }
5496
5497 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5498 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5499 }
5500
5501 setverdict(pass);
5502}
5503
5504/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5505testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5506 f_init_vty_bsc();
5507 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5508
5509 f_init();
5510
5511 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5512 if (not ischosen(remote_addr.v10)) {
5513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5514 log2str("Unexpected remote_addr: ", remote_addr));
5515 }
5516
5517 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5518 setverdict(fail, "Received address family is not IPv6");
5519 }
5520
5521 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5522 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5523 }
5524
5525 setverdict(pass);
5526}
5527
Harald Welte3d04ae62018-04-04 20:29:05 +02005528/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005529 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005530 ***********************************************************************/
5531
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005532private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5533 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005534runs on ConnHdlr {
5535 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005536
5537 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005538 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005539 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5540 repeat;
5541 }
5542 }
5543}
5544
5545private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5546runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005547 /* Expect BTS to immediately acknowledge activation as PDCH */
5548 PCU.clear;
5549 f_rsl_chan_act(g_pars.chan_mode);
5550 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005551 timer T_wait := 2.0;
5552 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005553 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005554 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005555 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005556 [] T_wait.timeout {
5557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5558 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5559 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005560 }
5561 /* try to activate this PDCH from the PCU point of view */
5562 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5563 /* FIXME: is there a response? */
5564}
5565
5566private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5567runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005568 /* Send RSL CHAN REL (deactivate) */
5569 PCU.clear;
5570 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5571 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005572 timer T_wait := 2.0;
5573 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005574 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005575 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005576 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005577 [] T_wait.timeout {
5578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5579 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5580 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005581 }
5582 /* Emulate PCU asking BTS to deactivate PDCH */
5583 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5584 alt {
5585 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5586 setverdict(pass);
5587 }
5588 [] RSL.receive { repeat; }
5589 }
5590}
5591
5592/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005593private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005594 var PCUIF_Message first_info;
5595 var integer ts_nr := g_chan_nr.tn;
5596 var integer trx_nr := 0;
5597 var integer bts_nr := 0;
5598 var integer pcu_conn_id := -1;
5599
5600 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5601
5602 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5603 f_sleep(3.0);
5604 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5605 setverdict(pass);
5606}
5607testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5608 var ConnHdlrPars pars;
5609 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005610 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005611
5612 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5613 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5614 vc_conn.done;
5615}
5616
5617/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005618private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005619 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005620 var integer pcu_conn_id := -1;
5621
5622 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5623
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005624 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5625 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5626 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005627 setverdict(pass);
5628}
5629testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5630 var ConnHdlrPars pars;
5631 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005632 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005633
5634 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5635 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5636 vc_conn.done;
5637}
5638
5639/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005640private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005641 var PCUIF_Message first_info;
5642 var integer ts_nr := g_chan_nr.tn;
5643 var integer trx_nr := 0;
5644 var integer bts_nr := 0;
5645 var integer pcu_conn_id := -1;
5646
5647 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5648
5649 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005650 /* Send a second Chan Activ and expect it to be NACKed */
5651 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5652 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005653 setverdict(pass);
5654}
5655testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5656 var ConnHdlrPars pars;
5657 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005658 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005659
5660 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5661 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5662 vc_conn.done;
5663}
5664
5665/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005666private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005667 var PCUIF_Message first_info;
5668 var integer ts_nr := g_chan_nr.tn;
5669 var integer trx_nr := 0;
5670 var integer bts_nr := 0;
5671 var integer pcu_conn_id := -1;
5672 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5673
5674 /* register for the TCH/F channel number */
5675 f_rslem_register(0, chan_nr);
5676
5677 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5678
5679 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5680 "RSL CHAN ACT");
5681 setverdict(pass);
5682}
5683testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5684 var ConnHdlrPars pars;
5685 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005686 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005687
5688 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5689 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5690 vc_conn.done;
5691}
5692
5693/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005694private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005695 var PCUIF_Message first_info;
5696 var integer ts_nr := g_chan_nr.tn;
5697 var integer trx_nr := 0;
5698 var integer bts_nr := 0;
5699 var integer pcu_conn_id := -1;
5700 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5701 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5702
5703 /* register for the TCH/H channel numbers */
5704 f_rslem_register(0, chan_nr[0]);
5705 f_rslem_register(0, chan_nr[1]);
5706
5707 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5708
5709 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5710 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5711 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5712 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5713 setverdict(pass);
5714}
5715testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5716 var ConnHdlrPars pars;
5717 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005718 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005719
5720 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5721 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5722 vc_conn.done;
5723}
5724
Harald Welte9bbbfb52018-04-05 09:33:19 +02005725/***********************************************************************
5726 * IPA Style Dynamic Timeslot Support
5727 ***********************************************************************/
5728
5729private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5730runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005731 /* Expect BTS to immediately acknowledge activation as PDCH */
5732 PCU.clear;
5733 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5734 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005735 timer T_wait := 2.0;
5736 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005737 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005738 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005739 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005740 [] T_wait.timeout {
5741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5742 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5743 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005744 }
5745 /* try to activate this PDCH from the PCU point of view */
5746 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5747 /* FIXME: is there a response? */
5748
5749 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5750}
5751
5752private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5753runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005754 /* Send RSL CHAN REL (deactivate) */
5755 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5756 PCU.clear;
5757 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005758 timer T_wait := 2.0;
5759 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005760 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005761 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005762 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005763 [] T_wait.timeout {
5764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5765 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5766 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005767 }
5768 /* Emulate PCU asking BTS to deactivate PDCH */
5769 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5770 alt {
5771 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5772 setverdict(pass);
5773 }
5774 [] RSL.receive { repeat; }
5775 }
5776}
5777
5778/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005779private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005780 var PCUIF_Message first_info;
5781 var integer ts_nr := g_chan_nr.tn;
5782 var integer trx_nr := 0;
5783 var integer bts_nr := 0;
5784 var integer pcu_conn_id := -1;
5785
5786 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5787
5788 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5789 f_sleep(3.0);
5790 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5791
5792 setverdict(pass);
5793
5794}
5795testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5796 var ConnHdlrPars pars;
5797 var ConnHdlr vc_conn;
5798 f_init();
5799
5800 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5801 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5802 vc_conn.done;
5803}
5804
5805/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005806private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005807 var PCUIF_Message first_info;
5808 var integer ts_nr := g_chan_nr.tn;
5809 var integer trx_nr := 0;
5810 var integer bts_nr := 0;
5811 var integer pcu_conn_id := -1;
5812
5813 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5814
5815 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5816 "RSL CHAN ACT");
5817 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5818 "RF CHAN REL", true);
5819 setverdict(pass);
5820}
5821testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5822 var ConnHdlrPars pars;
5823 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005824 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005825
5826 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5827 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5828 vc_conn.done;
5829}
5830
5831/* 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 +07005832private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005833 var PCUIF_Message first_info;
5834 var integer ts_nr := g_chan_nr.tn;
5835 var integer trx_nr := 0;
5836 var integer bts_nr := 0;
5837 var integer pcu_conn_id := -1;
5838
5839 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5840
5841 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5842 "RSL CHAN ACT");
5843
5844 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5845 alt {
5846 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5847 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005849 }
5850 [] RSL.receive { repeat; }
5851 }
5852
5853 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5854 "RF CHAN REL", true);
5855 setverdict(pass);
5856}
5857testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5858 var ConnHdlrPars pars;
5859 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005860 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005861
5862 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5863 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5864 vc_conn.done;
5865}
5866
5867/* 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 +07005868private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005869 var PCUIF_Message first_info;
5870 var integer ts_nr := g_chan_nr.tn;
5871 var integer trx_nr := 0;
5872 var integer bts_nr := 0;
5873 var integer pcu_conn_id := -1;
5874
5875 /* register for the TCH/F channel number */
5876 f_rslem_register(0, g_chan_nr);
5877
5878 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5879
5880 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5881
5882 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5883 "RSL CHAN ACT");
5884
5885 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5886
5887 setverdict(pass);
5888}
5889testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5890 var ConnHdlrPars pars;
5891 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005892 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005893
5894 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5895 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5896 vc_conn.done;
5897}
5898
5899
Harald Welte0472ab42018-03-12 15:02:26 +01005900/***********************************************************************
5901 * LAPDm / RLL related
5902 ***********************************************************************/
5903
5904private function f_tx_lapdm(template (value) LapdmFrame l,
5905 template (value) RslLinkId link_id) runs on ConnHdlr {
5906 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005907 var template (value) SacchL1Header l1h;
5908
5909 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005910 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005911 /* Compose dummy L1 header */
5912 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5913 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 +02005914 } else {
5915 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005916 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 +01005917 }
Harald Welte0472ab42018-03-12 15:02:26 +01005918}
5919
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005920private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005921 uint3_t sapi,
5922 RslLinkId link_id,
5923 octetstring l3,
5924 boolean exp
5925}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005926private type record of RllTestCase RllTestCases;
5927private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5928 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005929 sapi := sapi,
5930 link_id := id,
5931 l3 := l3,
5932 exp := exp
5933}
5934
5935/* execute the same callback function with a set of different parameters (tcs) on a
5936 * variety of logical channels */
5937private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5938 var ConnHdlrPars pars;
5939 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005940 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005941
5942 /* test on each of the channels we have */
5943 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5944 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5945
5946 /* test each of the test cases on the current channel */
5947 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5948 pars.spec.rll := tcs[j];
5949 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5950 vc_conn := f_start_handler(fn, pars);
5951 vc_conn.done;
5952 }
5953 }
5954
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005956}
5957
5958/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5959private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5960 var RllTestCase tc := g_pars.spec.rll;
5961 timer T := 3.0;
5962
5963 f_l1_tune(L1CTL);
5964 RSL.clear;
5965
5966 /* activate the logical channel */
5967 f_est_dchan();
5968 L1CTL.clear;
5969
5970 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5971 T.start;
5972 alt {
5973 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5974 if (tc.exp) {
5975 setverdict(pass);
5976 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005978 }
5979 }
5980 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5981 if (tc.exp) {
5982 setverdict(pass);
5983 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005985 }
5986 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005987 /* We also expect to receive the measurements */
5988 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005989 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005991 }
5992 [not tc.exp] T.timeout {
5993 setverdict(pass);
5994 }
5995 }
5996
5997 f_rsl_chan_deact();
5998 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5999 f_rslem_unregister(0, g_chan_nr);
6000}
6001testcase TC_rll_est_ind() runs on test_CT {
6002 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006003 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006004 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006005 /* normal SAPI0 establishment */
6006 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006007 /* SAPI 3 doesn't support contention resolution */
6008 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6009 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6010 /* normal SAPI3 establishment on main DCCH */
6011 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6012 /* normal SAPI3 establishment on SACCH */
6013 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6014 };
6015 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6016}
6017
6018/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6019private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6020 var RllTestCase tc := g_pars.spec.rll;
6021 var L1ctlDlMessage dl;
6022 timer T := 3.0;
6023
6024 f_l1_tune(L1CTL);
6025 RSL.clear;
6026
6027 /* activate the logical channel */
6028 f_est_dchan();
6029 L1CTL.clear;
6030
6031 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6032 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6033 T.start;
6034 alt {
6035 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6036 var LapdmFrame lapdm;
6037 var octetstring l2 := dl.payload.data_ind.payload;
6038 if (dl.dl_info.link_id.c == SACCH) {
6039 /* remove L1 header */
6040 l2 := substr(l2, 2, lengthof(l2)-2);
6041 }
6042 lapdm.ab := dec_LapdmFrameAB(l2);
6043 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6044 setverdict(pass);
6045 } else {
6046 repeat;
6047 }
6048 }
6049 [] L1CTL.receive { repeat; }
6050 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006052 }
6053 }
6054
6055 f_rsl_chan_deact();
6056 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6057 f_rslem_unregister(0, g_chan_nr);
6058}
6059testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6060 var RllTestCases tcs := {
6061 /* normal SAPI3 establishment on main DCCH */
6062 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6063 };
6064 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6065}
6066testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6067 var RllTestCases tcs := {
6068 /* normal SAPI3 establishment on SACCH */
6069 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6070 }
6071 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6072}
6073
6074/* altstep to receive a LAPDm frame matching the given template */
6075private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6076 var L1ctlDlMessage dl;
6077 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6078 var LapdmFrame lapdm;
6079 var octetstring l2 := dl.payload.data_ind.payload;
6080 if (dl.dl_info.link_id.c == SACCH) {
6081 /* remove L1 header */
6082 l2 := substr(l2, 2, lengthof(l2)-2);
6083 }
6084 if (ischosen(exp.ab)) {
6085 lapdm.ab := dec_LapdmFrameAB(l2);
6086 } else if (ischosen(exp.b4)) {
6087 lapdm.b4 := dec_LapdmFrameB4(l2);
6088 } else if (ischosen(exp.bbis)) {
6089 lapdm.bbis := dec_LapdmFrameBbis(l2);
6090 }
6091 log("Rx LAPDm ", lapdm);
6092 if (match(lapdm, exp)) {
6093 setverdict(pass);
6094 } else {
6095 repeat;
6096 }
6097 }
6098 [] L1CTL.receive { repeat; }
6099}
6100private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6101 timer T := t;
6102 T.start;
6103 alt {
6104 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006106 }
6107 [] as_l1_exp_lapdm(exp);
6108 }
6109}
6110
6111/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6112private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6113 /* send SABM from MS -> BTS */
6114 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6115 /* expect RLL EST IND on Abis */
6116 alt {
6117 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6118 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6119 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006121 }
6122 [] RSL.receive { repeat; }
6123 }
6124 /* expect UA from BTS -> MS */
6125 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6126}
6127
6128/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6129private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6130 var RllTestCase tc := g_pars.spec.rll;
6131
6132 f_l1_tune(L1CTL);
6133 RSL.clear;
6134
6135 /* activate the logical channel */
6136 f_est_dchan();
6137 L1CTL.clear;
6138
6139 /* first establish the link-layer */
6140 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6141
6142 /* then send the DISC */
6143 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6144 /* ... and expect the REL IND on the RSL side */
6145 alt {
6146 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6147 setverdict(pass);
6148 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006149 /* We also expect to receive the measurements */
6150 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006151 }
6152
6153 /* release the channel */
6154 f_rsl_chan_deact();
6155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6156 f_rslem_unregister(0, g_chan_nr);
6157}
6158testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6159 var RllTestCases tcs := {
6160 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6161 };
6162 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6163}
6164
6165testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6166 var RllTestCases tcs := {
6167 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6168 };
6169 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6170}
6171testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6172 var RllTestCases tcs := {
6173 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6174 };
6175 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6176}
6177testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6178 var RllTestCases tcs := {
6179 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6180 };
6181 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6182}
6183
6184/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6185private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6186 var RllTestCase tc := g_pars.spec.rll;
6187 f_l1_tune(L1CTL);
6188 RSL.clear;
6189
6190 /* activate the logical channel */
6191 f_est_dchan();
6192 L1CTL.clear;
6193
6194 /* first establish the link-layer */
6195 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6196
6197 /* then send the REL REQ via RSL */
6198 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6199 /* ... and expect the DISC on the Um side */
6200 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006201 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006202 /* FIXME: send a UA in resposne to the DISC */
6203 }
6204 }
6205
6206 /* release the channel */
6207 f_rsl_chan_deact();
6208 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6209 f_rslem_unregister(0, g_chan_nr);
6210}
6211testcase TC_rll_rel_req() runs on test_CT {
6212 var RllTestCases tcs := {
6213 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6214 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6215 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6216 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6217 };
6218 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6219}
6220
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006221/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006222testcase TC_rll_data_req() runs on test_CT {
6223}
6224
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006225/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006226testcase TC_rll_data_ind() runs on test_CT {
6227}
6228
6229/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6230private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6231 var RllTestCase tc := g_pars.spec.rll;
6232
6233 f_l1_tune(L1CTL);
6234 RSL.clear;
6235
6236 f_est_dchan();
6237 L1CTL.clear;
6238
6239 /* Send UNITDATA REQ on RSL side */
6240 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6241 /* Expect it to arrive on the other side */
6242 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006243 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006244 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006245 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006246 }
6247
6248 /* release the channel */
6249 f_rsl_chan_deact();
6250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6251 f_rslem_unregister(0, g_chan_nr);
6252}
6253testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6254 var octetstring l3 := f_rnd_octstring(15);
6255 var RllTestCases tcs := {
6256 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6257 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6258 };
6259 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6260}
6261testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6262 var octetstring l3 := f_rnd_octstring(19);
6263 var RllTestCases tcs := {
6264 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6265 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6266 };
6267 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6268}
6269
6270/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6271private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6272 var RllTestCase tc := g_pars.spec.rll;
6273
6274 f_l1_tune(L1CTL);
6275 RSL.clear;
6276
6277 f_est_dchan();
6278 L1CTL.clear;
6279
6280 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006281 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006282 /* Expdct RLL UNITDATA IND on RSL side */
6283 alt {
6284 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6285 setverdict(pass);
6286 }
6287 [] RSL.receive { repeat; }
6288 }
6289
6290 /* release the channel */
6291 f_rsl_chan_deact();
6292 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6293 f_rslem_unregister(0, g_chan_nr);
6294}
6295testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006296 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006297 var RllTestCases tcs := {
6298 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6299 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6300 };
6301 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6302}
6303testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6304 var octetstring l3 := f_rnd_octstring(18);
6305 var RllTestCases tcs := {
6306 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6307 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6308 };
6309 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6310}
6311
Harald Weltee613f962018-04-18 22:38:16 +02006312/***********************************************************************
6313 * Encryption Related
6314 ***********************************************************************/
6315
6316/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006317private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006318 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6319 if (link_id.c == SACCH) {
6320 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6321 } else {
6322 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6323 }
6324}
6325
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006326/* Expect (or not expect) other kinds of messages */
6327private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6328 [exp_any] RSL.receive { repeat; }
6329 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006331 }
6332}
6333
Harald Weltee613f962018-04-18 22:38:16 +02006334/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006335private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006336 RslLinkId link_id,
6337 octetstring l3,
6338 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006339 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006340) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006341 timer T := 3.0;
6342 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6343 T.start;
6344 /* Expect RLL UNITDATA IND on RSL side */
6345 alt {
6346 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6347 setverdict(pass);
6348 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006349 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006350 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006351 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006353 }
Harald Weltee613f962018-04-18 22:38:16 +02006354 }
6355}
6356
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006357/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6358private function f_data_mo(
6359 RslLinkId link_id,
6360 boolean p, uint3_t nr, uint3_t ns,
6361 octetstring l3,
6362 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006363 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006364) runs on ConnHdlr {
6365 timer T := 3.0;
6366 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6367 T.start;
6368 /* Expect RLL DATA IND on RSL side */
6369 alt {
6370 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6371 setverdict(pass);
6372 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006373 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006374 [] as_rsl_any_ind(exp_any);
6375 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006377 }
6378 }
6379}
6380
Harald Weltee613f962018-04-18 22:38:16 +02006381/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006382private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006383 f_l1_tune(L1CTL);
6384 f_est_dchan(true);
6385
6386 /* now we actually need to transmit some data both ways to check if the encryption works */
6387 var L1ctlDlMessage dl;
6388
Stefan Sperling603d98e2018-07-25 16:47:28 +02006389 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006390 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6391
6392 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6393 f_unitdata_mt(link_id, l3);
6394
6395 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6396 f_unitdata_mo(link_id, l3);
6397
6398 /* release the channel */
6399 f_rsl_chan_deact();
6400 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6401 f_rslem_unregister(0, g_chan_nr);
6402}
6403testcase TC_chan_act_a51() runs on test_CT {
6404 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6405 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6406 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6407}
6408testcase TC_chan_act_a52() runs on test_CT {
6409 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6410 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6411 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6412}
6413testcase TC_chan_act_a53() runs on test_CT {
6414 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6415 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6416 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6417}
6418
Eric Wildf1827a72019-05-28 17:37:35 +02006419/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6420 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 +07006421private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006422 f_l1_tune(L1CTL);
6423 f_est_dchan(true);
6424
6425 /* now we actually need to transmit some data both ways to check if the encryption works */
6426 var L1ctlDlMessage dl;
6427
6428 var octetstring l3 := f_rnd_octstring(20);
6429 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6430
6431 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6432 f_unitdata_mt(link_id, l3);
6433
6434 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6435 f_unitdata_mo(link_id, l3);
6436
6437 var RSL_Message rsl;
6438 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6439
6440 /* modify key to break proper encryption */
6441 g_pars.encr.key := f_rnd_octstring(8);
6442 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6443 rsl.ies := rsl.ies & { ei };
6444 RSL.send(rsl);
6445
6446 timer T0 := 1.0;
6447 T0.start;
6448 /* Expect RSL MODIFY ACK */
6449 alt {
6450 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6451 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6453 }
6454 [] T0.timeout {
6455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6456 }
6457 }
6458
6459 var octetstring l3msg := f_rnd_octstring(15);
6460 timer T1 := 3.0;
6461 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6462 due to broken encryption */
6463 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6464 T1.start;
6465 alt {
6466 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6468 }
6469 [] T1.timeout {
6470 setverdict(pass);
6471 }
6472 }
6473
6474 /* release the channel */
6475 f_rsl_chan_deact();
6476 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6477 f_rslem_unregister(0, g_chan_nr);
6478}
6479testcase TC_rsl_modify_encr() runs on test_CT {
6480 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6481 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6482 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6483}
Harald Weltee613f962018-04-18 22:38:16 +02006484
6485/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006486private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006487 /* L3 payload doesn't matter, as it is passed transparently */
6488 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6489 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6490 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6491
6492 f_l1_tune(L1CTL);
6493
6494 /* first establish a dedicated channel in the clear */
6495 f_est_dchan(false);
6496
6497 /* Establish ABM */
6498 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6499
6500 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6501 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6502 /* expect the L3 to arrive still unencrypted on the MS side */
6503 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6504
6505 /* configure L1 to apply ciphering */
6506 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6507 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6508
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006509 /* send first ciphered I-frame in response and expect it on RSL */
6510 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006511
6512 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6513 * and hence enable encryption also on the downlink */
6514
6515 /* expect bi-directional communication work in encrypted mode */
6516 f_unitdata_mo(link_id, f_rnd_octstring(15));
6517 f_unitdata_mt(link_id, f_rnd_octstring(15));
6518
6519 /* release the channel */
6520 f_rsl_chan_deact();
6521 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6522 f_rslem_unregister(0, g_chan_nr);
6523}
6524testcase TC_encr_cmd_a51() runs on test_CT {
6525 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6526 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6527 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6528}
6529testcase TC_encr_cmd_a52() runs on test_CT {
6530 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6531 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6532 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6533}
6534testcase TC_encr_cmd_a53() runs on test_CT {
6535 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6536 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6537 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6538}
6539
6540private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6541 var LapdmFrame lf;
6542 var octetstring reenc;
6543
6544 /* decode the LAPDm frame */
6545 if (ischosen(exp_match.ab)) {
6546 lf.ab := dec_LapdmFrameAB(enc);
6547 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006549 }
6550
6551 /* check if decoder result matches expectation */
6552 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006553 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006554 } else {
6555 log(name, ": matched");
6556 setverdict(pass);
6557 }
6558
6559 /* test if re-encoded frame equals original input */
6560 reenc := enc_LapdmFrame(lf);
6561 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006563 } else {
6564 setverdict(pass);
6565 }
6566}
6567
6568testcase TC_lapdm_selftest() runs on test_CT {
6569 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6570 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6571 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6572 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6573 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6574 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6575 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6576}
6577
Stefan Sperling4880be42018-08-07 18:12:59 +02006578/***********************************************************************
6579 * DTX Related (see GSM 05.08, section 8.3)
6580 ***********************************************************************/
6581
6582/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006583private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006584 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6585 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6586 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6587 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6588}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006589private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006590 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6591 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6592}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006593private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006594 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6595 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6596 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6597 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6598}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006599private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006600 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6601 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6602 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6603 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6604 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6605 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6606 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6607 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6608}
6609
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006610private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006611 var L1ctlDlMessage dl;
6612 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6613 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6614 var GsmFrameNumber first_fn;
6615 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006616 var integer nfill_frames_sacch := 0;
6617 var integer nfill_frames_nonsacch := 0;
6618 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006619 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6620 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006621 const integer frame_dtx_tchf_mod := 104;
6622 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6623 * which operates in terms of blocks rather than frames. */
6624 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6625 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006626 timer T := 5.0;
6627
6628 f_l1_tune(L1CTL);
6629 RSL.clear;
6630 L1CTL.clear;
6631
6632 /* activate TCHF signalling channel */
6633 f_est_dchan(false);
6634
6635 T.start;
6636 alt {
6637 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6638 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6639 var octetstring l2 := dl.payload.data_ind.payload;
6640
6641 if (is_first_frame) {
6642 is_first_frame := false;
6643 first_fn := dl.dl_info.frame_nr;
6644 }
6645
6646 if (dl.dl_info.link_id.c == SACCH) {
6647 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6648 if (not match(l2_fill_frame_sacch, l2)) {
6649 repeat;
6650 }
6651 } else if (not match(l2_fill_frame, l2)) {
6652 repeat;
6653 }
6654
6655 if (dtxd) {
6656 if (not f_g_chan_is_tchf()) {
6657 T.stop;
6658 f_rsl_chan_deact();
6659 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02006661 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006662 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006663 T.stop;
6664 f_rsl_chan_deact();
6665 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006666
6667 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6668 * 2 SACCH, 1 TCH/F */
6669 expected_fill_frames := 3;
6670
6671 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6672 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6673 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006675 } else {
6676 setverdict(pass);
6677 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006678 } else {
6679 if (dl.dl_info.link_id.c == SACCH) {
6680 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006681 repeat;
6682 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006683 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6684 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6685 * we should only see the subset of frames numbers which correspond to a block boundary.
6686 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6687 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6688 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6689 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6690 repeat;
6691 }
6692 }
6693 log("Received DTX TCH fill frame with bad frame number: ", fn,
6694 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6695 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6696 f_rsl_chan_deact();
6697 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006699 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006700 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006701 if (dl.dl_info.link_id.c == SACCH) {
6702 nfill_frames_sacch := nfill_frames_sacch + 1;
6703 } else {
6704 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6705 }
6706 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006707 T.stop;
6708 if (f_g_chan_is_tchf()) {
6709 /* Without DTX we can expect 25 fill frames for every 104 frames.
6710 * (24 FACCH + 1 SACCH filling) */
6711 expected_fill_frames := 25;
6712 } else if (f_g_chan_is_tchh()) {
6713 /* We can expect 2 fill frames for every 104 frames. */
6714 expected_fill_frames := 2;
6715 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6716 /* We can expect 5 fill frames for every 104 frames. */
6717 expected_fill_frames := 5;
6718 } else {
6719 f_rsl_chan_deact();
6720 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006721 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006722 }
6723
6724 f_rsl_chan_deact();
6725 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006726
6727 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006728 setverdict(pass);
6729 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006730 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6731 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006733 }
6734 } else {
6735 repeat;
6736 }
6737 }
6738 }
6739 [] L1CTL.receive { repeat; }
6740 [] T.timeout {
6741 f_rsl_chan_deact();
6742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006744 }
6745 }
6746}
6747
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006748private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006749 f_test_l2_fill_frames(false);
6750}
6751
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006752private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006753 f_test_l2_fill_frames(true);
6754}
6755
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006756private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006757 var ConnHdlr vc_conn;
6758 var ConnHdlrPars pars;
6759 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006760 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006761 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6762 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6763 if (dtxd) {
6764 if (i >= 4) { /* DTX is only allowed on TCH/F */
6765 break;
6766 }
6767 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6768 } else {
6769 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6770 }
6771 vc_conn.done;
6772 }
6773}
6774
6775/* Verify that L2 fill frames are sent on TCH in signaling mode if
6776 * there is nothing to transmit while DTX is disabled on downlink. */
6777testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6778 f_tch_sign_l2_fill_frame(false);
6779}
6780
6781/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6782 * there is nothing to transmit while DTX is enabled on downlink. */
6783testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6784 f_tch_sign_l2_fill_frame(true);
6785}
Harald Welte0472ab42018-03-12 15:02:26 +01006786
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006787testcase TC_chopped_ipa_ping() runs on test_CT {
6788 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6789}
6790
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006791testcase TC_chopped_ipa_payload() runs on test_CT {
6792 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6793}
6794
Harald Welte0472ab42018-03-12 15:02:26 +01006795/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6796/* protocol error as per 44.006 */
6797/* link layer failure (repetition of I-frame N200 times without ACK */
6798/* repetition of SABM or DISC N200 times without ACK */
6799/* receptiom of SABM in multi-frame established state */
6800
6801
Harald Welte68e495b2018-02-25 00:05:57 +01006802/* TODO Areas:
6803
6804* channel activation
6805** with BS_Power / MS_Power, bypassing power control loop
6806** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006807** with timing advance from initial activation on
6808* mode modify
6809** encryption
6810** multirate
6811* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006812** unsupported algorithm
6813* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006814* BS Power Control
6815* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006816* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006817* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006818** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006819* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006820** DATA_IND from BTS->PCU
6821** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006822
6823*/
Harald Welte70767382018-02-21 12:16:40 +01006824
6825control {
6826 execute( TC_chan_act_stress() );
6827 execute( TC_chan_act_react() );
6828 execute( TC_chan_deact_not_active() );
6829 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006830 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006831 execute( TC_sacch_filling() );
6832 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006833 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006834 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006835 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006836 execute( TC_sacch_chan_act_ho_async() );
6837 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006838 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006839 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006840 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006841 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006842 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006843 execute( TC_rach_load_idle_thresh0() );
6844 execute( TC_rach_load_idle_below_thresh() );
6845 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006846 execute( TC_meas_res_sign_tchf() );
6847 execute( TC_meas_res_sign_tchh() );
6848 execute( TC_meas_res_sign_sdcch4() );
6849 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006850 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006851 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006852 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006853 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006854 execute( TC_rsl_bs_pwr_static_ass() );
6855 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006856 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006857 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006858 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006859 execute( TC_rsl_ms_pwr_dyn_up() );
6860 execute( TC_rsl_ms_pwr_dyn_down() );
6861 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6862 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006863 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006864 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006865 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006866 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006867 execute( TC_paging_imsi_80percent() );
6868 execute( TC_paging_tmsi_80percent() );
6869 execute( TC_paging_imsi_200percent() );
6870 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006871 execute( TC_rsl_protocol_error() );
6872 execute( TC_rsl_mand_ie_error() );
6873 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006874 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006875 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006876 execute( TC_si_sched_2bis() );
6877 execute( TC_si_sched_2ter() );
6878 execute( TC_si_sched_2ter_2bis() );
6879 execute( TC_si_sched_2quater() );
6880 execute( TC_si_sched_13() );
6881 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006882 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006883 execute( TC_ipa_crcx_twice_not_active() );
6884 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006885 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006886 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006887
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006888 if (mp_pcu_socket != "") {
6889 execute( TC_pcu_act_req() );
6890 execute( TC_pcu_act_req_wrong_ts() );
6891 execute( TC_pcu_act_req_wrong_bts() );
6892 execute( TC_pcu_act_req_wrong_trx() );
6893 execute( TC_pcu_deact_req() );
6894 execute( TC_pcu_deact_req_wrong_ts() );
6895 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006896 if (mp_l1_supports_gprs) {
6897 execute( TC_pcu_data_req_pdtch() );
6898 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006899 execute( TC_pcu_data_req_wrong_bts() );
6900 execute( TC_pcu_data_req_wrong_trx() );
6901 execute( TC_pcu_data_req_wrong_ts() );
6902 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006903 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006904 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006905 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006906 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006907 execute( TC_pcu_data_req_imm_ass_pch() );
6908 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006909 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006910 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006911 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006912 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006913 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006914 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006915 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006916 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006917 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006918 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006919 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006920 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006921 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006922 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006923 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006924 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006925 execute( TC_dyn_osmo_pdch_act_deact() );
6926 execute( TC_dyn_osmo_pdch_double_act() );
6927 execute( TC_dyn_ipa_pdch_act_deact() );
6928 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6929
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006930 if (PCUIF_Types.mp_pcuif_version >= 10) {
6931 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006932 execute( TC_pcu_socket_nsvc_ipv4() );
6933 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006934 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006935 } else {
6936 log("PCU socket path not available, skipping PCU tests");
6937 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006938
Harald Welte3d04ae62018-04-04 20:29:05 +02006939 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006940 execute( TC_dyn_osmo_pdch_tchf_act() );
6941 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006942 execute( TC_dyn_ipa_pdch_tchf_act() );
6943 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006944
6945 execute( TC_rll_est_ind() );
6946 execute( TC_rll_est_req_DCCH_3() );
6947 execute( TC_rll_est_req_ACCH_3() );
6948 execute( TC_rll_rel_ind_DCCH_0() );
6949 execute( TC_rll_rel_ind_DCCH_3() );
6950 execute( TC_rll_rel_ind_ACCH_0() );
6951 execute( TC_rll_rel_ind_ACCH_3() );
6952 execute( TC_rll_rel_req() );
6953 execute( TC_rll_unit_data_req_DCCH() );
6954 execute( TC_rll_unit_data_req_ACCH() );
6955 execute( TC_rll_unit_data_ind_DCCH() );
6956 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006957
6958 execute( TC_chan_act_a51() );
6959 execute( TC_chan_act_a52() );
6960 execute( TC_chan_act_a53() );
6961 execute( TC_encr_cmd_a51() );
6962 execute( TC_encr_cmd_a52() );
6963 execute( TC_encr_cmd_a53() );
6964
Harald Welteee25aae2019-05-19 14:32:37 +02006965 execute( TC_err_rep_wrong_mdisc() );
6966 execute( TC_err_rep_wrong_msg_type() );
6967 execute( TC_err_rep_wrong_sequence() );
6968
Harald Weltee613f962018-04-18 22:38:16 +02006969 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006970
6971 execute( TC_tch_sign_l2_fill_frame() );
6972 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006973
6974 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006975 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006976}
6977
6978
6979}