blob: e24356a966824b3fc43a1db21e0b5153e67c4f44 [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) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003678 }
3679 for (var integer i:= 0; i < m; i := i + 1) {
3680 var integer fn_mod51 := arr[i].frame_number mod 51;
3681 if (not bcch_ext and fn_mod51 == 2 or
3682 bcch_ext and fn_mod51 == 6) {
3683 if (arr[i].si.header.message_type == key) {
3684 count := count + 1;
3685 }
3686 }
3687 }
3688 if (count >= n) {
3689 return true;
3690 } else {
3691 return false;
3692 }
3693}
3694
3695/* 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 +07003696private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3697 integer tc, RrMessageType key,
3698 boolean ext_bcch := false,
3699 integer n, integer m)
3700{
Harald Welte48494ca2018-02-25 16:59:50 +01003701 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003703 }
3704}
3705
3706/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003707private function f_si_vecslot_contains_only(SystemInformationVector arr,
3708 RrMessageType key,
3709 boolean bcch_ext := false)
3710return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003711 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3712 var integer fn_mod51 := arr[i].frame_number mod 51;
3713 if (not bcch_ext and fn_mod51 == 2 or
3714 bcch_ext and fn_mod51 == 6) {
3715 if (arr[i].si.header.message_type != key) {
3716 return false;
3717 }
3718 }
3719 }
3720 return true;
3721}
3722
3723/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003724private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3725 integer tc, RrMessageType key,
3726 boolean ext_bcch := false)
3727{
Harald Welte48494ca2018-02-25 16:59:50 +01003728 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003730 }
3731}
3732
3733/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003734private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003735 boolean bcch_extended,
3736 boolean si1_present,
3737 boolean si2bis_present,
3738 boolean si2ter_present,
3739 boolean si2quater_present,
3740 boolean si7_present,
3741 boolean si8_present,
3742 boolean si9_present,
3743 boolean si13_present,
3744 boolean si13alt_present,
3745 boolean si15_present,
3746 boolean si16_present,
3747 boolean si17_present,
3748 boolean si2n_present,
3749 boolean si21_present,
3750 boolean si22_present
3751}
3752
3753/* 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 +07003754private function f_validate_si_scheduling(SystemInformationConfig cfg,
3755 SystemInformationVectorPerTc si_per_tc)
3756{
Harald Welte48494ca2018-02-25 16:59:50 +01003757 var integer i;
3758 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3759 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003761 }
3762 }
3763 if (cfg.si1_present) {
3764 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3765 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3766 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3767 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3768 /* make sure *ALL* contain SI1 */
3769 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3770 }
3771 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3772 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3773 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3774 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3775 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3776 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3777
3778 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3779 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3780 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3781 * consecutive occurrences of TC = 4. */
3782 if (cfg.si2bis_present and not cfg.si2ter_present) {
3783 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3784 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3785 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3786 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3787 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3788 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3789 }
3790
3791 if (cfg.si7_present or cfg.si8_present) {
3792 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3793 * if System Information type 4 does not contain all information needed for cell
3794 * selection and reselection. */
3795 if (not cfg.bcch_extended) {
3796 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3797 }
3798 if (cfg.si7_present) {
3799 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3800 }
3801 if (cfg.si8_present) {
3802 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3803 }
3804 }
3805
3806 if (cfg.si2quater_present) {
3807 /* iii) System information type 2 quater is sent if needed, as determined by the system
3808 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3809 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3810 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3811 * within any of 4 consecutive occurrences of TC = 5. */
3812 if (not (cfg.bcch_extended)) {
3813 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3814 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3815 } else {
3816 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3817 }
3818 } else {
3819 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3820 }
3821 }
3822 if (cfg.si9_present) {
3823 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3824 * in system information type 3 as defined in 3GPP TS 44.018. */
3825 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3826 }
3827 if (cfg.si13_present) {
3828 /* vii) System Information type 13 is only related to the GPRS service. System Information
3829 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3830 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3831 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3832 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3833 * within any of 4 consecutive occurrences of TC=4. */
3834 if (not cfg.bcch_extended) {
3835 log("not-bccch-extended");
3836 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3837 } else {
3838 log("bccch-extended");
3839 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3840 }
3841 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003843 }
3844 }
3845 if (cfg.si16_present or cfg.si17_present) {
3846 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3847 * should not be sent in a cell where network sharing is used (see rule xv). */
3848 if (cfg.si22_present) {
3849 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3850 }
3851 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003853 }
3854 if (not cfg.bcch_extended) {
3855 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3856 }
3857 if (cfg.si16_present) {
3858 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3859 }
3860 if (cfg.si17_present) {
3861 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3862 }
3863 }
3864
3865 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3866 * broadcast information. The frequency with which they are sent is determined by the
3867 * system operator. System Information type 9 identifies the scheduling of System
3868 * Information type 18 and 20 messages. */
3869
3870 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3871 * Information Type 19 is present, then its scheduling shall be indicated in System
3872 * Information Type 9. */
3873
3874 if (cfg.si15_present) {
3875 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3876 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3877 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3878 * 4 consecutive occurrences of TC = 1. */
3879 if (not cfg.bcch_extended) {
3880 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3881 } else {
3882 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3883 }
3884 }
3885 if (cfg.si13alt_present) {
3886 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3887 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3888 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3889 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3890 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3891 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3892 * of TC = 4. */
3893 if (cfg.si13_present) {
3894 testcase.stop("Error: Cannot have SI13alt and SI13");
3895 }
3896 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003898 }
3899 if (not cfg.bcch_extended) {
3900 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3901 } else {
3902 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3903 }
3904 }
3905 if (cfg.si2n_present) {
3906 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3907 * as determined by the system operator. In the case that the message is sent on the
3908 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3909 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3910 * consecutive occurrences of TC = 4. */
3911 if (not cfg.bcch_extended) {
3912 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3913 } else {
3914 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3915 }
3916 }
3917 if (cfg.si21_present) {
3918 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3919 * determined by the system operator. If Extended Access Barring is in use in the cell
3920 * then this message is sent at least once within any of 4 consecutive occurrences of
3921 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3922 * cell then this message shall only be sent on BCCH Ext. */
3923 if (not cfg.bcch_extended) {
3924 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3925 } else {
3926 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3927 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003929 }
3930 }
3931 }
3932 if (cfg.si22_present) {
3933 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3934 * should not be sent in a cell where SoLSA is used (see rule viii). System
3935 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3936 * =2 and TC=6. */
3937 if (cfg.si16_present or cfg.si17_present) {
3938 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3939 }
3940 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3941 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003943 }
3944 if (not cfg.bcch_extended) {
3945 testcase.stop("Error: SI22 requires BCCH Extd!");
3946 } else {
3947 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3948 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3949 }
3950 }
3951}
3952
3953/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003954private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3955return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003956 timer T := duration;
3957 var SystemInformationVectorPerTc si_per_tc;
3958 var L1ctlDlMessage l1_dl;
3959
3960 /* initialize all per-TC vectors empty */
3961 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3962 si_per_tc[i] := {};
3963 }
3964
3965 /* flush all previous L1 queued msgs */
3966 pt.clear;
3967
3968 T.start;
3969 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003970 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003971 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3972 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3973 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003974 repeat;
3975 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003976
Harald Welte48494ca2018-02-25 16:59:50 +01003977 var integer tc := f_gsm_compute_tc(sig.frame_number);
3978 log("SI received at TC=", tc, ": ", sig.si);
3979 /* append to the per-TC bucket */
3980 si_per_tc[tc] := si_per_tc[tc] & { sig };
3981 repeat;
3982 }
3983 [] pt.receive { repeat; }
3984 [] T.timeout { }
3985 }
3986
3987 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3988 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3989 }
3990 log("si_per_tc=", si_per_tc);
3991 return si_per_tc;
3992}
3993
3994/* helper function: Set given SI via RSL + validate scheduling.
3995 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003996private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003997 var SystemInformationVectorPerTc si_per_tc;
3998 f_init_l1ctl();
3999 f_l1_tune(L1CTL);
4000
4001 /* Sample + Validate Scheduling */
4002 si_per_tc := f_l1_sample_si(L1CTL);
4003 f_validate_si_scheduling(si_cfg, si_per_tc);
4004
4005 setverdict(pass);
4006}
4007
4008testcase TC_si_sched_default() runs on test_CT {
4009 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004010 /* 2+3+4 are mandatory and set in f_init() */
4011 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004013}
4014
4015testcase TC_si_sched_1() runs on test_CT {
4016 f_init();
4017 si_cfg.si1_present := true;
4018 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004019 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004021}
4022
4023testcase TC_si_sched_2bis() runs on test_CT {
4024 f_init();
4025 si_cfg.si2bis_present := true;
4026 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4027 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004029}
4030
4031testcase TC_si_sched_2ter() runs on test_CT {
4032 f_init();
4033 si_cfg.si2ter_present := true;
4034 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4035 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004037}
4038
4039testcase TC_si_sched_2ter_2bis() runs on test_CT {
4040 f_init();
4041 si_cfg.si2bis_present := true;
4042 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4043 si_cfg.si2ter_present := true;
4044 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4045 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004047}
4048
4049testcase TC_si_sched_2quater() runs on test_CT {
4050 f_init();
4051 si_cfg.si2quater_present := true;
4052 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4053 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004055}
4056
4057testcase TC_si_sched_13() runs on test_CT {
4058 f_init();
4059 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004060 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004061 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004063}
4064
4065testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4066 f_init();
4067 si_cfg.si2bis_present := true;
4068 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4069 si_cfg.si2ter_present := true;
4070 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4071 si_cfg.si2quater_present := true;
4072 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4073 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004074 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004075 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004077}
4078
4079
Harald Welte68e495b2018-02-25 00:05:57 +01004080testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004081 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004082 /* FIXME: enable / disable individual BCCH info */
4083 //ts_RSL_BCCH_INFO(si_type, info);
4084 /* expect no ERROR REPORT after either of them *
4085 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004087}
4088
Harald Welte93640c62018-02-25 16:59:33 +01004089/***********************************************************************
4090 * Low-Level Protocol Errors / ERROR REPORT
4091 ***********************************************************************/
4092
Harald Welte01d982c2018-02-25 01:31:40 +01004093private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4094 timer T := 5.0;
4095 T.start;
4096 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004097 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004098 setverdict(pass);
4099 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004100 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004102 }
4103 [] RSL_CCHAN.receive {
4104 repeat;
4105 }
4106 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004108 }
4109 }
4110}
4111
4112/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4113testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004114 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004115 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4116 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004117 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004118
4119 f_exp_err_rep(RSL_ERR_PROTO);
4120}
4121
4122/* Provoke a mandatory IE error and match on ERROR REPORT */
4123testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004124 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004125
4126 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4127 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004128 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004129
4130 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4131}
4132
4133/* Provoke an IE content error and match on ERROR REPORT */
4134testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004135 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004136 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4137 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004138 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004139
4140 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4141}
4142
Harald Welteee25aae2019-05-19 14:32:37 +02004143/* attempt to activate channel with wrong RSL Message Discriminator IE */
4144function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4145 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4146 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4147 RSL.send(rsl);
4148 f_rslem_unregister(0, g_chan_nr);
4149}
4150testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4151 var ConnHdlr vc_conn;
4152 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4153
Harald Welte10474062019-05-30 16:48:17 +02004154 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004155
4156 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4157 vc_conn.done;
4158 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4159
4160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4161}
4162
4163/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004164private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004165 var template (value) RSL_Message rsl_tx;
4166 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4167 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4168 RSL.send(rsl_tx);
4169 f_rslem_unregister(0, g_chan_nr);
4170}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004171private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004172 var template (value) RSL_Message rsl_tx;
4173 /* we first have to activate the dedicated channel */
4174 f_rsl_chan_act(g_pars.chan_mode);
4175 /* ... to then send an invalid RLL message */
4176 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4177 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4178 RSL.send(rsl_tx);
4179 f_rslem_unregister(0, g_chan_nr);
4180}
4181testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4182 var ConnHdlr vc_conn;
4183 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4184 var template (value) RSL_Message rsl_tx;
4185
Harald Welte10474062019-05-30 16:48:17 +02004186 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004187
4188 /* Common Channel with wrong message type */
4189 RSL_CCHAN.clear;
4190 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4191 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004192 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004193 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4194
4195 /* TRX Management */
4196 RSL_CCHAN.clear;
4197 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4198 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004199 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004200 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4201
4202 /* Dedicated Channel */
4203 RSL_CCHAN.clear;
4204 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4205 vc_conn.done;
4206 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4207
4208 /* RLL */
4209 RSL_CCHAN.clear;
4210 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4211 vc_conn.done;
4212 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4213}
4214
4215/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004216private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004217 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4218 f_rslem_unregister(0, g_chan_nr);
4219}
4220testcase TC_err_rep_wrong_sequence() runs on test_CT {
4221 var ConnHdlr vc_conn;
4222 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4223
Harald Welte10474062019-05-30 16:48:17 +02004224 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004225
4226 RSL_CCHAN.clear;
4227 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4228 vc_conn.done;
4229 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4230}
4231
Harald Welte93640c62018-02-25 16:59:33 +01004232/***********************************************************************
4233 * IPA CRCX/MDCX/DLCS media stream handling
4234 ***********************************************************************/
4235
Harald Weltea871a382018-02-25 02:03:14 +01004236/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004237private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004238 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4239 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004240}
4241testcase TC_ipa_dlcx_not_active() runs on test_CT {
4242 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004243 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004244 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4245 vc_conn.done;
4246}
Harald Welte68e495b2018-02-25 00:05:57 +01004247
Harald Weltea3f1df92018-02-25 12:49:55 +01004248/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004249private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004250 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4251 "IPA CRCX ACK");
4252 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4253 "IPA CRCX NACK");
4254}
4255testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4256 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004257 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004258 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4259 vc_conn.done;
4260}
4261
4262/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004263private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004264 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4265 "IPA CRCX ACK");
4266 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4267 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4268 var uint7_t rtp_pt2 := f_rnd_int(127);
4269 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4270 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4271 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4272 "IPA MDCX ACK");
4273 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4274 "IPA DLCX ACK");
4275}
4276testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004278 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004279 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4280 vc_conn.done;
4281}
4282
Harald Welte3ae11da2018-02-25 13:36:06 +01004283/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004284private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004285 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4286 "IPA CRCX ACK");
4287 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4288 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4289 var uint7_t rtp_pt2 := f_rnd_int(127);
4290 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4291 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4292 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4293 "IPA MDCX ACK");
4294 /* Second MDCX */
4295 remote_ip := f_rnd_int(c_UINT32_MAX);
4296 remote_port := f_rnd_int(c_UINT16_MAX);
4297 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4298 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4299 "IPA MDCX ACK");
4300 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4301 "IPA DLCX ACK");
4302}
4303testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4304 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004305 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004306 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4307 vc_conn.done;
4308}
4309
Harald Welte9912eb52018-02-25 13:30:15 +01004310/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004311private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004312 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4313 "IPA CRCX NACK");
4314}
4315testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4316 var ConnHdlrPars pars;
4317 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004318 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004319
4320 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4321 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4322 vc_conn.done;
4323
4324 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4325 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4326 vc_conn.done;
4327}
4328
Harald Weltea3f1df92018-02-25 12:49:55 +01004329
Harald Welte883340c2018-02-28 18:59:29 +01004330/***********************************************************************
4331 * PCU Socket related tests
4332 ***********************************************************************/
4333
Harald Welte07bd2d22019-05-25 11:03:30 +02004334/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004335friend 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 +01004336runs on test_CT {
4337 timer T := 3.0;
4338
4339 /* we don't expect any RTS.req before PDCH are active */
4340 T.start;
4341 alt {
4342 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004344 }
4345 [] PCU.receive { repeat; }
4346 [] T.timeout { }
4347 }
4348
4349 /* Send PDCH activate request for known PDCH timeslot */
4350 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4351
4352 /* we now expect RTS.req for this timeslot (only) */
4353 T.start;
4354 alt {
4355 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4356 setverdict(pass);
4357 }
4358 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4359 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004361 }
4362 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004364 }
4365 [] PCU.receive { repeat; }
4366 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004368 }
4369 [not exp_success] T.timeout {
4370 setverdict(pass);
4371 }
4372 }
4373}
4374
Harald Welte07bd2d22019-05-25 11:03:30 +02004375/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004376friend 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 +01004377runs on test_CT {
4378 timer T := 3.0;
4379
4380 /* Send PDCH activate request for known PDCH timeslot */
4381 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4382
4383 PCU.clear;
4384 /* we now expect no RTS.req for this timeslot */
4385 T.start;
4386 alt {
4387 [] 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 +02004388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004389 }
4390 [] PCU.receive { repeat; }
4391 [] T.timeout {
4392 setverdict(pass);
4393 }
4394 }
4395}
4396
Harald Weltead033dc2019-05-25 17:28:16 +02004397friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004398 f_init();
4399 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4400}
4401
Harald Welte883340c2018-02-28 18:59:29 +01004402/* PDCH activation via PCU socket; check for presence of RTS.req */
4403testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004404 f_init_pcu_test();
4405
Harald Welte883340c2018-02-28 18:59:29 +01004406 f_TC_pcu_act_req(0, 0, 7, true);
4407}
4408
4409/* PDCH activation via PCU socket on non-PDCU timeslot */
4410testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004411 f_init_pcu_test();
4412
Harald Welte883340c2018-02-28 18:59:29 +01004413 f_TC_pcu_act_req(0, 0, 1, false);
4414}
4415
4416/* PDCH activation via PCU socket on wrong BTS */
4417testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004418 f_init_pcu_test();
4419
Harald Welte883340c2018-02-28 18:59:29 +01004420 f_TC_pcu_act_req(23, 0, 7, false);
4421}
4422
4423/* PDCH activation via PCU socket on wrong TRX */
4424testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004425 f_init_pcu_test();
4426
Harald Welte883340c2018-02-28 18:59:29 +01004427 f_TC_pcu_act_req(0, 23, 7, false);
4428}
4429
4430/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4431testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004432 f_init_pcu_test();
4433
Harald Welte883340c2018-02-28 18:59:29 +01004434 /* Activate PDCH */
4435 f_TC_pcu_act_req(0, 0, 7, true);
4436 f_sleep(1.0);
4437 /* and De-Activate again */
4438 f_TC_pcu_deact_req(0, 0, 7);
4439}
4440
4441/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4442testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004443 f_init_pcu_test();
4444
Harald Welte883340c2018-02-28 18:59:29 +01004445 f_TC_pcu_deact_req(0, 0, 1);
4446}
4447
4448/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4449testcase TC_pcu_ver_si13() runs on test_CT {
4450 const octetstring si13 := '00010203040506070909'O;
4451 var PCUIF_send_data sd;
4452 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004453 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004454
4455 /* Set SI13 via RSL */
4456 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004457
Harald Welte883340c2018-02-28 18:59:29 +01004458 T.start;
4459 alt {
4460 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4461 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4462 setverdict(pass);
4463 } else {
4464 repeat;
4465 }
4466 }
4467 [] PCU.receive { repeat; }
4468 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004470 }
4471 }
4472}
4473
4474private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4475
4476/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004477friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004478 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4479runs on test_CT
4480{
4481 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4482 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4483}
4484
4485/* 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 +02004486friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4487 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004488runs on test_CT
4489{
4490 var PCUIF_send_data sd;
4491
4492 timer T := 3.0;
4493 T.start;
4494 alt {
4495 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4496 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4497 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4498 sd.data.u.rts_req.fn, sapi, data);
4499 }
4500 [] PCU.receive { repeat; }
4501 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004503 }
4504 }
4505}
4506
4507/* Send DATA.req on invalid BTS */
4508testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004509 var TfiUsfArr tua := f_TfiUsfArrInit();
4510 var octetstring data := '0000'O & f_rnd_octstring(21);
4511
4512 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004513
Harald Welte883340c2018-02-28 18:59:29 +01004514 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004515 f_TfiUsfArrSet(tua, 7, 0);
4516 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4517 f_sleep(1.0);
4518
4519 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004520}
4521
4522/* Send DATA.req on invalid TRX */
4523testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004524 var TfiUsfArr tua := f_TfiUsfArrInit();
4525 var octetstring data := '0000'O & f_rnd_octstring(21);
4526
4527 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004528
Harald Welte883340c2018-02-28 18:59:29 +01004529 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004530 f_TfiUsfArrSet(tua, 7, 0);
4531 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4532 f_sleep(1.0);
4533
4534 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004535}
4536
4537/* Send DATA.req on invalid timeslot */
4538testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004539 var TfiUsfArr tua := f_TfiUsfArrInit();
4540 var octetstring data := '0000'O & f_rnd_octstring(21);
4541
4542 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004543
Harald Welte883340c2018-02-28 18:59:29 +01004544 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004545 f_TfiUsfArrSet(tua, 7, 0);
4546 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4547 f_sleep(1.0);
4548
4549 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004550}
4551
4552/* Send DATA.req on timeslot that hasn't been activated */
4553testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004554 var TfiUsfArr tua := f_TfiUsfArrInit();
4555 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004556
Harald Welte7162a612019-05-26 12:56:09 +02004557 f_virtphy_common();
4558
4559 f_TfiUsfArrSet(tua, 7, 0);
4560 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4561 f_sleep(1.0);
4562
4563 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004564}
4565
Harald Weltead033dc2019-05-25 17:28:16 +02004566private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004567 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4568 boolean wait_rts := true)
4569runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004570 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004571 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004572
4573 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004574 if (wait_rts) {
4575 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4576 } else {
4577 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4578 }
Harald Weltead033dc2019-05-25 17:28:16 +02004579
4580 T.start;
4581 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004582 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004583 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4584 setverdict(pass);
4585 }
Harald Welte7162a612019-05-26 12:56:09 +02004586 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4587 setverdict(fail, "Received unexpected ", rx_dl);
4588 }
Harald Weltead033dc2019-05-25 17:28:16 +02004589 [] L1CTL.receive {
4590 repeat;
4591 }
Harald Welte7162a612019-05-26 12:56:09 +02004592 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004593 setverdict(fail, "Timeout waiting for ", data);
4594 }
Harald Welte7162a612019-05-26 12:56:09 +02004595 [not expect_data] T.timeout {
4596 setverdict(pass);
4597 }
Harald Weltead033dc2019-05-25 17:28:16 +02004598 }
4599}
4600
4601private function f_disable_dynamic_ts() runs on test_CT
4602{
4603 f_init_vty_bsc();
4604 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4605 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4606 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4607 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004608 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004609}
4610
4611private function f_virtphy_common() runs on test_CT {
4612 f_disable_dynamic_ts();
4613 f_init_l1ctl();
4614 f_l1_tune(L1CTL);
4615}
4616
4617testcase TC_pcu_data_req_pdtch() runs on test_CT {
4618 var TfiUsfArr tua := f_TfiUsfArrInit();
4619 var octetstring data := '0000'O & f_rnd_octstring(21);
4620
4621 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004622
Harald Welte883340c2018-02-28 18:59:29 +01004623 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004624 f_TfiUsfArrSet(tua, 7, 0);
4625 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4626 f_sleep(1.0);
4627
4628 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004629}
4630
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004631/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004632testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004633 var TfiUsfArr tua := f_TfiUsfArrInit();
4634 var octetstring data := '0000'O & f_rnd_octstring(21);
4635
4636 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004637
Harald Welte883340c2018-02-28 18:59:29 +01004638 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004639 f_TfiUsfArrSet(tua, 7, 0);
4640 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4641 f_sleep(1.0);
4642
4643 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004644}
4645
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004646private function f_TC_pcu_ptcch_ul(uint16_t ra)
4647runs on test_CT {
4648 var template PCUIF_Message pcu_rach_ind;
4649 var PCUIF_send_data sd;
4650 var GsmFrameNumber fn;
4651 timer T;
4652
4653 /* Send an Access Burst on PTCCH/U over the Um-interface */
4654 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4655 chan_nr := ts_RslChanNr_PDCH(7),
4656 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4657
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004658 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4659 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004660
4661 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4662 T.start(52.0 * 4.615 / 1000.0);
4663 alt {
4664 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4665 log("Rx an Access Burst on the PCU interface: ", sd.data);
4666 setverdict(pass);
4667 T.stop;
4668 }
4669 [] PCU.receive { repeat; }
4670 [] T.timeout {
4671 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4672 /* Keep going, that's not the end of the world */
4673 }
4674 }
4675}
4676
4677testcase TC_pcu_ptcch() runs on test_CT {
4678 var L1ctlDlMessage dl;
4679 var octetstring data;
4680 timer T;
4681
4682 f_init_pcu_test();
4683 f_init_l1ctl();
4684 f_l1_tune(L1CTL);
4685
4686 /* Activate PDCH channel on TS7 */
4687 f_TC_pcu_act_req(0, 0, 7, true);
4688
4689 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004690 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004691 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004692 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004693 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004694
4695 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4696 for (var integer i := 0; i < 16; i := i + 1) {
4697 log("Sending an Access Burst towards the L1CTL interface");
4698 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4699 }
4700
4701 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4702 data := f_rnd_octstring(23);
4703
4704 /* Verify PTCCH/D: send a random data block, make sure it's received */
4705 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4706 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4707
4708 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4709 * let's give it more time in case if we miss the beginning. */
4710 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4711 alt {
4712 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4713 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4714 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4715 frame := data)) -> value dl {
4716 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4717 setverdict(pass);
4718 T.stop;
4719 }
4720 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4721 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4722 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4723 l2_data := data)) -> value dl {
4724 log("Rx PTCCH/D data block on L1CTL: ", dl);
4725 setverdict(pass);
4726 T.stop;
4727 }
4728 [] L1CTL.receive { repeat; }
4729 [] T.timeout {
4730 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4731 }
4732 }
4733}
4734
Harald Welte883340c2018-02-28 18:59:29 +01004735/* Send AGCH from PCU; check it appears on Um side */
4736testcase TC_pcu_data_req_agch() runs on test_CT {
4737 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004738 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004739 f_init_l1ctl();
4740 f_l1_tune(L1CTL);
4741
4742 f_TC_pcu_act_req(0, 0, 7, true);
4743 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4744
4745 T.start;
4746 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004747 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004748 setverdict(pass);
4749 }
4750 [] L1CTL.receive { repeat; }
4751 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004753 }
4754 }
4755}
4756
Harald Welte928622b2019-05-26 13:22:59 +02004757/* Send AGCH from PCU; check it appears on Um side */
4758testcase TC_pcu_data_req_pch() runs on test_CT {
4759 timer T := 3.0;
4760 f_init_pcu_test();
4761 f_init_l1ctl();
4762 f_l1_tune(L1CTL);
4763
4764 f_TC_pcu_act_req(0, 0, 7, true);
4765 /* three characters prefix: last 3 digits of IMSI as ASCII */
4766 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4767
4768 T.start;
4769 alt {
4770 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4771 setverdict(pass);
4772 }
4773 [] L1CTL.receive { repeat; }
4774 [] T.timeout {
4775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4776 }
4777 }
4778}
4779
Harald Welte883340c2018-02-28 18:59:29 +01004780/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4781testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4782 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004783 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004784 f_init_l1ctl();
4785 f_l1_tune(L1CTL);
4786
4787 /* append 3 last imsi digits so BTS can compute pagng group */
4788 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4789
4790 timer T := 0.5;
4791 T.start;
4792 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004793 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004794 /* TODO: verify paging group */
4795 setverdict(pass);
4796 }
4797 [] L1CTL.receive { repeat; }
4798 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004800 }
4801 }
4802}
4803
4804/* Send RACH from Um side, expect it to show up on PCU socket */
4805testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004806 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004807 f_init_l1ctl();
4808 f_l1_tune(L1CTL);
4809
4810 var GsmFrameNumber fn_last := 0;
4811 for (var integer i := 0; i < 1000; i := i+1) {
4812 var OCT1 ra := f_rnd_ra_ps();
4813 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4814 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004816 }
4817 fn_last := fn;
4818
4819 timer T := 2.0;
4820 T.start;
4821 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004822 [] 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 +01004823 T.stop;
4824 }
4825 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004827 }
4828 [] PCU.receive { repeat; }
4829 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004831 }
4832 }
4833 }
4834 setverdict(pass);
4835}
4836
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004837/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4838 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4839testcase TC_pcu_ext_rach_content() runs on test_CT {
4840 var template PCUIF_Message pcu_rach_ind;
4841 var GsmFrameNumber fn_last := 0;
4842 var L1ctlRachSynchSeq synch_seq;
4843 var PCUIF_BurstType pcu_bt;
4844 var GsmFrameNumber fn;
4845 var BIT11 ra11;
4846
4847 f_init_pcu_test();
4848 f_init_l1ctl();
4849 f_l1_tune(L1CTL);
4850
4851 for (var integer i := 0; i < 1000; i := i+1) {
4852 /* We need to test both TS1 & TS2 */
4853 if (i rem 2 == 0) {
4854 synch_seq := RACH_SYNCH_SEQ_TS1;
4855 pcu_bt := BURST_TYPE_1;
4856 } else {
4857 synch_seq := RACH_SYNCH_SEQ_TS2;
4858 pcu_bt := BURST_TYPE_2;
4859 }
4860
4861 ra11 := f_rnd_ra11_ps();
4862 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4863 if (fn == fn_last) {
4864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4865 "Two RACH in same FN?!?");
4866 }
4867 fn_last := fn;
4868
4869 /* Compose the expected message */
4870 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004871 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004872 ra := bit2int(ra11),
4873 is_11bit := 1,
4874 burst_type := pcu_bt,
4875 fn := fn);
4876
4877 timer T := 2.0;
4878 T.start;
4879 alt {
4880 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4881 T.stop;
4882 }
4883 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4885 }
4886 [] PCU.receive { repeat; }
4887 [] T.timeout {
4888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4889 }
4890 }
4891 }
4892 setverdict(pass);
4893}
4894
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004895private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4896runs on test_CT {
4897 var template PCUIF_send_data sdt;
4898 var PCUIF_send_data sd;
4899 var int16_t lqual_cb;
4900 timer T := 1.0;
4901
4902 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4903 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4904
4905 /* Send a random PDTCH frame over Um */
4906 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4907 '0000'O & f_rnd_octstring(21)));
4908
4909 T.start;
4910 alt {
4911 /* If expected link quality is above the threshold */
4912 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4913 lqual_cb := sd.data.u.data_ind.lqual_cb;
4914 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4915
4916 /* Make sure the actual link quality matches the expected value */
4917 if (not match(lqual_cb, lqual_cb_exp)) {
4918 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4919 "expected value ", lqual_cb_exp));
4920 } else {
4921 setverdict(pass);
4922 }
4923 }
4924 /* If expected link quality is below the threshold */
4925 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4927 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4928 }
4929 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4930 [] PCU.receive { repeat; }
4931 [lqual_cb_exp < thresh] T.timeout {
4932 log("Rx nothing, as expected");
4933 setverdict(pass);
4934 }
4935 [lqual_cb_exp >= thresh] T.timeout {
4936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4937 "Timeout waiting for PCUIF_DATA.ind");
4938 }
4939 }
4940}
4941
4942/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4943testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4944 f_init_pcu_test();
4945 PCU.clear;
4946
4947 f_init_l1ctl();
4948 f_l1_tune(L1CTL);
4949
4950 /* Activate a PDCH channel on TS7 */
4951 f_TC_pcu_act_req(0, 0, 7, true);
4952
4953 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004954 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004955 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004956 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004957 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004958
4959 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4960 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4961 var TrxcMessage ret;
4962
4963 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4964 valueof(ts_TRXC_FAKE_CI(i)));
4965
4966 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4967 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4968 }
4969}
4970
Harald Welte883340c2018-02-28 18:59:29 +01004971/* Send PAGING via RSL, expect it to shw up on PCU socket */
4972testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004973 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004974
4975 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004976 var MobileIdentityLV mi_lv;
4977 var octetstring mi_lv_enc;
4978 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004979 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004980
Harald Welte883340c2018-02-28 18:59:29 +01004981 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004982 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004983 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004984 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004985 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004986
4987 /* Fancy encoding for PCUIF */
4988 mi_lv := valueof(ts_MI_LV(mi));
4989 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4990 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004991
4992 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004993 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004994 T.start;
4995 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004996 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004997 }
4998 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005000 }
5001 [] PCU.receive { repeat; }
5002 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005004 }
5005 }
5006 }
5007 setverdict(pass);
5008}
5009
Harald Welted66c9b82019-05-25 09:03:15 +02005010/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5011testcase TC_pcu_time_ind() runs on test_CT {
5012 var PCUIF_send_data pcu_sd;
5013 var integer num_time_ind := 0;
5014 var integer first_fn, last_fn;
5015 var float test_duration := 5.0;
5016 timer T;
5017
5018 f_init_pcu_test();
5019 f_TC_pcu_act_req(0, 0, 7, true);
5020
5021 PCU.clear;
5022 T.start(test_duration);
5023 alt {
5024 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5025 num_time_ind := num_time_ind + 1;
5026 if (not isbound(first_fn)) {
5027 first_fn := pcu_sd.data.u.time_ind.fn;
5028 }
5029 last_fn := pcu_sd.data.u.time_ind.fn;
5030 repeat;
5031 }
5032 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5033 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5034 repeat;
5035 }
5036 [] PCU.receive {
5037 repeat;
5038 }
5039 [] T.timeout {}
5040 }
5041 var integer fn_expired := last_fn - first_fn;
5042 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5043
5044 /* verify the number of frames expired matches our expectation */
5045 const float c_GSM_FN_DURATION_MS := 4.61538;
5046 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005047 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005048 if (not match(fn_expired, t_fn_expected)) {
5049 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5050 }
5051
5052 /* There are three TIME.ind in every fn MOD 13 */
5053 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5054 /* Add some tolerance */
5055 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5056 if (not match(num_time_ind, t_time_ind_exp)) {
5057 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5058 }
5059
5060 setverdict(pass);
5061}
5062
Harald Welte4832c862019-05-25 14:57:18 +02005063/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5064testcase TC_pcu_rts_req() runs on test_CT {
5065 var PCUIF_send_data pcu_sd;
5066 var integer first_fn, last_fn;
5067 var integer num_rts_pdtch := 0;
5068 var integer num_rts_ptcch := 0;
5069 var float test_duration := 5.0;
5070 timer T;
5071
5072 f_init_pcu_test();
5073 f_TC_pcu_act_req(0, 0, 7, true);
5074
5075 PCU.clear;
5076 T.start(test_duration);
5077 alt {
5078 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5079 -> value pcu_sd {
5080 num_rts_pdtch := num_rts_pdtch + 1;
5081 if (not isbound(first_fn)) {
5082 first_fn := pcu_sd.data.u.rts_req.fn;
5083 }
5084 last_fn := pcu_sd.data.u.rts_req.fn;
5085 repeat;
5086 }
5087 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5088 -> value pcu_sd {
5089 num_rts_ptcch := num_rts_ptcch + 1;
5090 if (not isbound(first_fn)) {
5091 first_fn := pcu_sd.data.u.rts_req.fn;
5092 }
5093 last_fn := pcu_sd.data.u.rts_req.fn;
5094 repeat;
5095 }
5096 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5097 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5098 repeat;
5099 }
5100 [] PCU.receive {
5101 repeat;
5102 }
5103 [] T.timeout {}
5104 }
5105 var integer fn_expired := last_fn - first_fn;
5106 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5107 ", num_rts_ptcch=", num_rts_ptcch);
5108
5109 /* verify the number of frames expired matches our expectation */
5110 const float c_GSM_FN_DURATION_MS := 4.61538;
5111 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005112 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005113 if (not match(fn_expired, t_fn_expected)) {
5114 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5115 }
5116
5117 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5118 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5119 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5120 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5121 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5122 t_ptcch_exp);
5123 }
5124
5125 /* We have 12 PDTCH blocks every 52-multiframe */
5126 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5127 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5128 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5129 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5130 t_pdtch_exp);
5131 }
5132
5133 setverdict(pass);
5134}
5135
Harald Welte07bd2d22019-05-25 11:03:30 +02005136/* test for generating Abis side OML ALERT from the PCU */
5137testcase TC_pcu_oml_alert() runs on test_CT {
5138 var PCUIF_send_data pcu_sd;
5139 var integer num_time_ind := 0;
5140 var integer first_fn, last_fn;
5141 var float test_duration := 5.0;
5142 timer T;
5143
5144 f_init_pcu_test();
5145 f_TC_pcu_act_req(0, 0, 7, true);
5146
5147 /* re-connect CTRL port from BTS to BSC */
5148 f_ipa_ctrl_stop();
5149 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5150
5151 /* Send that OML Alert */
5152 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5153
5154 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5155 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5156 setverdict(pass);
5157}
5158
Harald Welteeaa9a862019-05-26 23:01:08 +02005159/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5160private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5161 var PCUIF_Message first_info;
5162 var integer pcu_conn_id := -1;
5163 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5164 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5165 var OCT4 tlli := '01020304'O;
5166 var OCT1 cause := '23'O;
5167 timer T := 5.0;
5168
5169 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5170
5171 f_l1_tune(L1CTL);
5172 RSL.clear;
5173
5174 f_est_dchan();
5175 L1CTL.clear;
5176
5177 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5178
5179 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5180 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5181 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5182
5183 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5184 T.start;
5185 alt {
5186 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5187 setverdict(pass);
5188 }
5189 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5190 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5191 }
5192 [] PCU.receive {
5193 repeat;
5194 }
5195 [] T.timeout {
5196 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5197 }
5198 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005199
5200 /* release the channel */
5201 f_rsl_chan_deact();
5202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5203 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005204}
5205testcase TC_pcu_rr_suspend() runs on test_CT {
5206 var ConnHdlrPars pars;
5207 var ConnHdlr vc_conn;
5208
5209 f_init();
5210
5211 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5212 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5213 vc_conn.done;
5214}
Harald Welte07bd2d22019-05-25 11:03:30 +02005215
Harald Weltea2e0e942019-05-27 18:12:53 +02005216/* Ensure that PCUIF socket can accept only a single connection */
5217testcase TC_pcu_socket_connect_multi() runs on test_CT {
5218 timer T := 5.0;
5219
5220 /* this (among other things) establishes the first connection to the PCUIF socket */
5221 f_init();
5222
5223 /* try to establish a second connection, expect it to fail */
5224 PCU.send(UD_connect:{mp_pcu_socket, -1});
5225 T.start;
5226 alt {
5227 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5228 setverdict(pass);
5229 }
5230 [] PCU.receive(UD_connect_result:?) {
5231 setverdict(fail, "Unexpected unix domain connect result");
5232 }
5233 [] T.timeout {
5234 setverdict(pass);
5235 }
5236 }
5237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5238}
5239
Harald Weltec8effb72019-05-27 18:23:04 +02005240/* Ensure that PCUIF socket can disconnect + reconnect */
5241testcase TC_pcu_socket_reconnect() runs on test_CT {
5242 /* this (among other things) establishes the first connection to the PCUIF socket */
5243 f_init();
5244
5245 f_sleep(1.0);
5246
5247 f_pcuif_close(PCU, g_pcu_conn_id);
5248 g_pcu_conn_id := -1;
5249
5250 f_sleep(1.0);
5251
5252 /* re-connect */
5253 PCU.clear;
5254 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5255 setverdict(pass);
5256
5257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5258}
5259
Harald Weltebe030482019-05-27 22:29:35 +02005260/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005261private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5262runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005263 var L1ctlDlMessage l1_dl;
5264 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005265 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005266 timer T := 5.0;
5267 T.start;
5268 alt {
5269 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005270 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5271 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005272 repeat;
5273 }
5274 }
5275 [] pt.receive {
5276 repeat;
5277 }
5278 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5280 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005281 }
5282 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005283 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005284}
5285
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005286/* Check if GPRS Indicator is present in RR System Information of a given type */
5287private function f_si_has_gprs_indicator(RrMessageType si_type)
5288runs on test_CT return boolean {
5289 var SystemInformation si := f_get_si(L1CTL, si_type);
5290
5291 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005292 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005293 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005294 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005295 }
5296
5297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5298 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005299}
5300
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005301/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5302private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5303runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005304 /* don't call f_init() as this would connect PCU socket */
5305 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005306
5307 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005308 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005309 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005310
5311 f_init_l1ctl();
5312 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005313 f_sleep(2.0);
5314 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005315
5316 if (f_si_has_gprs_indicator(si_type)) {
5317 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005318 } else {
5319 setverdict(pass);
5320 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005321
Harald Weltebe030482019-05-27 22:29:35 +02005322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5323}
5324
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005325testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5326 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5327}
Harald Weltebe030482019-05-27 22:29:35 +02005328
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005329testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5330 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5331}
5332
5333/* Ensure that GPRS capability is advertised after PCU socket connect */
5334private function f_TC_pcu_socket_connect(RrMessageType si_type)
5335runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005336 /* this (among other things) establishes the first connection to the PCUIF socket */
5337 f_init();
5338 f_init_l1ctl();
5339 f_l1_tune(L1CTL);
5340
5341 f_sleep(2.0);
5342 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005343
5344 if (not f_si_has_gprs_indicator(si_type)) {
5345 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005346 } else {
5347 setverdict(pass);
5348 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005349
Harald Weltebe030482019-05-27 22:29:35 +02005350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5351}
5352
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005353testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5354 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5355}
Harald Weltebe030482019-05-27 22:29:35 +02005356
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005357testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5358 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5359}
5360
5361/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5362private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5363runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005364 /* this (among other things) establishes the first connection to the PCUIF socket */
5365 f_init();
5366 f_init_l1ctl();
5367 f_l1_tune(L1CTL);
5368
5369 f_pcuif_close(PCU, g_pcu_conn_id);
5370 g_pcu_conn_id := -1;
5371
5372 f_sleep(1.0);
5373
5374 /* re-connect */
5375 PCU.clear;
5376 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5377
5378 f_sleep(2.0);
5379 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005380
5381 if (f_si_has_gprs_indicator(si_type)) {
5382 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005383 } else {
5384 setverdict(pass);
5385 }
5386
5387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5388}
5389
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005390testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5391 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5392}
5393
5394testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5395 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5396}
5397
Oliver Smithf5239c72019-08-28 10:01:25 +02005398/* 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) */
5399testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5400 var SystemInformation si3 := valueof(ts_SI3_default);
5401
5402 f_init();
5403
Harald Welte76220222020-10-11 20:32:44 +02005404 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5405 * information */
5406 timer T := 2.0;
5407 T.start;
5408 alt {
5409 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5410 [] T.timeout {}
5411 }
5412
Oliver Smithf5239c72019-08-28 10:01:25 +02005413 /* Verify cell_id */
5414 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5415 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5416 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005417 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5418 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5419 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005420 }
5421
5422 /* Verify LAC */
5423 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5424 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5425 if (lac_si3 != lac_pcu) {
5426 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5427 }
5428
5429 setverdict(pass);
5430}
Harald Welted66c9b82019-05-25 09:03:15 +02005431
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005432/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5433testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5434 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005435 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005436
5437 f_init();
5438
5439 info_ind := g_pcu_last_info.u.info_ind;
5440
5441 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5442 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5443 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5444 /* Skip inactive timeslots */
5445 continue;
5446 }
5447
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005448 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005449 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005450 else
5451 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005452
5453 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005454 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005455 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005456 hsn := fhp.maio_hsn.hsn,
5457 maio := fhp.maio_hsn.maio,
5458 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005459 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005460 } else {
5461 tr_ts := tr_PCUIF_InfoTrxTsH0;
5462 }
5463
5464 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5465 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5466 if (not match(ts, tr_ts)) {
5467 setverdict(fail, "Hopping parameters do not match: ",
5468 "received ", ts, " vs expected ", tr_ts);
5469 } else {
5470 setverdict(pass);
5471 }
5472 }
5473 }
5474}
5475
Alexander Couzens5283f552020-07-28 15:39:04 +02005476/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5477testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5478 f_init_vty_bsc();
5479 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5480 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5481
5482 f_init();
5483
5484 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5485 if (not ischosen(remote_addr.v10)) {
5486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5487 log2str("Unexpected remote_addr: ", remote_addr));
5488 }
5489
5490 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5491 setverdict(fail, "Received address family is not IPv4");
5492 }
5493
5494 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5495 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5496 }
5497
5498 setverdict(pass);
5499}
5500
5501/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5502testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5503 f_init_vty_bsc();
5504 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5505
5506 f_init();
5507
5508 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5509 if (not ischosen(remote_addr.v10)) {
5510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5511 log2str("Unexpected remote_addr: ", remote_addr));
5512 }
5513
5514 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5515 setverdict(fail, "Received address family is not IPv6");
5516 }
5517
5518 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5519 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5520 }
5521
5522 setverdict(pass);
5523}
5524
Harald Welte3d04ae62018-04-04 20:29:05 +02005525/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005526 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005527 ***********************************************************************/
5528
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005529private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5530 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005531runs on ConnHdlr {
5532 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005533
5534 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005535 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005536 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5537 repeat;
5538 }
5539 }
5540}
5541
5542private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5543runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005544 /* Expect BTS to immediately acknowledge activation as PDCH */
5545 PCU.clear;
5546 f_rsl_chan_act(g_pars.chan_mode);
5547 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005548 timer T_wait := 2.0;
5549 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005550 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005551 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005552 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005553 [] T_wait.timeout {
5554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5555 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5556 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005557 }
5558 /* try to activate this PDCH from the PCU point of view */
5559 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5560 /* FIXME: is there a response? */
5561}
5562
5563private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5564runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005565 /* Send RSL CHAN REL (deactivate) */
5566 PCU.clear;
5567 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5568 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005569 timer T_wait := 2.0;
5570 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005571 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005572 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005573 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005574 [] T_wait.timeout {
5575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5576 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5577 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005578 }
5579 /* Emulate PCU asking BTS to deactivate PDCH */
5580 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5581 alt {
5582 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5583 setverdict(pass);
5584 }
5585 [] RSL.receive { repeat; }
5586 }
5587}
5588
5589/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005590private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005591 var PCUIF_Message first_info;
5592 var integer ts_nr := g_chan_nr.tn;
5593 var integer trx_nr := 0;
5594 var integer bts_nr := 0;
5595 var integer pcu_conn_id := -1;
5596
5597 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5598
5599 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5600 f_sleep(3.0);
5601 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5602 setverdict(pass);
5603}
5604testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5605 var ConnHdlrPars pars;
5606 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005607 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005608
5609 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5610 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5611 vc_conn.done;
5612}
5613
5614/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005615private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005616 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005617 var integer pcu_conn_id := -1;
5618
5619 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5620
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005621 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5622 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5623 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005624 setverdict(pass);
5625}
5626testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5627 var ConnHdlrPars pars;
5628 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005629 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005630
5631 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5632 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5633 vc_conn.done;
5634}
5635
5636/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005637private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005638 var PCUIF_Message first_info;
5639 var integer ts_nr := g_chan_nr.tn;
5640 var integer trx_nr := 0;
5641 var integer bts_nr := 0;
5642 var integer pcu_conn_id := -1;
5643
5644 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5645
5646 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005647 /* Send a second Chan Activ and expect it to be NACKed */
5648 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5649 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005650 setverdict(pass);
5651}
5652testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5653 var ConnHdlrPars pars;
5654 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005655 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005656
5657 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5658 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5659 vc_conn.done;
5660}
5661
5662/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005663private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005664 var PCUIF_Message first_info;
5665 var integer ts_nr := g_chan_nr.tn;
5666 var integer trx_nr := 0;
5667 var integer bts_nr := 0;
5668 var integer pcu_conn_id := -1;
5669 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5670
5671 /* register for the TCH/F channel number */
5672 f_rslem_register(0, chan_nr);
5673
5674 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5675
5676 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5677 "RSL CHAN ACT");
5678 setverdict(pass);
5679}
5680testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5681 var ConnHdlrPars pars;
5682 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005683 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005684
5685 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5686 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5687 vc_conn.done;
5688}
5689
5690/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005691private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005692 var PCUIF_Message first_info;
5693 var integer ts_nr := g_chan_nr.tn;
5694 var integer trx_nr := 0;
5695 var integer bts_nr := 0;
5696 var integer pcu_conn_id := -1;
5697 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5698 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5699
5700 /* register for the TCH/H channel numbers */
5701 f_rslem_register(0, chan_nr[0]);
5702 f_rslem_register(0, chan_nr[1]);
5703
5704 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5705
5706 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5707 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5708 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5709 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5710 setverdict(pass);
5711}
5712testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5713 var ConnHdlrPars pars;
5714 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005715 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005716
5717 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5718 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5719 vc_conn.done;
5720}
5721
Harald Welte9bbbfb52018-04-05 09:33:19 +02005722/***********************************************************************
5723 * IPA Style Dynamic Timeslot Support
5724 ***********************************************************************/
5725
5726private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5727runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005728 /* Expect BTS to immediately acknowledge activation as PDCH */
5729 PCU.clear;
5730 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5731 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005732 timer T_wait := 2.0;
5733 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005734 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005735 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005736 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005737 [] T_wait.timeout {
5738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5739 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5740 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005741 }
5742 /* try to activate this PDCH from the PCU point of view */
5743 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5744 /* FIXME: is there a response? */
5745
5746 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5747}
5748
5749private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5750runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005751 /* Send RSL CHAN REL (deactivate) */
5752 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5753 PCU.clear;
5754 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005755 timer T_wait := 2.0;
5756 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005757 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005758 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005759 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005760 [] T_wait.timeout {
5761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5762 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5763 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005764 }
5765 /* Emulate PCU asking BTS to deactivate PDCH */
5766 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5767 alt {
5768 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5769 setverdict(pass);
5770 }
5771 [] RSL.receive { repeat; }
5772 }
5773}
5774
5775/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005776private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005777 var PCUIF_Message first_info;
5778 var integer ts_nr := g_chan_nr.tn;
5779 var integer trx_nr := 0;
5780 var integer bts_nr := 0;
5781 var integer pcu_conn_id := -1;
5782
5783 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5784
5785 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5786 f_sleep(3.0);
5787 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5788
5789 setverdict(pass);
5790
5791}
5792testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5793 var ConnHdlrPars pars;
5794 var ConnHdlr vc_conn;
5795 f_init();
5796
5797 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5798 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5799 vc_conn.done;
5800}
5801
5802/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005803private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005804 var PCUIF_Message first_info;
5805 var integer ts_nr := g_chan_nr.tn;
5806 var integer trx_nr := 0;
5807 var integer bts_nr := 0;
5808 var integer pcu_conn_id := -1;
5809
5810 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5811
5812 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5813 "RSL CHAN ACT");
5814 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5815 "RF CHAN REL", true);
5816 setverdict(pass);
5817}
5818testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5819 var ConnHdlrPars pars;
5820 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005821 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005822
5823 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5824 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5825 vc_conn.done;
5826}
5827
5828/* 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 +07005829private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005830 var PCUIF_Message first_info;
5831 var integer ts_nr := g_chan_nr.tn;
5832 var integer trx_nr := 0;
5833 var integer bts_nr := 0;
5834 var integer pcu_conn_id := -1;
5835
5836 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5837
5838 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5839 "RSL CHAN ACT");
5840
5841 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5842 alt {
5843 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5844 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005846 }
5847 [] RSL.receive { repeat; }
5848 }
5849
5850 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5851 "RF CHAN REL", true);
5852 setverdict(pass);
5853}
5854testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5855 var ConnHdlrPars pars;
5856 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005857 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005858
5859 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5860 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5861 vc_conn.done;
5862}
5863
5864/* 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 +07005865private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005866 var PCUIF_Message first_info;
5867 var integer ts_nr := g_chan_nr.tn;
5868 var integer trx_nr := 0;
5869 var integer bts_nr := 0;
5870 var integer pcu_conn_id := -1;
5871
5872 /* register for the TCH/F channel number */
5873 f_rslem_register(0, g_chan_nr);
5874
5875 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5876
5877 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5878
5879 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5880 "RSL CHAN ACT");
5881
5882 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5883
5884 setverdict(pass);
5885}
5886testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5887 var ConnHdlrPars pars;
5888 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005889 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005890
5891 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5892 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5893 vc_conn.done;
5894}
5895
5896
Harald Welte0472ab42018-03-12 15:02:26 +01005897/***********************************************************************
5898 * LAPDm / RLL related
5899 ***********************************************************************/
5900
5901private function f_tx_lapdm(template (value) LapdmFrame l,
5902 template (value) RslLinkId link_id) runs on ConnHdlr {
5903 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005904 var template (value) SacchL1Header l1h;
5905
5906 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005907 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005908 /* Compose dummy L1 header */
5909 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5910 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 +02005911 } else {
5912 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005913 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 +01005914 }
Harald Welte0472ab42018-03-12 15:02:26 +01005915}
5916
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005917private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005918 uint3_t sapi,
5919 RslLinkId link_id,
5920 octetstring l3,
5921 boolean exp
5922}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005923private type record of RllTestCase RllTestCases;
5924private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5925 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005926 sapi := sapi,
5927 link_id := id,
5928 l3 := l3,
5929 exp := exp
5930}
5931
5932/* execute the same callback function with a set of different parameters (tcs) on a
5933 * variety of logical channels */
5934private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5935 var ConnHdlrPars pars;
5936 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005937 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005938
5939 /* test on each of the channels we have */
5940 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5941 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5942
5943 /* test each of the test cases on the current channel */
5944 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5945 pars.spec.rll := tcs[j];
5946 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5947 vc_conn := f_start_handler(fn, pars);
5948 vc_conn.done;
5949 }
5950 }
5951
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005953}
5954
5955/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5956private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5957 var RllTestCase tc := g_pars.spec.rll;
5958 timer T := 3.0;
5959
5960 f_l1_tune(L1CTL);
5961 RSL.clear;
5962
5963 /* activate the logical channel */
5964 f_est_dchan();
5965 L1CTL.clear;
5966
5967 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5968 T.start;
5969 alt {
5970 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5971 if (tc.exp) {
5972 setverdict(pass);
5973 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005975 }
5976 }
5977 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5978 if (tc.exp) {
5979 setverdict(pass);
5980 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005982 }
5983 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005984 /* We also expect to receive the measurements */
5985 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005986 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005988 }
5989 [not tc.exp] T.timeout {
5990 setverdict(pass);
5991 }
5992 }
5993
5994 f_rsl_chan_deact();
5995 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5996 f_rslem_unregister(0, g_chan_nr);
5997}
5998testcase TC_rll_est_ind() runs on test_CT {
5999 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006000 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006001 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006002 /* normal SAPI0 establishment */
6003 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006004 /* SAPI 3 doesn't support contention resolution */
6005 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6006 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6007 /* normal SAPI3 establishment on main DCCH */
6008 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6009 /* normal SAPI3 establishment on SACCH */
6010 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6011 };
6012 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6013}
6014
6015/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6016private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6017 var RllTestCase tc := g_pars.spec.rll;
6018 var L1ctlDlMessage dl;
6019 timer T := 3.0;
6020
6021 f_l1_tune(L1CTL);
6022 RSL.clear;
6023
6024 /* activate the logical channel */
6025 f_est_dchan();
6026 L1CTL.clear;
6027
6028 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6029 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6030 T.start;
6031 alt {
6032 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6033 var LapdmFrame lapdm;
6034 var octetstring l2 := dl.payload.data_ind.payload;
6035 if (dl.dl_info.link_id.c == SACCH) {
6036 /* remove L1 header */
6037 l2 := substr(l2, 2, lengthof(l2)-2);
6038 }
6039 lapdm.ab := dec_LapdmFrameAB(l2);
6040 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6041 setverdict(pass);
6042 } else {
6043 repeat;
6044 }
6045 }
6046 [] L1CTL.receive { repeat; }
6047 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006049 }
6050 }
6051
6052 f_rsl_chan_deact();
6053 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6054 f_rslem_unregister(0, g_chan_nr);
6055}
6056testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6057 var RllTestCases tcs := {
6058 /* normal SAPI3 establishment on main DCCH */
6059 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6060 };
6061 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6062}
6063testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6064 var RllTestCases tcs := {
6065 /* normal SAPI3 establishment on SACCH */
6066 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6067 }
6068 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6069}
6070
6071/* altstep to receive a LAPDm frame matching the given template */
6072private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6073 var L1ctlDlMessage dl;
6074 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6075 var LapdmFrame lapdm;
6076 var octetstring l2 := dl.payload.data_ind.payload;
6077 if (dl.dl_info.link_id.c == SACCH) {
6078 /* remove L1 header */
6079 l2 := substr(l2, 2, lengthof(l2)-2);
6080 }
6081 if (ischosen(exp.ab)) {
6082 lapdm.ab := dec_LapdmFrameAB(l2);
6083 } else if (ischosen(exp.b4)) {
6084 lapdm.b4 := dec_LapdmFrameB4(l2);
6085 } else if (ischosen(exp.bbis)) {
6086 lapdm.bbis := dec_LapdmFrameBbis(l2);
6087 }
6088 log("Rx LAPDm ", lapdm);
6089 if (match(lapdm, exp)) {
6090 setverdict(pass);
6091 } else {
6092 repeat;
6093 }
6094 }
6095 [] L1CTL.receive { repeat; }
6096}
6097private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6098 timer T := t;
6099 T.start;
6100 alt {
6101 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006103 }
6104 [] as_l1_exp_lapdm(exp);
6105 }
6106}
6107
6108/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6109private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6110 /* send SABM from MS -> BTS */
6111 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6112 /* expect RLL EST IND on Abis */
6113 alt {
6114 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6115 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6116 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006118 }
6119 [] RSL.receive { repeat; }
6120 }
6121 /* expect UA from BTS -> MS */
6122 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6123}
6124
6125/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6126private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6127 var RllTestCase tc := g_pars.spec.rll;
6128
6129 f_l1_tune(L1CTL);
6130 RSL.clear;
6131
6132 /* activate the logical channel */
6133 f_est_dchan();
6134 L1CTL.clear;
6135
6136 /* first establish the link-layer */
6137 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6138
6139 /* then send the DISC */
6140 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6141 /* ... and expect the REL IND on the RSL side */
6142 alt {
6143 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6144 setverdict(pass);
6145 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006146 /* We also expect to receive the measurements */
6147 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006148 }
6149
6150 /* release the channel */
6151 f_rsl_chan_deact();
6152 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6153 f_rslem_unregister(0, g_chan_nr);
6154}
6155testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6156 var RllTestCases tcs := {
6157 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6158 };
6159 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6160}
6161
6162testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6163 var RllTestCases tcs := {
6164 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6165 };
6166 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6167}
6168testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6169 var RllTestCases tcs := {
6170 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6171 };
6172 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6173}
6174testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6175 var RllTestCases tcs := {
6176 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6177 };
6178 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6179}
6180
6181/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6182private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6183 var RllTestCase tc := g_pars.spec.rll;
6184 f_l1_tune(L1CTL);
6185 RSL.clear;
6186
6187 /* activate the logical channel */
6188 f_est_dchan();
6189 L1CTL.clear;
6190
6191 /* first establish the link-layer */
6192 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6193
6194 /* then send the REL REQ via RSL */
6195 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6196 /* ... and expect the DISC on the Um side */
6197 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006198 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006199 /* FIXME: send a UA in resposne to the DISC */
6200 }
6201 }
6202
6203 /* release the channel */
6204 f_rsl_chan_deact();
6205 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6206 f_rslem_unregister(0, g_chan_nr);
6207}
6208testcase TC_rll_rel_req() runs on test_CT {
6209 var RllTestCases tcs := {
6210 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6211 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6212 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6213 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6214 };
6215 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6216}
6217
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006218/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006219testcase TC_rll_data_req() runs on test_CT {
6220}
6221
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006222/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006223testcase TC_rll_data_ind() runs on test_CT {
6224}
6225
6226/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6227private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6228 var RllTestCase tc := g_pars.spec.rll;
6229
6230 f_l1_tune(L1CTL);
6231 RSL.clear;
6232
6233 f_est_dchan();
6234 L1CTL.clear;
6235
6236 /* Send UNITDATA REQ on RSL side */
6237 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6238 /* Expect it to arrive on the other side */
6239 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006240 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006241 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006242 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006243 }
6244
6245 /* release the channel */
6246 f_rsl_chan_deact();
6247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6248 f_rslem_unregister(0, g_chan_nr);
6249}
6250testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6251 var octetstring l3 := f_rnd_octstring(15);
6252 var RllTestCases tcs := {
6253 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6254 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6255 };
6256 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6257}
6258testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6259 var octetstring l3 := f_rnd_octstring(19);
6260 var RllTestCases tcs := {
6261 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6262 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6263 };
6264 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6265}
6266
6267/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6268private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6269 var RllTestCase tc := g_pars.spec.rll;
6270
6271 f_l1_tune(L1CTL);
6272 RSL.clear;
6273
6274 f_est_dchan();
6275 L1CTL.clear;
6276
6277 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006278 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006279 /* Expdct RLL UNITDATA IND on RSL side */
6280 alt {
6281 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6282 setverdict(pass);
6283 }
6284 [] RSL.receive { repeat; }
6285 }
6286
6287 /* release the channel */
6288 f_rsl_chan_deact();
6289 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6290 f_rslem_unregister(0, g_chan_nr);
6291}
6292testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006293 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006294 var RllTestCases tcs := {
6295 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6296 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6297 };
6298 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6299}
6300testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6301 var octetstring l3 := f_rnd_octstring(18);
6302 var RllTestCases tcs := {
6303 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6304 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6305 };
6306 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6307}
6308
Harald Weltee613f962018-04-18 22:38:16 +02006309/***********************************************************************
6310 * Encryption Related
6311 ***********************************************************************/
6312
6313/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006314private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006315 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6316 if (link_id.c == SACCH) {
6317 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6318 } else {
6319 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6320 }
6321}
6322
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006323/* Expect (or not expect) other kinds of messages */
6324private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6325 [exp_any] RSL.receive { repeat; }
6326 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006328 }
6329}
6330
Harald Weltee613f962018-04-18 22:38:16 +02006331/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006332private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006333 RslLinkId link_id,
6334 octetstring l3,
6335 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006336 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006337) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006338 timer T := 3.0;
6339 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6340 T.start;
6341 /* Expect RLL UNITDATA IND on RSL side */
6342 alt {
6343 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6344 setverdict(pass);
6345 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006346 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006347 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006348 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006350 }
Harald Weltee613f962018-04-18 22:38:16 +02006351 }
6352}
6353
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006354/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6355private function f_data_mo(
6356 RslLinkId link_id,
6357 boolean p, uint3_t nr, uint3_t ns,
6358 octetstring l3,
6359 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006360 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006361) runs on ConnHdlr {
6362 timer T := 3.0;
6363 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6364 T.start;
6365 /* Expect RLL DATA IND on RSL side */
6366 alt {
6367 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6368 setverdict(pass);
6369 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006370 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006371 [] as_rsl_any_ind(exp_any);
6372 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006374 }
6375 }
6376}
6377
Harald Weltee613f962018-04-18 22:38:16 +02006378/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006379private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006380 f_l1_tune(L1CTL);
6381 f_est_dchan(true);
6382
6383 /* now we actually need to transmit some data both ways to check if the encryption works */
6384 var L1ctlDlMessage dl;
6385
Stefan Sperling603d98e2018-07-25 16:47:28 +02006386 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006387 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6388
6389 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6390 f_unitdata_mt(link_id, l3);
6391
6392 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6393 f_unitdata_mo(link_id, l3);
6394
6395 /* release the channel */
6396 f_rsl_chan_deact();
6397 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6398 f_rslem_unregister(0, g_chan_nr);
6399}
6400testcase TC_chan_act_a51() runs on test_CT {
6401 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6402 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6403 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6404}
6405testcase TC_chan_act_a52() runs on test_CT {
6406 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6407 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6408 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6409}
6410testcase TC_chan_act_a53() runs on test_CT {
6411 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6412 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6413 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6414}
6415
Eric Wildf1827a72019-05-28 17:37:35 +02006416/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6417 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 +07006418private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006419 f_l1_tune(L1CTL);
6420 f_est_dchan(true);
6421
6422 /* now we actually need to transmit some data both ways to check if the encryption works */
6423 var L1ctlDlMessage dl;
6424
6425 var octetstring l3 := f_rnd_octstring(20);
6426 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6427
6428 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6429 f_unitdata_mt(link_id, l3);
6430
6431 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6432 f_unitdata_mo(link_id, l3);
6433
6434 var RSL_Message rsl;
6435 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6436
6437 /* modify key to break proper encryption */
6438 g_pars.encr.key := f_rnd_octstring(8);
6439 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6440 rsl.ies := rsl.ies & { ei };
6441 RSL.send(rsl);
6442
6443 timer T0 := 1.0;
6444 T0.start;
6445 /* Expect RSL MODIFY ACK */
6446 alt {
6447 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6448 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6450 }
6451 [] T0.timeout {
6452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6453 }
6454 }
6455
6456 var octetstring l3msg := f_rnd_octstring(15);
6457 timer T1 := 3.0;
6458 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6459 due to broken encryption */
6460 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6461 T1.start;
6462 alt {
6463 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6465 }
6466 [] T1.timeout {
6467 setverdict(pass);
6468 }
6469 }
6470
6471 /* release the channel */
6472 f_rsl_chan_deact();
6473 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6474 f_rslem_unregister(0, g_chan_nr);
6475}
6476testcase TC_rsl_modify_encr() runs on test_CT {
6477 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6478 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6479 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6480}
Harald Weltee613f962018-04-18 22:38:16 +02006481
6482/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006483private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006484 /* L3 payload doesn't matter, as it is passed transparently */
6485 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6486 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6487 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6488
6489 f_l1_tune(L1CTL);
6490
6491 /* first establish a dedicated channel in the clear */
6492 f_est_dchan(false);
6493
6494 /* Establish ABM */
6495 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6496
6497 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6498 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6499 /* expect the L3 to arrive still unencrypted on the MS side */
6500 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6501
6502 /* configure L1 to apply ciphering */
6503 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6504 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6505
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006506 /* send first ciphered I-frame in response and expect it on RSL */
6507 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006508
6509 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6510 * and hence enable encryption also on the downlink */
6511
6512 /* expect bi-directional communication work in encrypted mode */
6513 f_unitdata_mo(link_id, f_rnd_octstring(15));
6514 f_unitdata_mt(link_id, f_rnd_octstring(15));
6515
6516 /* release the channel */
6517 f_rsl_chan_deact();
6518 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6519 f_rslem_unregister(0, g_chan_nr);
6520}
6521testcase TC_encr_cmd_a51() runs on test_CT {
6522 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6523 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6524 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6525}
6526testcase TC_encr_cmd_a52() runs on test_CT {
6527 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6528 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6529 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6530}
6531testcase TC_encr_cmd_a53() runs on test_CT {
6532 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6533 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6534 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6535}
6536
6537private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6538 var LapdmFrame lf;
6539 var octetstring reenc;
6540
6541 /* decode the LAPDm frame */
6542 if (ischosen(exp_match.ab)) {
6543 lf.ab := dec_LapdmFrameAB(enc);
6544 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006546 }
6547
6548 /* check if decoder result matches expectation */
6549 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006551 } else {
6552 log(name, ": matched");
6553 setverdict(pass);
6554 }
6555
6556 /* test if re-encoded frame equals original input */
6557 reenc := enc_LapdmFrame(lf);
6558 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006560 } else {
6561 setverdict(pass);
6562 }
6563}
6564
6565testcase TC_lapdm_selftest() runs on test_CT {
6566 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6567 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6568 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6569 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6570 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6571 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6572 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6573}
6574
Stefan Sperling4880be42018-08-07 18:12:59 +02006575/***********************************************************************
6576 * DTX Related (see GSM 05.08, section 8.3)
6577 ***********************************************************************/
6578
6579/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006580private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006581 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6582 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6583 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6584 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6585}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006586private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006587 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6588 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6589}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006590private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006591 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6592 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6593 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6594 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6595}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006596private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006597 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6598 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6599 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6600 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6601 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6602 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6603 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6604 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6605}
6606
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006607private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006608 var L1ctlDlMessage dl;
6609 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6610 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6611 var GsmFrameNumber first_fn;
6612 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006613 var integer nfill_frames_sacch := 0;
6614 var integer nfill_frames_nonsacch := 0;
6615 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006616 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6617 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006618 const integer frame_dtx_tchf_mod := 104;
6619 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6620 * which operates in terms of blocks rather than frames. */
6621 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6622 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006623 timer T := 5.0;
6624
6625 f_l1_tune(L1CTL);
6626 RSL.clear;
6627 L1CTL.clear;
6628
6629 /* activate TCHF signalling channel */
6630 f_est_dchan(false);
6631
6632 T.start;
6633 alt {
6634 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6635 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6636 var octetstring l2 := dl.payload.data_ind.payload;
6637
6638 if (is_first_frame) {
6639 is_first_frame := false;
6640 first_fn := dl.dl_info.frame_nr;
6641 }
6642
6643 if (dl.dl_info.link_id.c == SACCH) {
6644 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6645 if (not match(l2_fill_frame_sacch, l2)) {
6646 repeat;
6647 }
6648 } else if (not match(l2_fill_frame, l2)) {
6649 repeat;
6650 }
6651
6652 if (dtxd) {
6653 if (not f_g_chan_is_tchf()) {
6654 T.stop;
6655 f_rsl_chan_deact();
6656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006657 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 +02006658 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006659 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006660 T.stop;
6661 f_rsl_chan_deact();
6662 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006663
6664 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6665 * 2 SACCH, 1 TCH/F */
6666 expected_fill_frames := 3;
6667
6668 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6669 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6670 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006672 } else {
6673 setverdict(pass);
6674 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006675 } else {
6676 if (dl.dl_info.link_id.c == SACCH) {
6677 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006678 repeat;
6679 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006680 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6681 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6682 * we should only see the subset of frames numbers which correspond to a block boundary.
6683 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6684 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6685 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6686 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6687 repeat;
6688 }
6689 }
6690 log("Received DTX TCH fill frame with bad frame number: ", fn,
6691 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6692 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6693 f_rsl_chan_deact();
6694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006695 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006696 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006697 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006698 if (dl.dl_info.link_id.c == SACCH) {
6699 nfill_frames_sacch := nfill_frames_sacch + 1;
6700 } else {
6701 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6702 }
6703 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006704 T.stop;
6705 if (f_g_chan_is_tchf()) {
6706 /* Without DTX we can expect 25 fill frames for every 104 frames.
6707 * (24 FACCH + 1 SACCH filling) */
6708 expected_fill_frames := 25;
6709 } else if (f_g_chan_is_tchh()) {
6710 /* We can expect 2 fill frames for every 104 frames. */
6711 expected_fill_frames := 2;
6712 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6713 /* We can expect 5 fill frames for every 104 frames. */
6714 expected_fill_frames := 5;
6715 } else {
6716 f_rsl_chan_deact();
6717 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006719 }
6720
6721 f_rsl_chan_deact();
6722 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006723
6724 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006725 setverdict(pass);
6726 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006727 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6728 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006730 }
6731 } else {
6732 repeat;
6733 }
6734 }
6735 }
6736 [] L1CTL.receive { repeat; }
6737 [] T.timeout {
6738 f_rsl_chan_deact();
6739 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006741 }
6742 }
6743}
6744
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006745private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006746 f_test_l2_fill_frames(false);
6747}
6748
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006749private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006750 f_test_l2_fill_frames(true);
6751}
6752
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006753private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006754 var ConnHdlr vc_conn;
6755 var ConnHdlrPars pars;
6756 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006757 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006758 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6759 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6760 if (dtxd) {
6761 if (i >= 4) { /* DTX is only allowed on TCH/F */
6762 break;
6763 }
6764 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6765 } else {
6766 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6767 }
6768 vc_conn.done;
6769 }
6770}
6771
6772/* Verify that L2 fill frames are sent on TCH in signaling mode if
6773 * there is nothing to transmit while DTX is disabled on downlink. */
6774testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6775 f_tch_sign_l2_fill_frame(false);
6776}
6777
6778/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6779 * there is nothing to transmit while DTX is enabled on downlink. */
6780testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6781 f_tch_sign_l2_fill_frame(true);
6782}
Harald Welte0472ab42018-03-12 15:02:26 +01006783
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006784testcase TC_chopped_ipa_ping() runs on test_CT {
6785 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6786}
6787
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006788testcase TC_chopped_ipa_payload() runs on test_CT {
6789 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6790}
6791
Harald Welte0472ab42018-03-12 15:02:26 +01006792/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6793/* protocol error as per 44.006 */
6794/* link layer failure (repetition of I-frame N200 times without ACK */
6795/* repetition of SABM or DISC N200 times without ACK */
6796/* receptiom of SABM in multi-frame established state */
6797
6798
Harald Welte68e495b2018-02-25 00:05:57 +01006799/* TODO Areas:
6800
6801* channel activation
6802** with BS_Power / MS_Power, bypassing power control loop
6803** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006804** with timing advance from initial activation on
6805* mode modify
6806** encryption
6807** multirate
6808* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006809** unsupported algorithm
6810* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006811* BS Power Control
6812* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006813* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006814* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006815** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006816* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006817** DATA_IND from BTS->PCU
6818** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006819
6820*/
Harald Welte70767382018-02-21 12:16:40 +01006821
6822control {
6823 execute( TC_chan_act_stress() );
6824 execute( TC_chan_act_react() );
6825 execute( TC_chan_deact_not_active() );
6826 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006827 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006828 execute( TC_sacch_filling() );
6829 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006830 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006831 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006832 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006833 execute( TC_sacch_chan_act_ho_async() );
6834 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006835 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006836 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006837 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006838 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006839 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006840 execute( TC_rach_load_idle_thresh0() );
6841 execute( TC_rach_load_idle_below_thresh() );
6842 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006843 execute( TC_meas_res_sign_tchf() );
6844 execute( TC_meas_res_sign_tchh() );
6845 execute( TC_meas_res_sign_sdcch4() );
6846 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006847 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006848 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006849 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006850 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006851 execute( TC_rsl_bs_pwr_static_ass() );
6852 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006853 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006854 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006855 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006856 execute( TC_rsl_ms_pwr_dyn_up() );
6857 execute( TC_rsl_ms_pwr_dyn_down() );
6858 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6859 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006860 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006861 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006862 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006863 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006864 execute( TC_paging_imsi_80percent() );
6865 execute( TC_paging_tmsi_80percent() );
6866 execute( TC_paging_imsi_200percent() );
6867 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006868 execute( TC_rsl_protocol_error() );
6869 execute( TC_rsl_mand_ie_error() );
6870 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006871 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006872 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006873 execute( TC_si_sched_2bis() );
6874 execute( TC_si_sched_2ter() );
6875 execute( TC_si_sched_2ter_2bis() );
6876 execute( TC_si_sched_2quater() );
6877 execute( TC_si_sched_13() );
6878 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006879 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006880 execute( TC_ipa_crcx_twice_not_active() );
6881 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006882 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006883 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006884
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006885 if (mp_pcu_socket != "") {
6886 execute( TC_pcu_act_req() );
6887 execute( TC_pcu_act_req_wrong_ts() );
6888 execute( TC_pcu_act_req_wrong_bts() );
6889 execute( TC_pcu_act_req_wrong_trx() );
6890 execute( TC_pcu_deact_req() );
6891 execute( TC_pcu_deact_req_wrong_ts() );
6892 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006893 if (mp_l1_supports_gprs) {
6894 execute( TC_pcu_data_req_pdtch() );
6895 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006896 execute( TC_pcu_data_req_wrong_bts() );
6897 execute( TC_pcu_data_req_wrong_trx() );
6898 execute( TC_pcu_data_req_wrong_ts() );
6899 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006900 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006901 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006902 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006903 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006904 execute( TC_pcu_data_req_imm_ass_pch() );
6905 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006906 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006907 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006908 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006909 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006910 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006911 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006912 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006913 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006914 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006915 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006916 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006917 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006918 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006919 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006920 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006921 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006922 execute( TC_dyn_osmo_pdch_act_deact() );
6923 execute( TC_dyn_osmo_pdch_double_act() );
6924 execute( TC_dyn_ipa_pdch_act_deact() );
6925 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6926
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006927 if (PCUIF_Types.mp_pcuif_version >= 10) {
6928 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006929 execute( TC_pcu_socket_nsvc_ipv4() );
6930 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006931 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006932 } else {
6933 log("PCU socket path not available, skipping PCU tests");
6934 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006935
Harald Welte3d04ae62018-04-04 20:29:05 +02006936 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006937 execute( TC_dyn_osmo_pdch_tchf_act() );
6938 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006939 execute( TC_dyn_ipa_pdch_tchf_act() );
6940 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006941
6942 execute( TC_rll_est_ind() );
6943 execute( TC_rll_est_req_DCCH_3() );
6944 execute( TC_rll_est_req_ACCH_3() );
6945 execute( TC_rll_rel_ind_DCCH_0() );
6946 execute( TC_rll_rel_ind_DCCH_3() );
6947 execute( TC_rll_rel_ind_ACCH_0() );
6948 execute( TC_rll_rel_ind_ACCH_3() );
6949 execute( TC_rll_rel_req() );
6950 execute( TC_rll_unit_data_req_DCCH() );
6951 execute( TC_rll_unit_data_req_ACCH() );
6952 execute( TC_rll_unit_data_ind_DCCH() );
6953 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006954
6955 execute( TC_chan_act_a51() );
6956 execute( TC_chan_act_a52() );
6957 execute( TC_chan_act_a53() );
6958 execute( TC_encr_cmd_a51() );
6959 execute( TC_encr_cmd_a52() );
6960 execute( TC_encr_cmd_a53() );
6961
Harald Welteee25aae2019-05-19 14:32:37 +02006962 execute( TC_err_rep_wrong_mdisc() );
6963 execute( TC_err_rep_wrong_msg_type() );
6964 execute( TC_err_rep_wrong_sequence() );
6965
Harald Weltee613f962018-04-18 22:38:16 +02006966 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006967
6968 execute( TC_tch_sign_l2_fill_frame() );
6969 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006970
6971 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006972 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006973}
6974
6975
6976}