blob: 9ebd95237bb8396c08dcd73d64f268076dd9dd7e [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;
Harald Welte70767382018-02-21 12:16:40 +010038import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020039import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010040
41import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010042import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010043import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020044import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010045import from RSL_Emulation all;
46
47import from IPL4asp_Types all;
48import from TRXC_Types all;
49import from TRXC_CodecPort all;
50import from TRXC_CodecPort_CtrlFunct all;
51
Harald Welte883340c2018-02-28 18:59:29 +010052import from PCUIF_Types all;
53import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020054import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010055
Harald Welte7484fc42018-02-24 14:09:45 +010056import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010057import from MobileL3_RRM_Types all;
58import from MobileL3_Types all;
59import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020060import from L3_Common all;
61import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010062
Harald Welte8da48242018-02-27 20:41:32 +010063import from Osmocom_VTY_Functions all;
64import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020065import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010066
Harald Welte505cf9b2018-09-15 17:47:23 +030067friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020068friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020069friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010070friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030071
Harald Welte70767382018-02-21 12:16:40 +010072/* The tests assume a BTS with the following timeslot configuration:
73 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020074 * TS1 : TCH/F
75 * TS2 : TCH/F
76 * TS3 : TCH/F_PDCH (IPA Style)
77 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010078 * TS5 : TCH/H
79 * TS6 : SDCCH/8
80 * TS7 : PDCH
81 */
82
83modulepar {
84 charstring mp_rsl_ip := "127.0.0.2";
85 integer mp_rsl_port := 3003;
86 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070087 integer mp_trx1_arfcn := 873;
88 integer mp_trx2_arfcn := 875;
89 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070090 charstring mp_bts_trxc_ip := "127.0.0.1";
91 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010092 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020093 charstring mp_ctrl_ip := "127.0.0.1";
94 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020095 charstring mp_bsc_ctrl_ip := "127.0.0.1";
96 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020097 integer mp_tolerance_rxqual := 1;
98 integer mp_tolerance_rxlev := 3;
99 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200100 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200101 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200102 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200103 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
104 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 +0200105 integer mp_ms_actual_ta_exp := 0;
106 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Harald Welte70767382018-02-21 12:16:40 +0100114}
115
Harald Welte629cc6b2018-03-11 17:19:05 +0100116type record of RslChannelNr ChannelNrs;
117
Harald Welte70767382018-02-21 12:16:40 +0100118type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100119 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100120 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100121 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100122 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100123 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100124 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100125
126 /* L1CTL port (for classic tests) */
127 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100128
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700129 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700130 port TRXC_CODEC_PT BTS_TRXC;
131 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100132
Harald Weltef50e3ae2018-09-10 10:27:56 +0200133 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100134 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200135 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100136
Harald Welte883340c2018-02-28 18:59:29 +0100137 /* PCU Interface of BTS */
138 port PCUIF_CODEC_PT PCU;
139 var integer g_pcu_conn_id;
140 /* Last PCU INFO IND we received */
141 var PCUIF_Message g_pcu_last_info;
142
Harald Welte48494ca2018-02-25 16:59:50 +0100143 /* SI configuration */
144 var SystemInformationConfig si_cfg := {
145 bcch_extended := false,
146 si1_present := false,
147 si2bis_present := false,
148 si2ter_present := false,
149 si2quater_present := false,
150 si7_present := false,
151 si8_present := false,
152 si9_present := false,
153 si13_present := false,
154 si13alt_present := false,
155 si15_present := false,
156 si16_present := false,
157 si17_present := false,
158 si2n_present := false,
159 si21_present := false,
160 si22_present := false
161 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100162
163 /* all logical channels available on the BTS */
164 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100165 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100166}
167
168/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200169type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100170 port L1CTL_PT L1CTL;
171
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700172 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700173 port TRXC_CODEC_PT BTS_TRXC;
174 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100175
176 timer g_Tguard;
177 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
178
179 var ConnHdlrPars g_pars;
180 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100181 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200182
183 /* PCU Interface of BTS */
184 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100185}
186
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700187function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700188 var bitstring trx_mask := '00000000'B;
189 var integer trx_count := 0;
190 var RSLEm_Event ev;
191 timer T;
192
Harald Welte70767382018-02-21 12:16:40 +0100193 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
194 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
195
196 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
197 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
198 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
199
200 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
201 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700202
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700203 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700204 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700205 T.start(mp_ipa_up_timeout);
206 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700207 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700208 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
209 /* Make sure that all transceivers use unique stream ID */
210 if (trx_mask[enum2int(ev.sid)] == '1'B) {
211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
212 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
213 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700214
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 /* This message (RF RESource INDication) is sent by the IUT itself */
216 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
217 trx_mask[enum2int(ev.sid)] := '1'B;
218 trx_count := trx_count + 1;
219
220 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
221 if (trx_count < mp_transceiver_num) { repeat; }
222 }
223 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
224 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
225 [] T.timeout {
226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
227 "Timeout waiting for RSL bring up");
228 }
229 }
Harald Welte70767382018-02-21 12:16:40 +0100230}
231
232type record ConnHdlrPars {
233 RslChannelNr chan_nr,
234 RSL_IE_ChannelMode chan_mode,
235 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100236 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200237 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200238 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700239 BtsBand bts0_band optional,
240
241 /* Frequency hopping parameters (disabled if absent) */
242 MaioHsn maio_hsn optional,
243 /* MA bitmap to be indicated in RR Immediate Assignment */
244 MobileAllocation ma_map,
245 /* The actual Mobile Allocation (ARFCN list) to be used */
246 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100247}
248
249/* Test-specific parameters */
250type union TestSpecUnion {
251 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100252}
253
Harald Welte82ccef72018-02-25 16:17:33 +0100254template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100255 max_retrans := RACH_MAX_RETRANS_7,
256 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100257 cell_barr_access := false,
258 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100259 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100260};
261
Harald Weltef10153f2018-02-25 16:34:05 +0100262template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100263 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200264 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100265 acs := '0'B,
266 neci := true,
267 rxlev_access_min := 0
268}
269
270template (value) LocationAreaIdentification ts_LAI_default := {
271 mcc_mnc := '262F42'H,
272 lac := 42
273}
274
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700275private template (value) GPRSIndicator ts_GPRSIndicator_def := {
276 ra_colour := 0,
277 si13_pos := '0'B
278}
279
280private template (value) SI3RestOctets ts_SI3RestOctets_def
281modifies ts_SI3RestOctets := {
282 gprs_ind := {
283 presence := CSN1_H,
284 ind := ts_GPRSIndicator_def
285 }
286}
287
288private template (value) SI4RestOctets ts_SI4RestOctets_def
289modifies ts_SI4RestOctets := {
290 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700291 presence := CSN1_H,
292 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700293 }
294}
295
Harald Welte7484fc42018-02-24 14:09:45 +0100296/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100297template (value) SystemInformation ts_SI3_default := {
298 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100299 payload := {
300 si3 := {
301 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100302 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100303 ctrl_chan_desc := {
304 msc_r99 := true,
305 att := true,
306 bs_ag_blks_res := 1,
307 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100308 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100309 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
310 spare := '00'B,
311 bs_pa_mfrms := 0, /* 2 multiframes */
312 t3212 := 1 /* 6 minutes */
313 },
Harald Welte82ccef72018-02-25 16:17:33 +0100314 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100315 dn_ind := false,
316 pwrc := false,
317 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100318 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100319 },
Harald Weltef10153f2018-02-25 16:34:05 +0100320 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100321 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700322 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100323 }
324 }
325}
Harald Welte70767382018-02-21 12:16:40 +0100326
Harald Weltef8df4cb2018-03-10 15:15:08 +0100327template (value) SystemInformation ts_SI2_default := {
328 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100329 payload := {
330 si2 := {
331 bcch_freq_list := '00000000000000000000000000000000'O,
332 ncc_permitted := '11111111'B,
333 rach_control := ts_RachCtrl_default
334 }
335 }
336}
337
Harald Weltef8df4cb2018-03-10 15:15:08 +0100338template (value) SystemInformation ts_SI4_default := {
339 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100340 payload := {
341 si4 := {
342 lai := ts_LAI_default,
343 cell_sel_par := ts_CellSelPar_default,
344 rach_control := ts_RachCtrl_default,
345 cbch_chan_desc := omit,
346 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700347 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100348 }
349 }
350}
351
352function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
353runs on test_CT {
354 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700355 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100356}
357
358function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
359runs on test_CT {
360 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
361 log("Setting ", rsl_si_type, ": ", si_dec);
362 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
363}
364
Harald Welte505cf9b2018-09-15 17:47:23 +0300365friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100366 map(self:BTSVTY, system:BTSVTY);
367 f_vty_set_prompts(BTSVTY);
368 f_vty_transceive(BTSVTY, "enable");
369}
370
Harald Welte505cf9b2018-09-15 17:47:23 +0300371friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200372 map(self:BSCVTY, system:BSCVTY);
373 f_vty_set_prompts(BSCVTY, "OsmoBSC");
374 f_vty_transceive(BSCVTY, "enable");
375}
376
Harald Welte883340c2018-02-28 18:59:29 +0100377/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200378private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
379 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100380 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200381 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
382 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100383 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200384 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100386 }
387}
388
Harald Weltef26de0b2018-04-04 20:28:05 +0200389private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
390 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100391 timer T := 2.0;
392 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100393 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200394 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100395 return;
396 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200397 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100398
399 T.start;
400 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200401 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100402 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100404 }
405 }
406}
407
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700408private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
409 out integer trxc_conn_id) {
410 var Result res;
411
412 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
413 "", -1, -1, { udp := {} }, {});
414 if (not ispresent(res.connId)) {
415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
416 "Could not connect to the control (TRXC) interface " &
417 "of FakeTRX, check your configuration");
418 }
419 trxc_conn_id := res.connId;
420}
421
Harald Welte70767382018-02-21 12:16:40 +0100422/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200423function f_init() runs on test_CT {
424 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100425 g_AllChannels := {
426 /* TS 1..4: TCH/F */
427 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
428 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
429 /* TS 5: TCH/H */
430 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
431 /* TS 0: SDCCH/4 */
432 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
433 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
434 /* TS 6: SDCCH/8 */
435 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
436 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
437 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
438 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
439 };
440
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200441 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700442 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200443 g_AllChanTypes := {
444 /* TS 1..4: TCH/F */
445 valueof(ts_RslChanNr_Bm(1)),
446 /* TS 5: TCH/H */
447 valueof(ts_RslChanNr_Lm(5,1)),
448 /* TS 0: SDCCH/4 */
449 valueof(ts_RslChanNr_SDCCH4(0,2)),
450 /* TS 6: SDCCH/8 */
451 valueof(ts_RslChanNr_SDCCH8(6,4))
452 };
453 } else {
454 g_AllChanTypes := {
455 /* TS 1..4: TCH/F */
456 valueof(ts_RslChanNr_Bm(1)),
457 /* TS 0: SDCCH/4 */
458 valueof(ts_RslChanNr_SDCCH4(0,2)),
459 /* TS 6: SDCCH/8 */
460 valueof(ts_RslChanNr_SDCCH8(6,4))
461 };
462 }
Harald Welte70767382018-02-21 12:16:40 +0100463 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100464 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100465 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200466 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100467
468 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100469 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
470 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
471 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
472 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100473
Harald Weltef26de0b2018-04-04 20:28:05 +0200474 map(self:PCU, system:PCU);
475 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100476
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700477 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100478 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700479
480 /* Init TRXC interface to FakeTRX */
481 map(self:BTS_TRXC, system:BTS_TRXC);
482 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
483
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700484 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700485 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 +0700486 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700487 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
488 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100489 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200490
491 /* Wait some extra time to make sure the BTS emits a stable carrier.
492 * (this is only relevant when running the tests with a physical BTS.) */
493 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100494}
495
Harald Welte68e495b2018-02-25 00:05:57 +0100496/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
497function f_init_l1ctl() runs on test_CT {
498 map(self:L1CTL, system:L1CTL);
499 f_connect_reset(L1CTL);
500}
501
Harald Welte70767382018-02-21 12:16:40 +0100502type function void_fn(charstring id) runs on ConnHdlr;
503
504/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700505function f_start_handler(void_fn fn, ConnHdlrPars pars,
506 boolean pcu_comp := false,
507 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100508runs on test_CT return ConnHdlr {
509 var charstring id := testcasename();
510 var ConnHdlr vc_conn;
511
512 vc_conn := ConnHdlr.create(id);
513 /* connect to RSL Emulation main component */
514 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
515 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700516
517 /* The ConnHdlr component may want to talk to some ports directly,
518 * so we disconnect it from the test_CT and connect it to the component.
519 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200520 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200521 unmap(self:PCU, system:PCU);
522 map(vc_conn:PCU, system:PCU);
523 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700524 if (trxc_comp) {
525 unmap(self:BTS_TRXC, system:BTS_TRXC);
526 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
527 }
Harald Welte70767382018-02-21 12:16:40 +0100528
529 vc_conn.start(f_handler_init(fn, id, pars));
530 return vc_conn;
531}
532
Harald Welte70767382018-02-21 12:16:40 +0100533private altstep as_Tguard() runs on ConnHdlr {
534 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100536 }
537}
538
Harald Welte990a3612019-05-27 14:02:13 +0200539friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
540 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100541}
542
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700543private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100544 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700545 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100546}
547
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700548private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100549 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700550 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100551}
552
553/* first function started in ConnHdlr component */
554private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
555runs on ConnHdlr {
556 g_pars := pars;
557 g_chan_nr := pars.chan_nr;
558
559 map(self:L1CTL, system:L1CTL);
560 f_connect_reset(L1CTL);
561
Harald Welted48c0c72019-06-05 10:01:15 +0200562 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700563 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100564 }
Harald Welte70767382018-02-21 12:16:40 +0100565
566 g_Tguard.start(pars.t_guard);
567 activate(as_Tguard());
568
569 f_rslem_register(0, pars.chan_nr);
570
571 /* call the user-supplied test case function */
572 fn.apply(id);
573}
574
Harald Welteb1726c92018-03-30 11:56:38 +0200575function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
576 boolean ignore_other := false)
577runs on ConnHdlr return RSL_Message {
578 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100579 timer T := 3.0;
580 RSL.send(tx);
581 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100582 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200583 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100584 T.stop;
585 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100586 }
Harald Welte1eba3742018-02-25 12:48:14 +0100587 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100589 }
Harald Welte21240e62018-03-11 21:43:35 +0100590 [not ignore_other] as_l1_sacch();
591 [not ignore_other] as_meas_res();
592 [not ignore_other] as_l1_dcch();
593 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100595 }
Harald Welte21240e62018-03-11 21:43:35 +0100596 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100597 }
Harald Welteb1726c92018-03-30 11:56:38 +0200598 return rx;
599}
600
601function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
602 boolean ignore_other := false)
603runs on ConnHdlr {
604 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100605}
606
Harald Welte8b01c792019-05-19 22:51:25 +0200607function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
608 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
609 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200610 if (encr_enable) {
611 /* append encryption related IEs, if requested */
612 var RSL_IE_EncryptionInfo encr_info;
613 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
614 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
615encr_info})) };
616 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200617 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200618 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100619}
620
Harald Welte70767382018-02-21 12:16:40 +0100621function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100622 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 +0100623 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100624}
625
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700626/* Default Mobile Allocation to be used for frequency hopping */
627private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
628 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
629
Harald Welte2f2b2b72019-05-31 22:24:57 +0200630friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100631 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700632 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100633 float t_guard := 20.0) := {
634 chan_nr := valueof(chan_nr),
635 chan_mode := valueof(chan_mode),
636 t_guard := t_guard,
637 l1_pars := {
638 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100639 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100640 meas_ul := {
641 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200642 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100643 rxqual := 0
644 },
645 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200646 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100647 rxqual := 0
648 }
649 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200650 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100651 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200652 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200653 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100654 },
Harald Weltee613f962018-04-18 22:38:16 +0200655 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200656 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700657 bts0_band := omit,
658 maio_hsn := maio_hsn,
659 ma_map := c_MA_null,
660 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100661}
662
Harald Welte93640c62018-02-25 16:59:33 +0100663/***********************************************************************
664 * Channel Activation / Deactivation
665 ***********************************************************************/
666
Harald Welte70767382018-02-21 12:16:40 +0100667/* Stress test: Do 500 channel activations/deactivations in rapid succession */
668function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
669 for (var integer i := 0; i < 500; i := i+1) {
670 f_rsl_chan_act(g_pars.chan_mode);
671 f_rsl_chan_deact();
672 }
673 setverdict(pass);
674}
675testcase TC_chan_act_stress() runs on test_CT {
676 var ConnHdlr vc_conn;
677 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200678 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100679 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
680 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100682}
683
684/* Test if re-activation of an already active channel fails as expected */
685function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
686 f_rsl_chan_act(g_pars.chan_mode);
687 /* attempt to activate the same lchan again -> expect reject */
688 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
689 alt {
690 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100692 }
693 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
694 setverdict(pass);
695 }
696 }
697 f_rsl_chan_deact();
698}
699testcase TC_chan_act_react() runs on test_CT {
700 var ConnHdlr vc_conn;
701 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100702 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100703 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
704 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100706}
707
708/* Attempt to de-activate a channel that's not active */
709function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
710 timer T := 3.0;
711 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
712 T.start;
713 alt {
714 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
715 setverdict(pass);
716 }
717 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100719 }
720 }
721}
722testcase TC_chan_deact_not_active() runs on test_CT {
723 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100724 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100725 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
726 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100728}
729
730/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
731function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
732 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
733 alt {
734 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100736 }
737 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
738 setverdict(pass);
739 }
740 }
741}
742private type record WrongChanNrCase {
743 RslChannelNr chan_nr,
744 charstring description
745}
746private type record of WrongChanNrCase WrongChanNrCases;
747private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
748 chan_nr := chan_nr,
749 description := desc
750}
751
752testcase TC_chan_act_wrong_nr() runs on test_CT {
753 var ConnHdlr vc_conn;
754 var ConnHdlrPars pars;
755
Harald Welte294b0a22018-03-10 23:26:48 +0100756 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100757
758 var WrongChanNrCases wrong := {
759 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
760 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
761 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
762 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
763 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
764 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
765 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
766 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
767 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
768 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
769 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
770 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
771 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
772 };
773
774 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
775 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
776 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
777 vc_conn.done;
778 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100780}
781
Harald Weltee613f962018-04-18 22:38:16 +0200782/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200783friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200784 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200785 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200786
787 /* test on each of the channels we have */
788 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
789 pars.chan_nr := valueof(g_AllChanTypes[i]);
790
791 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
792 vc_conn := f_start_handler(fn, pars);
793 vc_conn.done;
794 }
795
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200797}
798
Harald Welte93640c62018-02-25 16:59:33 +0100799/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100800 * SACCH handling
801 ***********************************************************************/
802
803private function f_exp_sacch(boolean exp) runs on ConnHdlr {
804 timer T_sacch := 3.0;
805 T_sacch.start;
806 alt {
807 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100809 }
810 [not exp] T_sacch.timeout {
811 setverdict(pass);
812 }
813 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
814 setverdict(pass);
815 }
816 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100818 }
819 [] L1CTL.receive { repeat; }
820 [] RSL.receive { repeat; }
821 }
822}
823
824/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
825private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
826 f_l1_tune(L1CTL);
827 RSL.clear;
828
829 /* activate the logical channel */
830 f_est_dchan();
831 L1CTL.clear;
832
833 /* check that SACCH actually are received as expected */
834 f_exp_sacch(true);
835
836 /* deactivate SACCH on the logical channel */
837 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
838 f_sleep(1.0);
839 L1CTL.clear;
840
841 /* check that no SACCH are received anymore */
842 f_exp_sacch(false);
843
844 /* release the channel */
845 f_rsl_chan_deact();
846 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
847}
848testcase TC_deact_sacch() runs on test_CT {
849 var ConnHdlr vc_conn;
850 var ConnHdlrPars pars;
851 f_init();
852 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
853 //for (var integer i := 0; i < 1; i := i+1) {
854 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
855 log(testcasename(), ": Starting for ", g_AllChannels[i]);
856 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
857 vc_conn.done;
858 }
859 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100861}
862
Harald Welte55700662018-03-12 13:15:43 +0100863/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100864private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
865 var L1ctlDlMessage dl;
866 /* check that the specified SI5 value is actually sent */
867 timer T_sacch := 3.0;
868 L1CTL.clear;
869 T_sacch.start;
870 alt {
871 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
872 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
873 if (match(l3, l3_exp)) {
874 setverdict(pass);
875 } else {
876 repeat;
877 }
878 }
879 [] L1CTL.receive { repeat; }
880 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100882 }
883 }
884}
885
Harald Welte55700662018-03-12 13:15:43 +0100886/* verify that given SACCH payload is not present */
887private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
888 var L1ctlDlMessage dl;
889 /* check that the specified SI5 value is actually sent */
890 timer T_sacch := 3.0;
891 L1CTL.clear;
892 T_sacch.start;
893 alt {
894 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
895 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
896 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100898 } else {
899 repeat;
900 }
901 }
902 [] L1CTL.receive { repeat; }
903 [] T_sacch.timeout {
904 setverdict(pass);
905 }
906 }
907}
908
Harald Welte629cc6b2018-03-11 17:19:05 +0100909/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100910private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
911 /* Set a known default SACCH filling for SI5 */
912 var octetstring si5 := f_rnd_octstring(19);
913 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
914
915 f_l1_tune(L1CTL);
916 RSL.clear;
917
918 /* activate the logical channel */
919 f_est_dchan();
920
921 /* check that the specified SI5 value is actually sent */
922 f_sacch_present(si5);
923
924 /* release the channel */
925 RSL.clear;
926 f_rsl_chan_deact();
927 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
928}
929testcase TC_sacch_filling() runs on test_CT {
930 var ConnHdlr vc_conn;
931 var ConnHdlrPars pars;
932 f_init();
933 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
934 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
935 log(testcasename(), ": Starting for ", g_AllChannels[i]);
936 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
937 vc_conn.done;
938 }
939 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100941}
942
Harald Welte629cc6b2018-03-11 17:19:05 +0100943/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100944private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
945 /* Set a known default SACCH filling for SI5 */
946 var octetstring si5 := f_rnd_octstring(19);
947 var octetstring si5_diff := f_rnd_octstring(19);
948 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
949
950 f_l1_tune(L1CTL);
951 RSL.clear;
952
953 log("Activating channel, expecting standard SI5");
954 /* activate the logical channel */
955 f_est_dchan();
956 /* check that the specified SI5 value is actually sent */
957 f_sacch_present(si5);
958
959 /* set channel-specific different SI5 */
960 log("Setting channel specific SACCH INFO, expecting it");
961 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
962 /* check that the specified lchan-specific value is now used */
963 f_sacch_present(si5_diff);
964
965 /* deactivate the channel and re-activate it, this should result in default SI5 */
966 log("De-activating and re-activating channel, expecting standard SI5");
967 f_rsl_chan_deact();
968 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
969 /* Verify that the TRX-wide default SACCH filling is present again */
970 f_sacch_present(si5);
971
972 /* release the channel */
973 RSL.clear;
974 f_rsl_chan_deact();
975 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
976}
977testcase TC_sacch_info_mod() runs on test_CT {
978 var ConnHdlr vc_conn;
979 var ConnHdlrPars pars;
980 f_init();
981 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
982 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
983 log(testcasename(), ": Starting for ", g_AllChannels[i]);
984 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
985 vc_conn.done;
986 }
987 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100989}
990
Harald Welte075d84c2018-03-12 13:07:24 +0100991/* Test SACCH scheduling of multiple different SI message types */
992private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
993 var octetstring si5 := f_rnd_octstring(19);
994 var octetstring si5bis := f_rnd_octstring(19);
995 var octetstring si5ter := f_rnd_octstring(19);
996 var octetstring si6 := f_rnd_octstring(19);
997
998 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
999 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1000 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1001 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1002
1003 f_l1_tune(L1CTL);
1004 RSL.clear;
1005
1006 /* activate the logical channel */
1007 f_est_dchan();
1008 L1CTL.clear;
1009
1010 /* check that SACCH actually are received as expected */
1011 f_sacch_present(si5);
1012 f_sacch_present(si5bis);
1013 f_sacch_present(si5ter);
1014 f_sacch_present(si6);
1015
1016 /* release the channel */
1017 f_rsl_chan_deact();
1018 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1019}
1020testcase TC_sacch_multi() runs on test_CT {
1021 var ConnHdlr vc_conn;
1022 var ConnHdlrPars pars;
1023 f_init();
1024 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1025 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1026 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1027 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1028 vc_conn.done;
1029 }
1030 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001032}
1033
Harald Welte55700662018-03-12 13:15:43 +01001034/* Test if SACH information is modified as expected */
1035private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1036 var octetstring si5 := f_rnd_octstring(19);
1037 var octetstring si6 := f_rnd_octstring(19);
1038
1039 /* First, configure both SI5 and SI6 to be transmitted */
1040 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1041 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1042
1043 f_l1_tune(L1CTL);
1044 RSL.clear;
1045
1046 /* activate the logical channel */
1047 f_est_dchan();
1048 L1CTL.clear;
1049
1050 /* check that SACCH actually are received as expected */
1051 f_sacch_present(si5);
1052 f_sacch_present(si6);
1053
1054 /* disable SI6 */
1055 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1056
1057 /* check that SI5 is still transmitted */
1058 f_sacch_present(si5);
1059 /* check if SI6 is now gone */
1060 f_sacch_missing(si6);
1061
1062 /* release the channel */
1063 f_rsl_chan_deact();
1064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1065}
1066testcase TC_sacch_multi_chg() runs on test_CT {
1067 var ConnHdlr vc_conn;
1068 var ConnHdlrPars pars;
1069 f_init();
1070 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1071 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1072 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1073 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1074 vc_conn.done;
1075 }
1076 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001078}
1079
Harald Weltec8d363c2019-05-19 20:36:48 +02001080/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1081private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1082 var octetstring si5 := f_rnd_octstring(19);
1083 var octetstring si6 := f_rnd_octstring(19);
1084 var octetstring si5_specific := f_rnd_octstring(19);
1085 var octetstring si6_specific := f_rnd_octstring(19);
1086
1087 /* First, configure both SI5 and SI6 to be transmitted */
1088 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1089 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1090
1091 f_l1_tune(L1CTL);
1092 RSL.clear;
1093
1094 /* activate channel with different SACCH filling */
1095 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1096 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1097 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1098 }));
1099 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1100 RSL_IE_Body:{sacch_info := sacch_info})) };
1101 f_est_dchan(more_ies := addl_ies);
1102
1103 /* check that SACCH actually are received as expected */
1104 f_sacch_present(si5_specific);
1105 f_sacch_present(si6_specific);
1106
1107 /* release the channel */
1108 f_rsl_chan_deact();
1109 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1110}
1111testcase TC_sacch_chan_act() runs on test_CT {
1112 var ConnHdlr vc_conn;
1113 var ConnHdlrPars pars;
1114 f_init();
1115
1116 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1117 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1118 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1119 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1120 vc_conn.done;
1121 }
1122 /* TODO: do the above in parallel, rather than sequentially? */
1123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1124}
1125
Harald Welte8b01c792019-05-19 22:51:25 +02001126/* verify that SACCH DL transmission is started only if MS power IE present
1127 * see section 4.1.3 of 3GPP TS 48.058 */
1128private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1129 var octetstring si5 := f_rnd_octstring(19);
1130
1131 f_l1_tune(L1CTL);
1132 RSL.clear;
1133
1134 /* Step 1: Activate ASYNC HO channel without MS power IE */
1135
1136 /* Activate channel on BTS side */
1137 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1138 /* don't perform immediate assignment here, as we're testing non-IA case */
1139 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001140 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001141
1142 /* Verify that no DL SACCH is being received */
1143 f_sacch_missing(?);
1144
1145 f_rsl_chan_deact();
1146 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1147
1148
1149 /* Step 2: Activate ASYNC HO channel with MS power IE */
1150
1151 /* Activate channel on BTS side */
1152 var RSL_IE_List addl_ies := {
1153 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1154 };
1155 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1156 /* don't perform immediate assignment here, as we're testing non-IA case */
1157 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001158 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001159
1160 /* Verify that DL SACCH is being received */
1161 f_sacch_present(si5);
1162
1163 f_rsl_chan_deact();
1164 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1165}
1166testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1167 var ConnHdlr vc_conn;
1168 var ConnHdlrPars pars;
1169 f_init();
1170
1171 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1172 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1173 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1174 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1175 vc_conn.done;
1176 }
1177 /* TODO: do the above in parallel, rather than sequentially? */
1178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1179}
1180
1181/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1182 * see section 4.1.4 of 3GPP TS 48.058 */
1183private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1184 var octetstring si5 := f_rnd_octstring(19);
1185 var RSL_IE_List addl_ies;
1186
1187 f_l1_tune(L1CTL);
1188 RSL.clear;
1189
1190 /* Step 1: Activate SYNC HO channel without MS power IE */
1191
1192 /* Activate channel on BTS side */
1193 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1194 /* don't perform immediate assignment here, as we're testing non-IA case */
1195 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001196 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001197
1198 /* Verify that no DL SACCH is being received */
1199 f_sacch_missing(?);
1200
1201 f_rsl_chan_deact();
1202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1203
1204
1205 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1206
1207 /* Activate channel on BTS side */
1208 addl_ies := {
1209 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1210 };
1211 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1212 /* don't perform immediate assignment here, as we're testing non-IA case */
1213 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001214 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001215
1216 /* Verify that no DL SACCH is being received */
1217 f_sacch_missing(?);
1218
1219 f_rsl_chan_deact();
1220 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1221
1222
1223 /* Step 2b: Activate SYNC HO channel with TA IE */
1224
1225 /* Activate channel on BTS side */
1226 addl_ies := {
1227 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1228 };
1229 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1230 /* don't perform immediate assignment here, as we're testing non-IA case */
1231 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001232 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001233
1234 /* Verify that no DL SACCH is being received */
1235 f_sacch_missing(?);
1236
1237 f_rsl_chan_deact();
1238 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1239
1240
1241 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1242
1243 /* Activate channel on BTS side */
1244 addl_ies := {
1245 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1246 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1247 };
1248 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1249 /* don't perform immediate assignment here, as we're testing non-IA case */
1250 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001251 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001252
1253 /* Verify that DL SACCH is being received */
1254 f_sacch_present(si5);
1255
1256 f_rsl_chan_deact();
1257 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1258}
1259testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1260 var ConnHdlr vc_conn;
1261 var ConnHdlrPars pars;
1262 f_init();
1263
1264 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1265 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1266 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1267 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1268 vc_conn.done;
1269 }
1270 /* TODO: do the above in parallel, rather than sequentially? */
1271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1272}
Harald Welte629cc6b2018-03-11 17:19:05 +01001273
1274
1275/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001276 * RACH Handling
1277 ***********************************************************************/
1278
Harald Welte8c24c2b2018-02-26 08:31:31 +01001279/* like L1SAP_IS_PACKET_RACH */
1280private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001281 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001282 return true;
1283 }
1284 return false;
1285}
1286
1287/* generate a random RACH for circuit-switched */
1288private function f_rnd_ra_cs() return OCT1 {
1289 var OCT1 ra;
1290 do {
1291 ra := f_rnd_octstring(1);
1292 } while (ra_is_ps(ra));
1293 return ra;
1294}
1295
Harald Welte883340c2018-02-28 18:59:29 +01001296/* generate a random RACH for packet-switched */
1297private function f_rnd_ra_ps() return OCT1 {
1298 var OCT1 ra;
1299 do {
1300 ra := f_rnd_octstring(1);
1301 } while (not ra_is_ps(ra));
1302 return ra;
1303}
1304
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001305/* generate a random 11-bit RA (packet-switched only) */
1306private function f_rnd_ra11_ps() return BIT11 {
1307 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1308 return int2bit(ra11, 11);
1309}
1310
Harald Welte8c24c2b2018-02-26 08:31:31 +01001311/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1312testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001313 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001314 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001315 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001316
Harald Welte8c24c2b2018-02-26 08:31:31 +01001317 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001318 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001319 for (var integer i := 0; i < 1000; i := i+1) {
1320 var OCT1 ra := f_rnd_ra_cs();
1321 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1322 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001324 }
1325 fn_last := fn;
1326
1327 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001328 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001329 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001330 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001331 T.stop;
1332 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001333 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001335 }
1336 [] RSL_CCHAN.receive { repeat; }
1337 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001338 test_failed := true;
1339 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001340 }
1341 }
1342 }
Maxba06feb2019-03-05 10:52:46 +01001343 if (test_failed) {
1344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001345 }
Maxba06feb2019-03-05 10:52:46 +01001346 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001348}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001349
1350/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1351testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001352 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001353 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001354 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001355 f_l1_tune(L1CTL);
1356
1357 var GsmFrameNumber fn_last := 0;
1358 for (var integer i := 0; i < 1000; i := i+1) {
1359 var OCT1 ra := f_rnd_ra_cs();
1360 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1361 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001363 }
1364 fn_last := fn;
1365 }
1366 var integer rsl_chrqd := 0;
1367 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001368 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001369 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001370 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001371 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001372 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001373 repeat;
1374 }
1375 [] RSL_CCHAN.receive { repeat; }
1376 [] T.timeout { }
1377 }
1378 if (rsl_chrqd == 1000) {
1379 setverdict(pass);
1380 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001382 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001384}
1385
Harald Welte3453ab42019-05-24 21:19:58 +02001386private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1387 var charstring bts_str := "bts " & int2str(bts_nr);
1388 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1389}
1390
1391/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1392private template integer tr_rach_slots_per_interval := (90 .. 130);
1393
1394/* Expect 0 RACH load on an idle BTS that has just started up */
1395testcase TC_rach_load_idle_thresh0() runs on test_CT {
1396 var ASP_RSL_Unitdata rx_ud;
1397
1398 f_init_vty_bsc();
1399 /* send load indications even at 0% load */
1400 f_vty_load_ind_thresh(0);
1401 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1402 f_sleep(2.0);
1403
1404 f_init();
1405
1406 timer T := 5.0;
1407 T.start;
1408 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001409 [] 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 +02001410 setverdict(pass);
1411 repeat;
1412 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001413 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001414 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1415 repeat;
1416 }
1417 [] RSL_CCHAN.receive {
1418 repeat;
1419 }
1420 [] T.timeout { }
1421 }
1422
1423 f_vty_load_ind_thresh(10);
1424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1425}
1426
1427/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1428testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1429 var ASP_RSL_Unitdata rx_ud;
1430
1431 f_init_vty_bsc();
1432 f_init();
1433
1434 timer T := 5.0;
1435 T.start;
1436 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001437 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001438 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1439 repeat;
1440 }
1441 [] RSL_CCHAN.receive {
1442 repeat;
1443 }
1444 [] T.timeout {
1445 setverdict(pass);
1446 }
1447 }
1448
1449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1450}
1451
1452/* Expect 0 RACH load on an idle BTS that has just started up */
1453testcase TC_rach_load_count() runs on test_CT {
1454 var ASP_RSL_Unitdata rx_ud;
1455 var integer load_access_count := 0;
1456
1457 f_init_vty_bsc();
1458 /* send load indications even at 0% load */
1459 f_vty_load_ind_thresh(0);
1460 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1461 f_sleep(2.0);
1462 f_init();
1463
1464 f_init_l1ctl();
1465 f_sleep(1.0);
1466 f_l1_tune(L1CTL);
1467
1468 var GsmFrameNumber fn_last := 0;
1469 for (var integer i := 0; i < 1000; i := i+1) {
1470 var OCT1 ra := f_rnd_ra_cs();
1471 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1472 if (fn == fn_last) {
1473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1474 }
1475 fn_last := fn;
1476 }
1477
1478 timer T := 5.0;
1479 T.start;
1480 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001481 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001482 -> value rx_ud {
1483 var RSL_IE_Body ie;
1484 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1485 load_access_count := load_access_count + ie.rach_load.access_count;
1486 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1487 setverdict(fail, "Access count cannot be < Busy count");
1488 }
1489 repeat;
1490 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001491 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001492 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1493 repeat;
1494 }
1495 [] RSL_CCHAN.receive {
1496 repeat;
1497 }
1498 [] T.timeout { }
1499 }
1500 if (load_access_count == 1000) {
1501 setverdict(pass);
1502 } else {
1503 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1504 }
1505
1506 f_vty_load_ind_thresh(10);
1507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1508}
1509
Harald Welte54a2a2d2018-02-26 09:14:05 +01001510private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001511 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001512 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001513 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001514 f_sleep(0.5);
1515
1516 /* Transmit RACH request + wait for confirmation */
1517 var OCT1 ra := f_rnd_ra_cs();
1518 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1519
1520 /* Check for expected result */
1521 timer T := 1.5;
1522 T.start;
1523 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001524 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001525 setverdict(pass);
1526 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001527 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001529 }
1530 [] RSL_CCHAN.receive { repeat; }
1531 [not expect_pass] T.timeout {
1532 setverdict(pass);
1533 }
1534 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001536 }
1537 }
1538}
1539
1540/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1541testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001542 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001543 f_init_l1ctl();
1544 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001545 f_sleep(1.0);
1546
1547 /* default max-ta is 63 (full range of GSM timing advance */
1548
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001549 /* We allow early arrival up to 2 symbols */
1550 f_rach_toffs(-1*256, true);
1551 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001552 f_rach_toffs(-10*256, false);
1553
1554 /* 0 / 32 / 63 bits is legal / permitted */
1555 f_rach_toffs(0, true);
1556 f_rach_toffs(32*256, true);
1557 f_rach_toffs(63*256, true);
1558
1559 /* more than 63 bits is not legal / permitted */
1560 f_rach_toffs(64*256, false);
1561 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001563}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001564
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001565function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1566 var GsmFrameNumber fn;
1567 var RSL_Message rm;
1568
1569 f_l1_tune(L1CTL);
1570 RSL.clear;
1571
1572 /* Generate a random Handover Reference */
1573 var integer ho_ref := oct2int(f_rnd_octstring(1));
1574
1575 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1576 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1577 RSL_IE_Body:{ handover_ref := ho_ref }));
1578
1579 /* Activate a channel on the BTS side (no encryption) */
1580 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1581 act_type := t_RSL_IE_ActType_HO_SYNC);
1582
1583 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1584 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001585 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001586
1587 /* Send handover Access Burst */
1588 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1589
1590 /* TODO: test mismatching Handover Reference, and missing IE */
1591
1592 /* Wait for handover detection */
1593 timer T := 3.0;
1594 T.start;
1595 alt {
1596 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1597 log("Handover RACH has been detected: ", rm);
1598 setverdict(pass);
1599 }
1600 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1602 log2str("RSL_CHAN_RQD was not expected: ", rm));
1603 }
1604 [] RSL.receive { repeat; }
1605 [] T.timeout {
1606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1607 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1608 }
1609 }
1610
1611 /* Release the channel */
1612 f_rsl_chan_deact();
1613 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1614}
1615
1616/* Test handover RACH detection */
1617testcase TC_ho_rach() runs on test_CT {
1618 var ConnHdlrPars pars;
1619 var ConnHdlr vc_conn;
1620
1621 f_init();
1622
1623 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1624 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1625 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1626 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1627 vc_conn.done;
1628 }
1629
1630 /* TODO: do the above in parallel, rather than sequentially? */
1631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1632}
1633
Harald Welte93640c62018-02-25 16:59:33 +01001634/***********************************************************************
1635 * Measurement Processing / Reporting
1636 ***********************************************************************/
1637
Harald Welte70767382018-02-21 12:16:40 +01001638template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1639 spare := '0'B,
1640 lpd := 0,
1641 sapi := sapi,
1642 c_r := c_r,
1643 ea := true
1644}
1645
Harald Welted879bd92018-03-12 15:01:23 +01001646template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001647 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001648 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001649 len := 0, /* overwritten */
1650 m := false,
1651 el := 1,
1652 payload := pl
1653}
1654
1655/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1656altstep as_l1_sacch() runs on ConnHdlr {
1657 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001658 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001659 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001660 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 +01001661 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001662 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001663
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001664 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1665 g_pars.l1_pars.ms_power_level, false,
1666 g_pars.l1_pars.ms_actual_ta);
1667
1668 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1669 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1670
1671 log("Sending Measurement Report: ", l1h, l2);
1672 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001673 repeat;
1674 }
1675}
1676
1677altstep as_l1_dcch() runs on ConnHdlr {
1678 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001679 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001680 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1681 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001682 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1683 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001684 repeat;
1685 }
1686}
1687
1688type record MeasElem {
1689 uint6_t rxlev,
1690 uint3_t rxqual
1691}
1692
1693type record MeasElemFS {
1694 MeasElem full,
1695 MeasElem sub
1696}
1697
1698type record ConnL1Pars {
1699 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001700 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001701 MeasElemFS meas_ul,
1702 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001703 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001704 uint5_t ms_power_level,
1705 uint8_t ms_actual_ta
1706}
1707
1708/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1709private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1710 return 63 + (toffs256s/256);
1711}
1712
Harald Welted5684392018-03-10 18:22:04 +01001713private function f_max(integer a, integer b) return integer {
1714 if (a > b) {
1715 return a;
1716 } else {
1717 return b;
1718 }
1719}
1720
1721private function f_min(integer a, integer b) return integer {
1722 if (a < b) {
1723 return a;
1724 } else {
1725 return b;
1726 }
1727}
1728
1729/* compute negative tolerance val-tolerance, ensure >= min */
1730private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1731 val := val - tolerance;
1732 return f_max(val, min);
1733}
1734
1735/* compute positive tolerance val+tolerance, ensure <= max */
1736private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1737 val := val + tolerance;
1738 return f_min(val, max);
1739}
1740
1741/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1742private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1743return template integer {
1744 var template integer ret;
1745 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1746 return ret;
1747}
1748
1749
Harald Welte70767382018-02-21 12:16:40 +01001750/* build a template for matching measurement results against */
1751private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1752 var ConnL1Pars l1p := g_pars.l1_pars;
1753 var template RSL_IE_UplinkMeas ul_meas := {
1754 len := 3,
1755 rfu := '0'B,
1756 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001757 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001758 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001759 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001760 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001761 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1762 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001763 supp_meas_info := omit
1764 };
Harald Welte685d5982018-02-27 20:42:05 +01001765 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001766 ul_meas.len := (3+8);
1767 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001768 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001769 toa256_min := ?,
1770 toa256_max := ?,
1771 toa256_std_dev := ?
1772 }
Harald Welte685d5982018-02-27 20:42:05 +01001773 }
Harald Welte70767382018-02-21 12:16:40 +01001774 var template RSL_IE_BS_Power bs_power := {
1775 reserved := 0,
1776 epc := false,
1777 fpc := false,
1778 power_level := l1p.bs_power_level
1779 };
1780 var template RSL_IE_L1Info l1_info := {
1781 ms_power_lvl := l1p.ms_power_level,
1782 fpc := false,
1783 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001784 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001785 };
1786 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001787 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001788 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1789 ?, t_toffs);
1790}
1791
Philipp Maierdd841d32019-12-17 14:44:54 +01001792/* build a template for matching measurement results that do not contain any
1793 * MS related measurement (l1_info, l3_info and ms timing offset). */
1794private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1795 var ConnL1Pars l1p := g_pars.l1_pars;
1796 var template RSL_IE_UplinkMeas ul_meas := {
1797 len := 3,
1798 rfu := '0'B,
1799 dtx_d := l1p.dtx_enabled,
1800 rxlev_f_u := ?,
1801 reserved1 := '00'B,
1802 rxlev_s_u := ?,
1803 reserved2 := '00'B,
1804 rxq_f_u := ?,
1805 rxq_s_u := ?,
1806 supp_meas_info := omit
1807 };
1808 if (l1p.toa256_enabled) {
1809 ul_meas.len := (3+8);
1810 ul_meas.supp_meas_info := {
1811 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1812 toa256_min := ?,
1813 toa256_max := ?,
1814 toa256_std_dev := ?
1815 }
1816 }
1817 var template RSL_IE_BS_Power bs_power := {
1818 reserved := 0,
1819 epc := false,
1820 fpc := false,
1821 power_level := l1p.bs_power_level
1822 };
1823
1824 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1825}
1826
Harald Welte70767382018-02-21 12:16:40 +01001827/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001828altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001829 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001830 var boolean chan_est := false;
1831
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001832 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001833
1834 /* Receive osmocom specific measurement reports. This is the normal
1835 * case. Here we verify that the measurement reports we sent are
1836 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001837 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1838 /* increment counter of next to-be-expected meas rep */
1839 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1840 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001841 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001842
1843 /* The following two cases may only happen in the beginning
1844 * of the channel establishment phase. Once we have received
1845 * the "our" measurement report the first time, the channel
1846 * is established and empty or hardcoded TRXCON reports must
1847 * not occur anymore. */
1848 chan_est := true;
1849
1850 repeat;
1851 }
1852
1853 /* When the BTS has established the channel, the MS might need slightly
1854 * more time to establish the channel and actually start sending. The
1855 * result is then a measurement report that just lacks the measurement
1856 * information of the MS. This is normal and we tolerate this behavior. */
1857 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1858 /* increment counter of next to-be-expected meas rep */
1859 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1860 /* Re-start the timer expecting the next MEAS RES */
1861 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001862 repeat;
1863 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001864
1865 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1866 * measurements if the TTCN3 side does not supply measurement input in
1867 * time. In those cases TRXCON will either use a cached measurement
1868 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1869 * report the templates above will not match. We tolerate this
1870 * behavior, but only once. */
1871 [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 +01001872 /* increment counter of next to-be-expected meas rep */
1873 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1874 if (g_first_meas_res) {
1875 g_first_meas_res := false;
1876 repeat;
1877 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001879 }
Harald Welte70767382018-02-21 12:16:40 +01001880 }
1881 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001883 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001884 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001886 }
1887}
1888
Harald Weltee613f962018-04-18 22:38:16 +02001889private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1890 select (rsl_alg_id) {
1891 case (RSL_ALG_ID_A5_0) { return 0; }
1892 case (RSL_ALG_ID_A5_1) { return 1; }
1893 case (RSL_ALG_ID_A5_2) { return 2; }
1894 case (RSL_ALG_ID_A5_3) { return 3; }
1895 case (RSL_ALG_ID_A5_4) { return 4; }
1896 case (RSL_ALG_ID_A5_5) { return 5; }
1897 case (RSL_ALG_ID_A5_6) { return 6; }
1898 case (RSL_ALG_ID_A5_7) { return 7; }
1899 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1901 /* Make compiler happy by calling mtc.stop here. It is already
1902 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001903 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001904 }
1905 }
1906}
1907
1908private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1909 select (rsl_alg_id) {
1910 case (RSL_ALG_ID_A5_1) { return '000'B; }
1911 case (RSL_ALG_ID_A5_2) { return '001'B; }
1912 case (RSL_ALG_ID_A5_3) { return '010'B; }
1913 case (RSL_ALG_ID_A5_4) { return '011'B; }
1914 case (RSL_ALG_ID_A5_5) { return '100'B; }
1915 case (RSL_ALG_ID_A5_6) { return '101'B; }
1916 case (RSL_ALG_ID_A5_7) { return '110'B; }
1917 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1919 /* Make compiler happy by calling mtc.stop here. It is already
1920 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001921 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001922 }
1923 }
1924}
1925
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001926/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1927private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1928 var GsmFrameNumber fn;
1929 timer T := 8.0;
1930
1931 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1932 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1933
1934 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1935 /* Send the actual RACH */
1936 fn := f_L1CTL_RACH(L1CTL, ra);
1937
1938 T.start;
1939 alt {
1940 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1941 [] T.timeout {
1942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1943 }
1944 }
1945 T.stop
1946 return fn;
1947}
Harald Weltee613f962018-04-18 22:38:16 +02001948
Harald Welte70767382018-02-21 12:16:40 +01001949/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001950private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001951 var GsmFrameNumber fn;
1952 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001953 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001954 var integer ra := 23;
1955
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001956 /* Send RACH request and wait for ChanReq */
1957 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001958
1959 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001960 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001961
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001962 /* Craft channel description (with or without frequency hopping parameters) */
1963 if (ispresent(g_pars.maio_hsn)) {
1964 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1965 } else {
1966 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1967 }
1968
Harald Welte70767382018-02-21 12:16:40 +01001969 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001970 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001971 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1972
1973 /* receive IMM.ASS on MS side */
1974 var ImmediateAssignment ia_um;
1975 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001976
1977 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1978 if (ch_desc.h != ia_um.chan_desc.h) {
1979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1980 }
1981
Harald Welte70767382018-02-21 12:16:40 +01001982 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001983 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001984 /* enable encryption, if requested */
1985 if (encr_enable) {
1986 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1987 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1988 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001989
1990 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001991}
1992
1993/* establish DChan, verify existance + contents of measurement reports */
1994function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001995 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001996 RSL.clear;
1997
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001998 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001999 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002000 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002001 }
Harald Welte70767382018-02-21 12:16:40 +01002002
2003 f_est_dchan();
2004
2005 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2006 * RSL measurement reports on Abis side */
2007 timer T := 8.0;
2008 T.start;
2009 alt {
2010 [] as_l1_sacch();
2011 [] as_meas_res();
2012 [] as_l1_dcch();
2013 [] L1CTL.receive { repeat; }
2014 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002015 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002016 * of any earlier errors, so if we reach this timeout, we're good */
2017 setverdict(pass);
2018 }
2019 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002021 }
2022 }
2023 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002024 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002025}
Harald Welte0472ab42018-03-12 15:02:26 +01002026
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002027/* Verify Tx power reduction and ramping up during BTS bring up */
2028function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
2029 var L1ctlDlMessage l1_dl;
2030 f_l1_tune(L1CTL);
2031 RSL.clear;
2032
2033 var integer initial_rx_lvl := -1;
2034 var integer last_rx_lvl := -1;
2035 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2036
2037 timer T := 2.0;
2038 alt {
2039 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2040 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2041 log("Received rx_level=", rx_lvl);
2042 if (initial_rx_lvl == -1) {
2043 initial_rx_lvl := rx_lvl;
2044 last_rx_lvl := rx_lvl;
2045
2046 /* Expect a somehow low value during first received messages */
2047 if (initial_rx_lvl >= max_rx_lvl / 2) {
2048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2049 log2str("Detected high initial tx power during ramp up: ",
2050 initial_rx_lvl , ", full power is", max_rx_lvl));
2051 }
2052 }
2053
2054 /* received Rx level bigger than maximum allowed power by CN */
2055 if (rx_lvl > max_rx_lvl) {
2056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2057 log2str("Detected Tx power higher than full power: ",
2058 rx_lvl , " > ", max_rx_lvl));
2059 }
2060
2061 /* Make sure it never decreases, since we are rumping up */
2062 if (last_rx_lvl > rx_lvl) {
2063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2064 log2str("Detected Tx power decrease during ramp up: ",
2065 last_rx_lvl , " -> ", rx_lvl));
2066 }
2067
2068 if (rx_lvl == max_rx_lvl and not T.running) {
2069 /* We reached the maximum power, start timer and receive
2070 /* a few more to make sure we don't surpass it */
2071 log("Reached full power, wating a bit more until success");
2072 T.start;
2073 }
2074
2075 last_rx_lvl := rx_lvl;
2076 repeat;
2077 }
2078 [] L1CTL.receive { repeat; }
2079 [] T.timeout { }
2080 }
2081
2082 /* We didn't increase tx power during ramp up */
2083 if (initial_rx_lvl < last_rx_lvl) {
2084 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2085 } else {
2086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2087 log2str("No Tx power increase during whole ramp up: ",
2088 initial_rx_lvl , " -> ", last_rx_lvl));
2089 }
2090
2091 setverdict(pass);
2092}
2093testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2094 var ConnHdlr vc_conn;
2095 var ConnHdlrPars pars;
2096 f_init();
2097 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2098 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2099 pcu_comp := false, trxc_comp := true);
2100 vc_conn.done;
2101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2102}
2103
Eric Wildae8f2622019-06-18 17:05:11 +02002104function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
2105 timer T := 8.0;
2106 T.start;
2107 var RSL_Message rsl;
2108 alt {
2109 [] as_l1_sacch();
2110 [] L1CTL.receive { repeat; }
2111 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2112 if (rsl.ies[3].body.bs_power.power_level == level) {
2113 setverdict(pass)
2114 } else {
2115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2116 }
2117 }
2118 [] T.timeout {
2119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2120 }
2121 }
2122}
2123
2124/* see if the rsl meas res contains our expeced bs power level
2125bs power set during assignment */
2126function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2127 f_l1_tune(L1CTL);
2128 RSL.clear;
2129
2130 if (mp_bts_trxc_port != -1) {
2131 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2132 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2133 }
2134
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002135 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002136 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2137 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2138
2139 f_est_dchan(more_ies :={valueof(pwr)});
2140
2141 f_check_meas_bs_power_level(pwr_var);
2142
2143 f_rsl_chan_deact();
2144 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2145}
2146
2147/* see if the rsl meas res contains our expeced bs power level
2148bs power set after assignment */
2149function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2150 f_l1_tune(L1CTL);
2151 RSL.clear;
2152
2153 if (mp_bts_trxc_port != -1) {
2154 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2155 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2156 }
2157
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002158 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002159 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2160
2161 f_est_dchan();
2162
2163 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2164
2165 f_check_meas_bs_power_level(pwr_var);
2166
2167 f_rsl_chan_deact();
2168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2169}
2170
2171testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2172 var ConnHdlr vc_conn;
2173 var ConnHdlrPars pars;
2174 f_init();
2175 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2176 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2177 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2178 pcu_comp := false, trxc_comp := true);
2179 vc_conn.done;
2180 }
2181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2182}
2183
2184testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2185 var ConnHdlr vc_conn;
2186 var ConnHdlrPars pars;
2187 f_init();
2188 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2189 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2190 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2191 pcu_comp := false, trxc_comp := true);
2192 vc_conn.done;
2193 }
2194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2195}
2196
Eric Wild61edb7e2019-06-03 12:38:31 +02002197/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2198second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2199These power levels are valid for all bands and require no special handling */
2200function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2201 var uint5_t pwr_var := 7;
2202 var L1ctlDlMessage l1_dl;
2203
2204 f_trxc_fake_rssi(rxlev2dbm(10));
2205 f_l1_tune(L1CTL);
2206 RSL.clear;
2207
2208 var RSL_IE_List addl_ies;
2209 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2210
2211 addl_ies := {
2212 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2213 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2214 };
2215
2216 /* establish with power parameters */
2217 f_est_dchan(more_ies := addl_ies);
2218
2219 /* set a high value to ensure L1 power control level increases */
2220 f_trxc_fake_rssi(rxlev2dbm(20));
2221
2222 timer T2 := 6.0;
2223 T2.start;
2224 alt {
2225 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002226 /* Update sent MS power to follow what BTS requests */
2227 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2228 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002229 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002230 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002231 T2.stop;
2232 }
2233 [] L1CTL.receive { repeat; }
2234 [] T2.timeout {
2235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2236 "Power Level in L1 header has not increased sufficiently");
2237 }
2238 }
2239
2240 /* set a low value to ensure L1 power control level decreases */
2241 f_trxc_fake_rssi(rxlev2dbm(0));
2242
2243 timer T4 := 6.0;
2244 T4.start;
2245 alt {
2246 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002247 /* Update sent MS power to follow what BTS requests */
2248 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2249 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002250 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002251 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002252 T4.stop;
2253 setverdict(pass, "Power level in L1 decreased/increased as expected");
2254 }
2255 [] L1CTL.receive { repeat; }
2256 [] T4.timeout {
2257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2258 "Power Level in L1 header has not decreased sufficiently");
2259 }
2260 }
2261
2262 f_rsl_chan_deact();
2263 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2264
2265}
2266
2267/* check that we do not exceed the max power */
2268function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2269 var uint5_t pwr_var := 7;
2270 var L1ctlDlMessage l1_dl;
2271
2272 /* set a low value to ensure power increases */
2273 f_trxc_fake_rssi(rxlev2dbm(10));
2274 f_l1_tune(L1CTL);
2275 RSL.clear;
2276
2277 var RSL_IE_List addl_ies;
2278 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2279
2280 addl_ies := {
2281 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2282 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2283 };
2284
2285 /* establish with power parameters */
2286 f_est_dchan(more_ies := addl_ies);
2287
2288 timer T1 := 10.0;
2289 T1.start;
2290 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002291 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2292 /* Update sent MS power to follow what BTS requests */
2293 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2294 repeat;
2295 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002296 [] L1CTL.receive { repeat; }
2297 [] T1.timeout {
2298 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2299 setverdict(fail, "Power level in L1 header should not have changed");
2300 }
2301 }
2302 }
2303
2304 f_rsl_chan_deact();
2305 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2306
2307}
2308
2309/* see if we reach the band max power */
2310function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2311 var L1ctlDlMessage l1_dl;
2312 var uint5_t pwr_var := 15;
2313 var uint5_t pwr_max_var := f_get_max_power_from_band();
2314
2315 /* set a low value to ensure power increases */
2316 f_trxc_fake_rssi(rxlev2dbm(10));
2317 f_l1_tune(L1CTL);
2318 RSL.clear;
2319
2320 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2321 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2322
2323 /* establish with fixed power level */
2324 f_est_dchan(more_ies :={valueof(pwr)});
2325
2326 /* check our initial power level */
2327 f_wait_for_l1_power_level(pwr_var);
2328
2329 /* update power param to enable power loop
2330 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2331 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2332
2333 /* wait, then check that our power level was reduced */
2334 timer T1 := 10.0;
2335 T1.start;
2336 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002337 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2338 /* Update sent MS power to follow what BTS requests */
2339 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2340 repeat;
2341 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002342 [] L1CTL.receive { repeat; }
2343 [] T1.timeout {
2344 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2345 if( f_power_level_is_highest_dbm(rcv) ){
2346 setverdict(pass, "Power level in L1 header reduced as expected");
2347 } else {
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2349 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2350 }
2351 }
2352 }
2353
2354 f_rsl_chan_deact();
2355 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2356
2357}
2358
2359/* see if we reach the band min power */
2360function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2361 var L1ctlDlMessage l1_dl;
2362
2363 /* set a high value to ensure power decreases */
2364 f_trxc_fake_rssi(rxlev2dbm(50));
2365 f_l1_tune(L1CTL);
2366 RSL.clear;
2367
2368 var uint5_t pwr_var := 5;
2369 var uint5_t pwr_target_val := 15;
2370
2371 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2372 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2373
2374 /* establish with fixed power level */
2375 f_est_dchan(more_ies :={valueof(pwr)});
2376
2377 /* check our initial power level */
2378 f_wait_for_l1_power_level(pwr_var);
2379
2380 /* update power param to enable power loop
2381 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002382 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002383
2384 /* wait, then check that our power level was increased */
2385 timer T1 := 10.0;
2386 T1.start;
2387 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002388 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2389 /* Update sent MS power to follow what BTS requests */
2390 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2391 repeat;
2392 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002393 [] L1CTL.receive { repeat; }
2394 [] T1.timeout {
2395 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2396 setverdict(pass, "Power level in L1 header increased to lowest power value");
2397 } else {
2398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2399 "Power level in L1 header NOT increased to lowest power value");
2400 }
2401 }
2402 }
2403
2404 f_rsl_chan_deact();
2405 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2406
2407}
2408
Eric Wild095024b2019-06-17 15:08:57 +02002409/* see if we change the power level without receiving power parameters, which should not happen
2410rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002411function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2412 var L1ctlDlMessage l1_dl;
2413
2414 /* set a high value to ensure power decreases */
2415 f_trxc_fake_rssi(rxlev2dbm(50));
2416 f_l1_tune(L1CTL);
2417 RSL.clear;
2418
2419 var uint5_t pwr_var := 5;
2420
2421 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2422 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2423
2424 /* establish with fixed power level */
2425 f_est_dchan(more_ies :={valueof(pwr)});
2426
2427 /* check our initial power level */
2428 f_wait_for_l1_power_level(pwr_var);
2429
2430 /* wait, then check that our power level did not change */
2431 timer T1 := 10.0;
2432 T1.start;
2433 alt {
2434 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2435 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2437 "BS power control should not be active unless we receive a power parameters IE!");
2438 }
2439 repeat;
2440 }
2441 [] L1CTL.receive { repeat; }
2442 [] T1.timeout { setverdict(pass); }
2443 }
2444
2445 f_rsl_chan_deact();
2446 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2447
2448}
2449
Eric Wild095024b2019-06-17 15:08:57 +02002450/* see if we change the power level without receiving power parameters, which should not happen
2451ms power control WITHOUT power parameters */
2452function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2453 var L1ctlDlMessage l1_dl;
2454
2455 /* set a high value to ensure power decreases */
2456 f_trxc_fake_rssi(rxlev2dbm(50));
2457 f_l1_tune(L1CTL);
2458 RSL.clear;
2459
2460 var uint5_t pwr_var := 5;
2461
2462 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2463 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2464
2465 /* establish with fixed power level */
2466 f_est_dchan(more_ies :={valueof(pwr)});
2467
2468 /* check our initial power level */
2469 f_wait_for_l1_power_level(pwr_var);
2470
2471 /* pwr control without power params IE, should NOT activate MS power control*/
2472 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2473
2474 /* wait, then check that our power level did not change */
2475 timer T1 := 10.0;
2476 T1.start;
2477 alt {
2478 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2479 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2481 "BS power control should not be active unless we receive a power parameters IE!");
2482 }
2483 repeat;
2484 }
2485 [] L1CTL.receive { repeat; }
2486 [] T1.timeout { setverdict(pass); }
2487 }
2488
2489 f_rsl_chan_deact();
2490 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2491
2492}
2493
Eric Wild61edb7e2019-06-03 12:38:31 +02002494function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2495 var L1ctlDlMessage l1_dl;
2496 timer T0 := 10.0;
2497 T0.start;
2498 alt {
2499 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2500 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2502 "Power level in L1 header != signaled (RSL) power level.");
2503 }
2504 }
2505 [] L1CTL.receive { repeat; }
2506 [] T0.timeout {
2507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2508 "Timeout waiting for initial power level");
2509 }
2510 }
2511 T0.stop;
2512}
2513
2514private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2515 var IntegerRecord min_dbm_level;
2516 var IntegerRecord max_dbm_level;
2517 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2518
2519 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2520 if (min_dbm_level[i] == level) {
2521 return true;
2522 }
2523 }
2524 return false;
2525}
2526
2527private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2528 var IntegerRecord min_dbm_level;
2529 var IntegerRecord max_dbm_level;
2530 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2531
2532 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2533 if (max_dbm_level[i] == level) {
2534 return true;
2535 }
2536 }
2537 return false;
2538}
2539
2540private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2541 var IntegerRecord min_dbm_level;
2542 var IntegerRecord max_dbm_level;
2543 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2544 return max_dbm_level[0];
2545}
2546
2547type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2548template charstring BtsBand_allGSM:= pattern "GSM???";
2549private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2550 // 45.005 4.1.1
2551 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2552 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2553 2, 1, 0};
2554 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2555 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2556 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2557 var IntegerRecord rv;
2558
2559 select(band){
2560 case (BtsBand_allGSM){
2561 rv := gsm_power;
2562 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2563 max_dbm_level := {2, 1, 0};
2564 }
2565 case("DCS1800"){
2566 rv := dcs_power;
2567 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2568 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2569 }
2570 case("PCS1900"){
2571 rv := pcs_power;
2572 min_dbm_level := {15};
2573 max_dbm_level := {30};
2574 }
2575 }
2576
2577 return rv;
2578}
2579
2580private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2581 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2582}
2583
2584testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2585 var ConnHdlr vc_conn;
2586 var ConnHdlrPars pars;
2587 f_init();
2588 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2589 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2590 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2591 pars.bts0_band := f_vty_get_bts0_band();
2592 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2593 vc_conn.done;
2594 }
2595 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2597}
2598
2599testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2600 var ConnHdlr vc_conn;
2601 var ConnHdlrPars pars;
2602 f_init();
2603 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2604 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2605 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2606 pars.bts0_band := f_vty_get_bts0_band();
2607 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2608 vc_conn.done;
2609 }
2610 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2612}
2613
2614testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2615 var ConnHdlr vc_conn;
2616 var ConnHdlrPars pars;
2617 f_init();
2618 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2619 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2620 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2621 pars.bts0_band := f_vty_get_bts0_band();
2622 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2623 vc_conn.done;
2624 }
2625 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2627}
2628
2629testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2630 var ConnHdlr vc_conn;
2631 var ConnHdlrPars pars;
2632 f_init();
2633 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2634 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2635 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2636 pars.bts0_band := f_vty_get_bts0_band();
2637 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2638 vc_conn.done;
2639 }
2640 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2642}
2643
Eric Wild280ccb82019-06-17 11:11:52 +02002644testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2645 var ConnHdlr vc_conn;
2646 var ConnHdlrPars pars;
2647 f_init();
2648 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2649 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2650 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2651 pars.bts0_band := f_vty_get_bts0_band();
2652 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2653 vc_conn.done;
2654 }
2655 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2657}
2658
Eric Wild095024b2019-06-17 15:08:57 +02002659testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2660 var ConnHdlr vc_conn;
2661 var ConnHdlrPars pars;
2662 f_init();
2663 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2664 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2665 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2666 pars.bts0_band := f_vty_get_bts0_band();
2667 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2668 vc_conn.done;
2669 }
2670 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2672}
2673
Harald Welte70767382018-02-21 12:16:40 +01002674testcase TC_meas_res_sign_tchf() runs on test_CT {
2675 var ConnHdlr vc_conn;
2676 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002677 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002678 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2679 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002680 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2681 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002682 vc_conn.done;
2683 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002685}
2686testcase TC_meas_res_sign_tchh() runs on test_CT {
2687 var ConnHdlr vc_conn;
2688 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002689 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002690 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2691 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002692 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2693 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002694 vc_conn.done;
2695 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002697}
2698testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2699 var ConnHdlr vc_conn;
2700 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002701 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002702 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2703 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002704 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2705 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002706 vc_conn.done;
2707 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002709}
2710testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2711 var ConnHdlr vc_conn;
2712 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002713 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002714 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2715 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002716 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2717 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002718 vc_conn.done;
2719 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002721}
Harald Welte685d5982018-02-27 20:42:05 +01002722testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2723 var ConnHdlr vc_conn;
2724 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002725 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002726 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2727 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2728 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2729 pars.l1_pars.toa256_enabled := true;
2730 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2731 vc_conn.done;
2732 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002734}
2735
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002736/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2737 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2738function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2739 var L1ctlDlMessage l1_dl;
2740 var RSL_IE_MS_Power ms_power;
2741 var RSL_Message rsl;
2742 var uint5_t power_level := 0;
2743
2744 f_l1_tune(L1CTL);
2745 RSL.clear;
2746
2747 f_est_dchan();
2748
2749 ms_power.reserved := 0;
2750 ms_power.fpc_epc := false;
2751
2752 /* Send the first power control command. This will disable any BTS/TRX
2753 * internal power control and switch the MS (which is not in scope of
2754 * this test) to a constant power level. We start with a power level
2755 * of 0 */
2756 ms_power.power_level := power_level;
2757 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2758 RSL.send(rsl);
2759
2760 alt {
2761
2762 /* Pick all SACCH blocks for checking */
2763 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2764
2765 /* The first byte of the L1 header contains the power level.
2766 * The reserved bits and the fpc bit is set to 0, so we may
2767 * compare directly. */
2768 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2769 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2770 }
2771
2772 /* Signal a new power level via RSL for the next turn. */
2773 if (power_level < 31) {
2774 power_level := power_level + 1;
2775 ms_power.power_level := power_level;
2776 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2777 RSL.send(rsl);
2778 repeat;
2779 }
2780
2781 }
2782
2783 /* Ignore all other blocks */
2784 [] L1CTL.receive { repeat; }
2785
2786 }
2787
2788 f_rsl_chan_deact();
2789 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2790
2791 setverdict(pass);
2792}
2793
2794testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2795 var ConnHdlr vc_conn;
2796 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002797 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002798
2799 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2800 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2801 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2802 vc_conn.done;
2803 }
2804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2805}
Harald Welte70767382018-02-21 12:16:40 +01002806
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002807/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002808TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2809function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2810 var L1ctlDlMessage l1_dl;
2811 var uint5_t ta_to_test := 16;
2812
2813
2814 f_l1_tune(L1CTL);
2815 RSL.clear;
2816
2817 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002818 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002819
2820 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2821
2822
2823 alt {
2824
2825 /* Pick all SACCH blocks for checking */
2826 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2827
2828 /* The second byte of the L1 header contains the TA. */
2829 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2830 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2831 }
2832
2833 }
2834
2835 /* Ignore all other blocks */
2836 [] L1CTL.receive { repeat; }
2837
2838 }
2839
2840 f_rsl_chan_deact();
2841 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2842
2843 setverdict(pass);
2844}
2845
2846testcase TC_rsl_chan_initial_ta() runs on test_CT {
2847 var ConnHdlr vc_conn;
2848 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002849 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002850 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002851 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2852 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002853 vc_conn.done;
2854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2855}
2856
Eric Wilde57e1a62019-05-28 13:30:55 +02002857/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2858function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2859 var L1ctlDlMessage l1_dl;
2860 var uint5_t ms_power_level := 7;
2861
2862 var RSL_IE_MS_Power ms_power;
2863 ms_power.reserved := 0;
2864 ms_power.fpc_epc := false;
2865 ms_power.power_level := ms_power_level;
2866
2867 f_l1_tune(L1CTL);
2868 RSL.clear;
2869
2870 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2871
2872 timer T := 1.0;
2873 T.start;
2874 alt {
2875 /* Pick all SACCH blocks for checking */
2876 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2877 /* The first byte of the L1 header contains the power level.. */
2878 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2879 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2880 }
2881 }
2882 /* Ignore all other blocks */
2883 [] L1CTL.receive { repeat; }
2884 [] T.timeout {
2885 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2886 }
2887 }
2888
2889 f_rsl_chan_deact();
2890 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2891 setverdict(pass);
2892}
2893
2894testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2895 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2896 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2897}
2898
Harald Welte0472ab42018-03-12 15:02:26 +01002899/* 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 +01002900private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002901 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002902 RSL.clear;
2903
2904 f_est_dchan();
2905 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002906 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002907
2908 timer T := 40.0;
2909 T.start;
2910 alt {
2911 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2912 setverdict(pass)
2913 }
2914 [] RSL.receive { repeat };
2915 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002917 }
2918 }
2919 f_rsl_chan_deact();
2920}
2921testcase TC_conn_fail_crit() runs on test_CT {
2922 var ConnHdlr vc_conn;
2923 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002924 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002925 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2926 pars.t_guard := 60.0;
2927 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2928 vc_conn.done;
2929}
2930
Harald Welte93640c62018-02-25 16:59:33 +01002931/***********************************************************************
2932 * Paging
2933 ***********************************************************************/
2934
Harald Welte68e495b2018-02-25 00:05:57 +01002935function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2936 if (tmsi == 'FFFFFFFF'O) {
2937 return true;
2938 } else {
2939 return false;
2940 }
2941}
Harald Welte70767382018-02-21 12:16:40 +01002942
Philipp Maier82cb0b12018-08-31 14:41:39 +02002943type record allowedFn { integer frame_nr }
2944template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2945template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2946template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2947template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2948template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2949template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2950template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2951template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2952function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2953{
2954 var integer frame_nr_51;
2955 frame_nr_51 := frame_nr mod 51
2956
2957 var allowedFn fn_check;
2958 fn_check.frame_nr := frame_nr_51;
2959
2960 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002962 return;
2963 }
2964
2965 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2966 return;
2967 }
2968 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2969 return;
2970 }
2971 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2972 return;
2973 }
2974 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2975 return;
2976 }
2977 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2978 return;
2979 }
2980 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2981 return;
2982 }
2983 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2984 return;
2985 }
2986 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2987 return;
2988 }
2989
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002991 return;
2992}
2993
2994altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids, PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01002995runs on test_CT {
2996 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002997 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002998 repeat;
2999 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003000 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003001 var octetstring without_plen :=
3002 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3003 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003004
3005 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3006
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003007 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3008 /* Ignore empty RR Paging Request (PCH filling) messages.
3009 * TODO: does it make sense to count them? */
3010 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003011 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3012 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003013 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003014 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3015 }
3016 } else if (match(rr, tr_PAGING_REQ2)) {
3017 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3018 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3019 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3020 }
3021 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3022 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3023 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003024 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003025 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3026 }
3027 } else if (match(rr, tr_PAGING_REQ3)) {
3028 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3029 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3030 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3031 }
3032 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3033 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3034 }
3035 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3036 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3037 }
3038 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3039 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3040 }
3041 }
3042 repeat;
3043 }
3044}
3045
3046type record PagingTestCfg {
3047 boolean combined_ccch,
3048 integer bs_ag_blks_res,
3049 float load_factor,
3050 boolean exp_load_ind,
3051 boolean exp_overload,
3052 boolean use_tmsi
3053}
3054
3055type record PagingTestState {
3056 integer num_paging_sent,
3057 integer num_paging_rcv_msgs,
3058 integer num_paging_rcv_ids,
3059 integer num_overload
3060}
3061
Harald Welte68e495b2018-02-25 00:05:57 +01003062/* Helper function for paging related testing */
3063private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003064 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003065 f_init_l1ctl();
3066 f_l1_tune(L1CTL);
3067
3068 var PagingTestState st := {
3069 num_paging_sent := 0,
3070 num_paging_rcv_msgs := 0,
3071 num_paging_rcv_ids := 0,
3072 num_overload := 0
3073 };
3074
3075 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3076 var float max_pch_imsi_per_sec;
3077 if (cfg.use_tmsi) {
3078 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3079 } else {
3080 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3081 }
3082 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3083 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003084 var float time_total := 20.0;
3085 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3086 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003087
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003088 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3089 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003090
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003091 timer T_itv := 0.0;
3092 T_itv.start;
3093 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003094 alt {
3095 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003096 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003097 st.num_overload := st.num_overload + 1;
3098 repeat;
3099 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003100 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003102 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003103 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003104 log("Rx LOAD_IND");
3105 /* FIXME: analyze/verify interval + contents */
3106 repeat;
3107 }
3108 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003109 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003110 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003111 [] T_itv.timeout {
3112 /* Send paging cmds based on elapsed time */
3113 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3114 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003115 var MobileIdentityV mi;
3116
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003117 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003118 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003119 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003120 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003121 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003122 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003123
3124 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003125 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 +02003126
3127 st.num_paging_sent := st.num_paging_sent + 1;
3128 }
3129 if (st.num_paging_sent < pkt_total) {
3130 /* Wait for interval to next PAGING COMMAND */
3131 var float time_now := T_total.read;
3132 var float next_sched := int2float(st.num_paging_sent)*interval;
3133 if (next_sched > time_now) {
3134 T_itv.start(next_sched - time_now);
3135 } else {
3136 T_itv.start(0.0);
3137 }
3138 } else {
3139 /* We are done, no need to keep counting */
3140 T_total.stop;
3141 }
3142 }
3143 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003144 }
3145 }
3146
3147 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3148 timer T_wait := 18.0;
3149 T_wait.start;
3150 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003151 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003152 [] L1CTL.receive { repeat; }
3153 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003154 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3155 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003156 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003158 }
Harald Welte68e495b2018-02-25 00:05:57 +01003159 }
3160
3161 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3162 " rcvd_ids=", st.num_paging_rcv_ids);
3163 return st;
3164}
3165
3166/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3167 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3168 * - that CCCH LOAD IND (PCH) are being generated
3169 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3170testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003171 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003172 var PagingTestCfg cfg := {
3173 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003174 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003175 load_factor := 0.8,
3176 exp_load_ind := true,
3177 exp_overload := false,
3178 use_tmsi := false
3179 };
3180 var PagingTestState st := f_TC_paging(cfg);
3181 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3183 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003184 } else {
3185 setverdict(pass);
3186 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003188}
3189
3190/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3191 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3192 * - that CCCH LOAD IND (PCH) are being generated
3193 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3194testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003195 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003196 var PagingTestCfg cfg := {
3197 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003198 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003199 load_factor := 0.8,
3200 exp_load_ind := true,
3201 exp_overload := false,
3202 use_tmsi := true
3203 };
3204 var PagingTestState st := f_TC_paging(cfg);
3205 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3207 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003208 } else {
3209 setverdict(pass);
3210 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003212}
3213
3214/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3215 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3216 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3217 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3218testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003219 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003220 var PagingTestCfg cfg := {
3221 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003222 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003223 load_factor := 2.0,
3224 exp_load_ind := true,
3225 exp_overload := true,
3226 use_tmsi := false
3227 };
3228 var PagingTestState st := f_TC_paging(cfg);
3229 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3230 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003231 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003232 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003233 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 +01003234 } else {
3235 setverdict(pass);
3236 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003238}
3239
3240/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3241 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3242 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3243 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3244testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003245 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003246 var PagingTestCfg cfg := {
3247 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003248 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003249 load_factor := 2.0,
3250 exp_load_ind := true,
3251 exp_overload := true,
3252 use_tmsi := true
3253 };
3254 var PagingTestState st := f_TC_paging(cfg);
3255 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3256 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003257 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003258 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003259 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 +01003260 } else {
3261 setverdict(pass);
3262 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003264}
3265
3266
Harald Welte93640c62018-02-25 16:59:33 +01003267/***********************************************************************
3268 * Immediate Assignment / AGCH
3269 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003270private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003271 len := 0,
3272 ma := ''B
3273}
Harald Welte93640c62018-02-25 16:59:33 +01003274
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003275template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
Vadim Yanitskiye9f68be2020-05-27 02:08:35 +07003276 uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003277 chan_nr := chan_nr,
3278 tsc := tsc,
3279 h := false,
3280 arfcn := arfcn,
3281 maio_hsn := omit
3282}
3283
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003284template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3285 template (value) MaioHsn maio_hsn) := {
3286 chan_nr := chan_nr,
3287 tsc := tsc,
3288 h := true,
3289 arfcn := omit,
3290 maio_hsn := maio_hsn
3291}
3292
Harald Weltee8d750e2018-06-10 21:41:35 +02003293private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3294 return int2str(num_tx) & " sent, "
3295 & int2str(num_rx) & " received, "
3296 & int2str(num_del) & " deleted";
3297}
3298
3299private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3300 var L1ctlDlMessage l1_dl;
3301 timer T := 10.0;
3302 var integer num_tx := 0;
3303 var integer num_rx := 0;
3304 var integer num_del := 0;
3305 var charstring res_str;
3306 var float rx_ratio;
3307
Harald Welte10474062019-05-30 16:48:17 +02003308 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003309 f_init_l1ctl();
3310 f_l1_tune(L1CTL);
3311
3312 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003313 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003314 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3315 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003316 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003317 num_tx := num_tx+1;
3318 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003319 }
3320 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003321 T.start;
3322 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003323 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003324 num_del := num_del+1;
3325 repeat;
3326 }
3327 [] RSL_CCHAN.receive {
3328 repeat;
3329 }
3330 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3331 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3332 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3333 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3334 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003335 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003336 } else {
3337 num_rx := num_rx+1;
3338 }
3339 repeat;
3340 }
3341 [] L1CTL.receive { repeat; }
3342 [] T.timeout { }
3343 }
3344 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3345 log("AGCH test: " & res_str);
3346 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003348 }
3349 rx_ratio := int2float(num_rx) / int2float(num_tx);
3350 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003351 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 +02003352 } else {
3353 setverdict(pass);
3354 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003356}
3357
Harald Weltee8d750e2018-06-10 21:41:35 +02003358/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3359testcase TC_imm_ass_1000_20ms() runs on test_CT {
3360 f_TC_imm_ass(1000, 0.02, 0.25);
3361}
3362
3363/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3364testcase TC_imm_ass_200_0ms() runs on test_CT {
3365 f_TC_imm_ass(200, 0.0, 0.05);
3366}
3367
3368/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3369testcase TC_imm_ass_200_76ms() runs on test_CT {
3370 f_TC_imm_ass(150, 0.076, 1.00);
3371}
3372
3373
3374
Harald Welte48494ca2018-02-25 16:59:50 +01003375/***********************************************************************
3376 * BCCH
3377 ***********************************************************************/
3378
3379/* tuple of Frame Number + decoded SI */
3380type record SystemInformationFn {
3381 GsmFrameNumber frame_number,
3382 SystemInformation si
3383}
3384
3385/* an arbitrary-length vector of decoded SI + gsmtap header */
3386type record of SystemInformationFn SystemInformationVector;
3387
3388/* an array of SI-vectors indexed by TC value */
3389type SystemInformationVector SystemInformationVectorPerTc[8];
3390
3391/* determine if a given SI vector contains given SI type at least once */
3392function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3393 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3394 var integer fn_mod51 := arr[i].frame_number mod 51;
3395 if (not bcch_ext and fn_mod51 == 2 or
3396 bcch_ext and fn_mod51 == 6) {
3397 if (arr[i].si.header.message_type == key) {
3398 return true;
3399 }
3400 }
3401 }
3402 return false;
3403}
3404
3405/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3406function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3407 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003409 }
3410}
3411
3412/* check if a given SI vector contains given SI type at least once on any TC */
3413function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3414 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3415 if (f_si_vecslot_contains(arr[tc], key) or
3416 f_si_vecslot_contains(arr[tc], key, true)) {
3417 return true;
3418 }
3419 }
3420 return false;
3421}
3422
3423/* determine if a given SI vector contains given SI type at least N of M times */
3424function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3425 var integer count := 0;
3426 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003428 }
3429 for (var integer i:= 0; i < m; i := i + 1) {
3430 var integer fn_mod51 := arr[i].frame_number mod 51;
3431 if (not bcch_ext and fn_mod51 == 2 or
3432 bcch_ext and fn_mod51 == 6) {
3433 if (arr[i].si.header.message_type == key) {
3434 count := count + 1;
3435 }
3436 }
3437 }
3438 if (count >= n) {
3439 return true;
3440 } else {
3441 return false;
3442 }
3443}
3444
3445/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3446function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3447 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003449 }
3450}
3451
3452/* determine if a given SI vector contains given SI type at least once */
3453function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3454 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3455 var integer fn_mod51 := arr[i].frame_number mod 51;
3456 if (not bcch_ext and fn_mod51 == 2 or
3457 bcch_ext and fn_mod51 == 6) {
3458 if (arr[i].si.header.message_type != key) {
3459 return false;
3460 }
3461 }
3462 }
3463 return true;
3464}
3465
3466/* ensure a given TC slot of the SI vector contains only given SI type */
3467function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3468 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003470 }
3471}
3472
3473/* SI configuration of cell, against which we validate actual SI messages */
3474type set SystemInformationConfig {
3475 boolean bcch_extended,
3476 boolean si1_present,
3477 boolean si2bis_present,
3478 boolean si2ter_present,
3479 boolean si2quater_present,
3480 boolean si7_present,
3481 boolean si8_present,
3482 boolean si9_present,
3483 boolean si13_present,
3484 boolean si13alt_present,
3485 boolean si15_present,
3486 boolean si16_present,
3487 boolean si17_present,
3488 boolean si2n_present,
3489 boolean si21_present,
3490 boolean si22_present
3491}
3492
3493/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3494function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3495 var integer i;
3496 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3497 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003499 }
3500 }
3501 if (cfg.si1_present) {
3502 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3503 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3504 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3505 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3506 /* make sure *ALL* contain SI1 */
3507 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3508 }
3509 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3510 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3511 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3512 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3513 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3514 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3515
3516 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3517 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3518 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3519 * consecutive occurrences of TC = 4. */
3520 if (cfg.si2bis_present and not cfg.si2ter_present) {
3521 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3522 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3523 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3524 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3525 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3526 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3527 }
3528
3529 if (cfg.si7_present or cfg.si8_present) {
3530 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3531 * if System Information type 4 does not contain all information needed for cell
3532 * selection and reselection. */
3533 if (not cfg.bcch_extended) {
3534 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3535 }
3536 if (cfg.si7_present) {
3537 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3538 }
3539 if (cfg.si8_present) {
3540 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3541 }
3542 }
3543
3544 if (cfg.si2quater_present) {
3545 /* iii) System information type 2 quater is sent if needed, as determined by the system
3546 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3547 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3548 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3549 * within any of 4 consecutive occurrences of TC = 5. */
3550 if (not (cfg.bcch_extended)) {
3551 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3552 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3553 } else {
3554 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3555 }
3556 } else {
3557 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3558 }
3559 }
3560 if (cfg.si9_present) {
3561 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3562 * in system information type 3 as defined in 3GPP TS 44.018. */
3563 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3564 }
3565 if (cfg.si13_present) {
3566 /* vii) System Information type 13 is only related to the GPRS service. System Information
3567 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3568 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3569 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3570 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3571 * within any of 4 consecutive occurrences of TC=4. */
3572 if (not cfg.bcch_extended) {
3573 log("not-bccch-extended");
3574 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3575 } else {
3576 log("bccch-extended");
3577 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3578 }
3579 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003581 }
3582 }
3583 if (cfg.si16_present or cfg.si17_present) {
3584 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3585 * should not be sent in a cell where network sharing is used (see rule xv). */
3586 if (cfg.si22_present) {
3587 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3588 }
3589 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003591 }
3592 if (not cfg.bcch_extended) {
3593 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3594 }
3595 if (cfg.si16_present) {
3596 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3597 }
3598 if (cfg.si17_present) {
3599 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3600 }
3601 }
3602
3603 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3604 * broadcast information. The frequency with which they are sent is determined by the
3605 * system operator. System Information type 9 identifies the scheduling of System
3606 * Information type 18 and 20 messages. */
3607
3608 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3609 * Information Type 19 is present, then its scheduling shall be indicated in System
3610 * Information Type 9. */
3611
3612 if (cfg.si15_present) {
3613 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3614 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3615 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3616 * 4 consecutive occurrences of TC = 1. */
3617 if (not cfg.bcch_extended) {
3618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3619 } else {
3620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3621 }
3622 }
3623 if (cfg.si13alt_present) {
3624 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3625 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3626 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3627 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3628 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3629 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3630 * of TC = 4. */
3631 if (cfg.si13_present) {
3632 testcase.stop("Error: Cannot have SI13alt and SI13");
3633 }
3634 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003636 }
3637 if (not cfg.bcch_extended) {
3638 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3639 } else {
3640 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3641 }
3642 }
3643 if (cfg.si2n_present) {
3644 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3645 * as determined by the system operator. In the case that the message is sent on the
3646 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3647 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3648 * consecutive occurrences of TC = 4. */
3649 if (not cfg.bcch_extended) {
3650 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3651 } else {
3652 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3653 }
3654 }
3655 if (cfg.si21_present) {
3656 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3657 * determined by the system operator. If Extended Access Barring is in use in the cell
3658 * then this message is sent at least once within any of 4 consecutive occurrences of
3659 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3660 * cell then this message shall only be sent on BCCH Ext. */
3661 if (not cfg.bcch_extended) {
3662 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3663 } else {
3664 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3665 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003667 }
3668 }
3669 }
3670 if (cfg.si22_present) {
3671 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3672 * should not be sent in a cell where SoLSA is used (see rule viii). System
3673 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3674 * =2 and TC=6. */
3675 if (cfg.si16_present or cfg.si17_present) {
3676 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3677 }
3678 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3679 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003681 }
3682 if (not cfg.bcch_extended) {
3683 testcase.stop("Error: SI22 requires BCCH Extd!");
3684 } else {
3685 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3686 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3687 }
3688 }
3689}
3690
3691/* sample Systme Information for specified duration via L1CTL */
3692function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3693 timer T := duration;
3694 var SystemInformationVectorPerTc si_per_tc;
3695 var L1ctlDlMessage l1_dl;
3696
3697 /* initialize all per-TC vectors empty */
3698 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3699 si_per_tc[i] := {};
3700 }
3701
3702 /* flush all previous L1 queued msgs */
3703 pt.clear;
3704
3705 T.start;
3706 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003707 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003708 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3709 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3710 log("Ignoring non-RR SI ", l1_dl);
3711 repeat;
3712 }
3713 var SystemInformationFn sig := {
3714 frame_number := l1_dl.dl_info.frame_nr,
3715 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3716 }
3717 var integer tc := f_gsm_compute_tc(sig.frame_number);
3718 log("SI received at TC=", tc, ": ", sig.si);
3719 /* append to the per-TC bucket */
3720 si_per_tc[tc] := si_per_tc[tc] & { sig };
3721 repeat;
3722 }
3723 [] pt.receive { repeat; }
3724 [] T.timeout { }
3725 }
3726
3727 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3728 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3729 }
3730 log("si_per_tc=", si_per_tc);
3731 return si_per_tc;
3732}
3733
3734/* helper function: Set given SI via RSL + validate scheduling.
3735 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3736function f_TC_si_sched() runs on test_CT {
3737 var SystemInformationVectorPerTc si_per_tc;
3738 f_init_l1ctl();
3739 f_l1_tune(L1CTL);
3740
3741 /* Sample + Validate Scheduling */
3742 si_per_tc := f_l1_sample_si(L1CTL);
3743 f_validate_si_scheduling(si_cfg, si_per_tc);
3744
3745 setverdict(pass);
3746}
3747
3748testcase TC_si_sched_default() runs on test_CT {
3749 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003750 /* 2+3+4 are mandatory and set in f_init() */
3751 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003753}
3754
3755testcase TC_si_sched_1() runs on test_CT {
3756 f_init();
3757 si_cfg.si1_present := true;
3758 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003759 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003761}
3762
3763testcase TC_si_sched_2bis() runs on test_CT {
3764 f_init();
3765 si_cfg.si2bis_present := true;
3766 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3767 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003769}
3770
3771testcase TC_si_sched_2ter() runs on test_CT {
3772 f_init();
3773 si_cfg.si2ter_present := true;
3774 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3775 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003777}
3778
3779testcase TC_si_sched_2ter_2bis() runs on test_CT {
3780 f_init();
3781 si_cfg.si2bis_present := true;
3782 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3783 si_cfg.si2ter_present := true;
3784 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3785 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003787}
3788
3789testcase TC_si_sched_2quater() runs on test_CT {
3790 f_init();
3791 si_cfg.si2quater_present := true;
3792 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3793 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003795}
3796
3797testcase TC_si_sched_13() runs on test_CT {
3798 f_init();
3799 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003800 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003801 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003803}
3804
3805testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3806 f_init();
3807 si_cfg.si2bis_present := true;
3808 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3809 si_cfg.si2ter_present := true;
3810 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3811 si_cfg.si2quater_present := true;
3812 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3813 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003814 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003815 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003817}
3818
3819
Harald Welte68e495b2018-02-25 00:05:57 +01003820testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003821 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003822 /* FIXME: enable / disable individual BCCH info */
3823 //ts_RSL_BCCH_INFO(si_type, info);
3824 /* expect no ERROR REPORT after either of them *
3825 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003827}
3828
Harald Welte93640c62018-02-25 16:59:33 +01003829/***********************************************************************
3830 * Low-Level Protocol Errors / ERROR REPORT
3831 ***********************************************************************/
3832
Harald Welte01d982c2018-02-25 01:31:40 +01003833private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3834 timer T := 5.0;
3835 T.start;
3836 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003837 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01003838 setverdict(pass);
3839 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003840 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003842 }
3843 [] RSL_CCHAN.receive {
3844 repeat;
3845 }
3846 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003848 }
3849 }
3850}
3851
3852/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3853testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003854 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003855 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3856 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003857 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003858
3859 f_exp_err_rep(RSL_ERR_PROTO);
3860}
3861
3862/* Provoke a mandatory IE error and match on ERROR REPORT */
3863testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003864 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003865
3866 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3867 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003868 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003869
3870 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3871}
3872
3873/* Provoke an IE content error and match on ERROR REPORT */
3874testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003875 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003876 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3877 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003878 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003879
3880 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3881}
3882
Harald Welteee25aae2019-05-19 14:32:37 +02003883/* attempt to activate channel with wrong RSL Message Discriminator IE */
3884function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3885 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3886 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3887 RSL.send(rsl);
3888 f_rslem_unregister(0, g_chan_nr);
3889}
3890testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3891 var ConnHdlr vc_conn;
3892 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3893
Harald Welte10474062019-05-30 16:48:17 +02003894 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003895
3896 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3897 vc_conn.done;
3898 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3899
3900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3901}
3902
3903/* Send messages with wrong message type */
3904function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3905 var template (value) RSL_Message rsl_tx;
3906 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3907 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3908 RSL.send(rsl_tx);
3909 f_rslem_unregister(0, g_chan_nr);
3910}
3911function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3912 var template (value) RSL_Message rsl_tx;
3913 /* we first have to activate the dedicated channel */
3914 f_rsl_chan_act(g_pars.chan_mode);
3915 /* ... to then send an invalid RLL message */
3916 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3917 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3918 RSL.send(rsl_tx);
3919 f_rslem_unregister(0, g_chan_nr);
3920}
3921testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3922 var ConnHdlr vc_conn;
3923 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3924 var template (value) RSL_Message rsl_tx;
3925
Harald Welte10474062019-05-30 16:48:17 +02003926 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003927
3928 /* Common Channel with wrong message type */
3929 RSL_CCHAN.clear;
3930 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3931 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003932 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003933 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3934
3935 /* TRX Management */
3936 RSL_CCHAN.clear;
3937 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3938 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003939 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003940 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3941
3942 /* Dedicated Channel */
3943 RSL_CCHAN.clear;
3944 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3945 vc_conn.done;
3946 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3947
3948 /* RLL */
3949 RSL_CCHAN.clear;
3950 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3951 vc_conn.done;
3952 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3953}
3954
3955/* Send messages in wrong sequence (RLL to an inactive lchan) */
3956function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3957 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3958 f_rslem_unregister(0, g_chan_nr);
3959}
3960testcase TC_err_rep_wrong_sequence() runs on test_CT {
3961 var ConnHdlr vc_conn;
3962 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3963
Harald Welte10474062019-05-30 16:48:17 +02003964 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003965
3966 RSL_CCHAN.clear;
3967 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3968 vc_conn.done;
3969 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3970}
3971
Harald Welte93640c62018-02-25 16:59:33 +01003972/***********************************************************************
3973 * IPA CRCX/MDCX/DLCS media stream handling
3974 ***********************************************************************/
3975
Harald Weltea871a382018-02-25 02:03:14 +01003976/* Send IPA DLCX to inactive lchan */
3977function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003978 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3979 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003980}
3981testcase TC_ipa_dlcx_not_active() runs on test_CT {
3982 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003983 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003984 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3985 vc_conn.done;
3986}
Harald Welte68e495b2018-02-25 00:05:57 +01003987
Harald Weltea3f1df92018-02-25 12:49:55 +01003988/* Send IPA CRCX twice to inactive lchan */
3989function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3990 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3991 "IPA CRCX ACK");
3992 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3993 "IPA CRCX NACK");
3994}
3995testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3996 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003997 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003998 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3999 vc_conn.done;
4000}
4001
4002/* Regular sequence of CRCX/MDCX/DLCX */
4003function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4004 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4005 "IPA CRCX ACK");
4006 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4007 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4008 var uint7_t rtp_pt2 := f_rnd_int(127);
4009 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4010 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4011 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4012 "IPA MDCX ACK");
4013 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4014 "IPA DLCX ACK");
4015}
4016testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4017 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004018 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004019 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4020 vc_conn.done;
4021}
4022
Harald Welte3ae11da2018-02-25 13:36:06 +01004023/* Sequence of CRCX, 2x MDCX, DLCX */
4024function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4025 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4026 "IPA CRCX ACK");
4027 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4028 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4029 var uint7_t rtp_pt2 := f_rnd_int(127);
4030 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4031 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4032 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4033 "IPA MDCX ACK");
4034 /* Second MDCX */
4035 remote_ip := f_rnd_int(c_UINT32_MAX);
4036 remote_port := f_rnd_int(c_UINT16_MAX);
4037 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4038 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4039 "IPA MDCX ACK");
4040 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4041 "IPA DLCX ACK");
4042}
4043testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4044 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004045 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004046 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4047 vc_conn.done;
4048}
4049
Harald Welte9912eb52018-02-25 13:30:15 +01004050/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
4051function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
4052 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4053 "IPA CRCX NACK");
4054}
4055testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4056 var ConnHdlrPars pars;
4057 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004058 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004059
4060 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4061 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4062 vc_conn.done;
4063
4064 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4065 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4066 vc_conn.done;
4067}
4068
Harald Weltea3f1df92018-02-25 12:49:55 +01004069
Harald Welte883340c2018-02-28 18:59:29 +01004070/***********************************************************************
4071 * PCU Socket related tests
4072 ***********************************************************************/
4073
Harald Welte07bd2d22019-05-25 11:03:30 +02004074/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004075friend 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 +01004076runs on test_CT {
4077 timer T := 3.0;
4078
4079 /* we don't expect any RTS.req before PDCH are active */
4080 T.start;
4081 alt {
4082 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004084 }
4085 [] PCU.receive { repeat; }
4086 [] T.timeout { }
4087 }
4088
4089 /* Send PDCH activate request for known PDCH timeslot */
4090 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4091
4092 /* we now expect RTS.req for this timeslot (only) */
4093 T.start;
4094 alt {
4095 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4096 setverdict(pass);
4097 }
4098 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4099 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004101 }
4102 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004104 }
4105 [] PCU.receive { repeat; }
4106 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004108 }
4109 [not exp_success] T.timeout {
4110 setverdict(pass);
4111 }
4112 }
4113}
4114
Harald Welte07bd2d22019-05-25 11:03:30 +02004115/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004116friend 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 +01004117runs on test_CT {
4118 timer T := 3.0;
4119
4120 /* Send PDCH activate request for known PDCH timeslot */
4121 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4122
4123 PCU.clear;
4124 /* we now expect no RTS.req for this timeslot */
4125 T.start;
4126 alt {
4127 [] 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 +02004128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004129 }
4130 [] PCU.receive { repeat; }
4131 [] T.timeout {
4132 setverdict(pass);
4133 }
4134 }
4135}
4136
Harald Weltead033dc2019-05-25 17:28:16 +02004137friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004138 f_init();
4139 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4140}
4141
Harald Welte883340c2018-02-28 18:59:29 +01004142/* PDCH activation via PCU socket; check for presence of RTS.req */
4143testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004144 f_init_pcu_test();
4145
Harald Welte883340c2018-02-28 18:59:29 +01004146 f_TC_pcu_act_req(0, 0, 7, true);
4147}
4148
4149/* PDCH activation via PCU socket on non-PDCU timeslot */
4150testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004151 f_init_pcu_test();
4152
Harald Welte883340c2018-02-28 18:59:29 +01004153 f_TC_pcu_act_req(0, 0, 1, false);
4154}
4155
4156/* PDCH activation via PCU socket on wrong BTS */
4157testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004158 f_init_pcu_test();
4159
Harald Welte883340c2018-02-28 18:59:29 +01004160 f_TC_pcu_act_req(23, 0, 7, false);
4161}
4162
4163/* PDCH activation via PCU socket on wrong TRX */
4164testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004165 f_init_pcu_test();
4166
Harald Welte883340c2018-02-28 18:59:29 +01004167 f_TC_pcu_act_req(0, 23, 7, false);
4168}
4169
4170/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4171testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004172 f_init_pcu_test();
4173
Harald Welte883340c2018-02-28 18:59:29 +01004174 /* Activate PDCH */
4175 f_TC_pcu_act_req(0, 0, 7, true);
4176 f_sleep(1.0);
4177 /* and De-Activate again */
4178 f_TC_pcu_deact_req(0, 0, 7);
4179}
4180
4181/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4182testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004183 f_init_pcu_test();
4184
Harald Welte883340c2018-02-28 18:59:29 +01004185 f_TC_pcu_deact_req(0, 0, 1);
4186}
4187
4188/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4189testcase TC_pcu_ver_si13() runs on test_CT {
4190 const octetstring si13 := '00010203040506070909'O;
4191 var PCUIF_send_data sd;
4192 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004193 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004194
4195 /* Set SI13 via RSL */
4196 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004197
Harald Welte883340c2018-02-28 18:59:29 +01004198 T.start;
4199 alt {
4200 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4201 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4202 setverdict(pass);
4203 } else {
4204 repeat;
4205 }
4206 }
4207 [] PCU.receive { repeat; }
4208 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004210 }
4211 }
4212}
4213
4214private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4215
4216/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004217friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004218 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4219runs on test_CT
4220{
4221 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4222 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4223}
4224
4225/* 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 +02004226friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4227 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004228runs on test_CT
4229{
4230 var PCUIF_send_data sd;
4231
4232 timer T := 3.0;
4233 T.start;
4234 alt {
4235 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4236 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4237 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4238 sd.data.u.rts_req.fn, sapi, data);
4239 }
4240 [] PCU.receive { repeat; }
4241 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004243 }
4244 }
4245}
4246
4247/* Send DATA.req on invalid BTS */
4248testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004249 var TfiUsfArr tua := f_TfiUsfArrInit();
4250 var octetstring data := '0000'O & f_rnd_octstring(21);
4251
4252 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004253
Harald Welte883340c2018-02-28 18:59:29 +01004254 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004255 f_TfiUsfArrSet(tua, 7, 0);
4256 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4257 f_sleep(1.0);
4258
4259 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004260}
4261
4262/* Send DATA.req on invalid TRX */
4263testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004264 var TfiUsfArr tua := f_TfiUsfArrInit();
4265 var octetstring data := '0000'O & f_rnd_octstring(21);
4266
4267 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004268
Harald Welte883340c2018-02-28 18:59:29 +01004269 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004270 f_TfiUsfArrSet(tua, 7, 0);
4271 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4272 f_sleep(1.0);
4273
4274 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004275}
4276
4277/* Send DATA.req on invalid timeslot */
4278testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004279 var TfiUsfArr tua := f_TfiUsfArrInit();
4280 var octetstring data := '0000'O & f_rnd_octstring(21);
4281
4282 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004283
Harald Welte883340c2018-02-28 18:59:29 +01004284 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004285 f_TfiUsfArrSet(tua, 7, 0);
4286 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4287 f_sleep(1.0);
4288
4289 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004290}
4291
4292/* Send DATA.req on timeslot that hasn't been activated */
4293testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004294 var TfiUsfArr tua := f_TfiUsfArrInit();
4295 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004296
Harald Welte7162a612019-05-26 12:56:09 +02004297 f_virtphy_common();
4298
4299 f_TfiUsfArrSet(tua, 7, 0);
4300 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4301 f_sleep(1.0);
4302
4303 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004304}
4305
Harald Weltead033dc2019-05-25 17:28:16 +02004306private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004307 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4308 boolean wait_rts := true)
4309runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004310 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004311 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004312
4313 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004314 if (wait_rts) {
4315 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4316 } else {
4317 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4318 }
Harald Weltead033dc2019-05-25 17:28:16 +02004319
4320 T.start;
4321 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004322 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004323 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4324 setverdict(pass);
4325 }
Harald Welte7162a612019-05-26 12:56:09 +02004326 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4327 setverdict(fail, "Received unexpected ", rx_dl);
4328 }
Harald Weltead033dc2019-05-25 17:28:16 +02004329 [] L1CTL.receive {
4330 repeat;
4331 }
Harald Welte7162a612019-05-26 12:56:09 +02004332 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004333 setverdict(fail, "Timeout waiting for ", data);
4334 }
Harald Welte7162a612019-05-26 12:56:09 +02004335 [not expect_data] T.timeout {
4336 setverdict(pass);
4337 }
Harald Weltead033dc2019-05-25 17:28:16 +02004338 }
4339}
4340
4341private function f_disable_dynamic_ts() runs on test_CT
4342{
4343 f_init_vty_bsc();
4344 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4345 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4346 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4347 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004348 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004349}
4350
4351private function f_virtphy_common() runs on test_CT {
4352 f_disable_dynamic_ts();
4353 f_init_l1ctl();
4354 f_l1_tune(L1CTL);
4355}
4356
4357testcase TC_pcu_data_req_pdtch() runs on test_CT {
4358 var TfiUsfArr tua := f_TfiUsfArrInit();
4359 var octetstring data := '0000'O & f_rnd_octstring(21);
4360
4361 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004362
Harald Welte883340c2018-02-28 18:59:29 +01004363 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004364 f_TfiUsfArrSet(tua, 7, 0);
4365 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4366 f_sleep(1.0);
4367
4368 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004369}
4370
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004371/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004372testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004373 var TfiUsfArr tua := f_TfiUsfArrInit();
4374 var octetstring data := '0000'O & f_rnd_octstring(21);
4375
4376 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004377
Harald Welte883340c2018-02-28 18:59:29 +01004378 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004379 f_TfiUsfArrSet(tua, 7, 0);
4380 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4381 f_sleep(1.0);
4382
4383 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004384}
4385
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004386private function f_TC_pcu_ptcch_ul(uint16_t ra)
4387runs on test_CT {
4388 var template PCUIF_Message pcu_rach_ind;
4389 var PCUIF_send_data sd;
4390 var GsmFrameNumber fn;
4391 timer T;
4392
4393 /* Send an Access Burst on PTCCH/U over the Um-interface */
4394 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4395 chan_nr := ts_RslChanNr_PDCH(7),
4396 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4397
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004398 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4399 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004400
4401 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4402 T.start(52.0 * 4.615 / 1000.0);
4403 alt {
4404 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4405 log("Rx an Access Burst on the PCU interface: ", sd.data);
4406 setverdict(pass);
4407 T.stop;
4408 }
4409 [] PCU.receive { repeat; }
4410 [] T.timeout {
4411 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4412 /* Keep going, that's not the end of the world */
4413 }
4414 }
4415}
4416
4417testcase TC_pcu_ptcch() runs on test_CT {
4418 var L1ctlDlMessage dl;
4419 var octetstring data;
4420 timer T;
4421
4422 f_init_pcu_test();
4423 f_init_l1ctl();
4424 f_l1_tune(L1CTL);
4425
4426 /* Activate PDCH channel on TS7 */
4427 f_TC_pcu_act_req(0, 0, 7, true);
4428
4429 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004430 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004431
4432 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4433 for (var integer i := 0; i < 16; i := i + 1) {
4434 log("Sending an Access Burst towards the L1CTL interface");
4435 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4436 }
4437
4438 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4439 data := f_rnd_octstring(23);
4440
4441 /* Verify PTCCH/D: send a random data block, make sure it's received */
4442 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4443 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4444
4445 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4446 * let's give it more time in case if we miss the beginning. */
4447 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4448 alt {
4449 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4450 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4451 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4452 frame := data)) -> value dl {
4453 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4454 setverdict(pass);
4455 T.stop;
4456 }
4457 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4458 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4459 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4460 l2_data := data)) -> value dl {
4461 log("Rx PTCCH/D data block on L1CTL: ", dl);
4462 setverdict(pass);
4463 T.stop;
4464 }
4465 [] L1CTL.receive { repeat; }
4466 [] T.timeout {
4467 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4468 }
4469 }
4470}
4471
Harald Welte883340c2018-02-28 18:59:29 +01004472/* Send AGCH from PCU; check it appears on Um side */
4473testcase TC_pcu_data_req_agch() runs on test_CT {
4474 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004475 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004476 f_init_l1ctl();
4477 f_l1_tune(L1CTL);
4478
4479 f_TC_pcu_act_req(0, 0, 7, true);
4480 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4481
4482 T.start;
4483 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004484 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004485 setverdict(pass);
4486 }
4487 [] L1CTL.receive { repeat; }
4488 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004490 }
4491 }
4492}
4493
Harald Welte928622b2019-05-26 13:22:59 +02004494/* Send AGCH from PCU; check it appears on Um side */
4495testcase TC_pcu_data_req_pch() runs on test_CT {
4496 timer T := 3.0;
4497 f_init_pcu_test();
4498 f_init_l1ctl();
4499 f_l1_tune(L1CTL);
4500
4501 f_TC_pcu_act_req(0, 0, 7, true);
4502 /* three characters prefix: last 3 digits of IMSI as ASCII */
4503 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4504
4505 T.start;
4506 alt {
4507 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4508 setverdict(pass);
4509 }
4510 [] L1CTL.receive { repeat; }
4511 [] T.timeout {
4512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4513 }
4514 }
4515}
4516
Harald Welte883340c2018-02-28 18:59:29 +01004517/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4518testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4519 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004520 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004521 f_init_l1ctl();
4522 f_l1_tune(L1CTL);
4523
4524 /* append 3 last imsi digits so BTS can compute pagng group */
4525 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4526
4527 timer T := 0.5;
4528 T.start;
4529 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004530 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004531 /* TODO: verify paging group */
4532 setverdict(pass);
4533 }
4534 [] L1CTL.receive { repeat; }
4535 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004537 }
4538 }
4539}
4540
4541/* Send RACH from Um side, expect it to show up on PCU socket */
4542testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004543 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004544 f_init_l1ctl();
4545 f_l1_tune(L1CTL);
4546
4547 var GsmFrameNumber fn_last := 0;
4548 for (var integer i := 0; i < 1000; i := i+1) {
4549 var OCT1 ra := f_rnd_ra_ps();
4550 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4551 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004553 }
4554 fn_last := fn;
4555
4556 timer T := 2.0;
4557 T.start;
4558 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004559 [] 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 +01004560 T.stop;
4561 }
4562 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004564 }
4565 [] PCU.receive { repeat; }
4566 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004568 }
4569 }
4570 }
4571 setverdict(pass);
4572}
4573
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004574/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4575 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4576testcase TC_pcu_ext_rach_content() runs on test_CT {
4577 var template PCUIF_Message pcu_rach_ind;
4578 var GsmFrameNumber fn_last := 0;
4579 var L1ctlRachSynchSeq synch_seq;
4580 var PCUIF_BurstType pcu_bt;
4581 var GsmFrameNumber fn;
4582 var BIT11 ra11;
4583
4584 f_init_pcu_test();
4585 f_init_l1ctl();
4586 f_l1_tune(L1CTL);
4587
4588 for (var integer i := 0; i < 1000; i := i+1) {
4589 /* We need to test both TS1 & TS2 */
4590 if (i rem 2 == 0) {
4591 synch_seq := RACH_SYNCH_SEQ_TS1;
4592 pcu_bt := BURST_TYPE_1;
4593 } else {
4594 synch_seq := RACH_SYNCH_SEQ_TS2;
4595 pcu_bt := BURST_TYPE_2;
4596 }
4597
4598 ra11 := f_rnd_ra11_ps();
4599 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4600 if (fn == fn_last) {
4601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4602 "Two RACH in same FN?!?");
4603 }
4604 fn_last := fn;
4605
4606 /* Compose the expected message */
4607 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004608 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004609 ra := bit2int(ra11),
4610 is_11bit := 1,
4611 burst_type := pcu_bt,
4612 fn := fn);
4613
4614 timer T := 2.0;
4615 T.start;
4616 alt {
4617 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4618 T.stop;
4619 }
4620 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4622 }
4623 [] PCU.receive { repeat; }
4624 [] T.timeout {
4625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4626 }
4627 }
4628 }
4629 setverdict(pass);
4630}
4631
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004632private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4633runs on test_CT {
4634 var template PCUIF_send_data sdt;
4635 var PCUIF_send_data sd;
4636 var int16_t lqual_cb;
4637 timer T := 1.0;
4638
4639 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4640 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4641
4642 /* Send a random PDTCH frame over Um */
4643 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4644 '0000'O & f_rnd_octstring(21)));
4645
4646 T.start;
4647 alt {
4648 /* If expected link quality is above the threshold */
4649 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4650 lqual_cb := sd.data.u.data_ind.lqual_cb;
4651 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4652
4653 /* Make sure the actual link quality matches the expected value */
4654 if (not match(lqual_cb, lqual_cb_exp)) {
4655 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4656 "expected value ", lqual_cb_exp));
4657 } else {
4658 setverdict(pass);
4659 }
4660 }
4661 /* If expected link quality is below the threshold */
4662 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4664 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4665 }
4666 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4667 [] PCU.receive { repeat; }
4668 [lqual_cb_exp < thresh] T.timeout {
4669 log("Rx nothing, as expected");
4670 setverdict(pass);
4671 }
4672 [lqual_cb_exp >= thresh] T.timeout {
4673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4674 "Timeout waiting for PCUIF_DATA.ind");
4675 }
4676 }
4677}
4678
4679/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4680testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4681 f_init_pcu_test();
4682 PCU.clear;
4683
4684 f_init_l1ctl();
4685 f_l1_tune(L1CTL);
4686
4687 /* Activate a PDCH channel on TS7 */
4688 f_TC_pcu_act_req(0, 0, 7, true);
4689
4690 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004691 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004692
4693 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4694 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4695 var TrxcMessage ret;
4696
4697 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4698 valueof(ts_TRXC_FAKE_CI(i)));
4699
4700 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4701 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4702 }
4703}
4704
Harald Welte883340c2018-02-28 18:59:29 +01004705/* Send PAGING via RSL, expect it to shw up on PCU socket */
4706testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004707 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004708
4709 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004710 var MobileIdentityLV mi_lv;
4711 var octetstring mi_lv_enc;
4712 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004713 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004714
Harald Welte883340c2018-02-28 18:59:29 +01004715 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004716 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004717 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004718 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004719 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004720
4721 /* Fancy encoding for PCUIF */
4722 mi_lv := valueof(ts_MI_LV(mi));
4723 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4724 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004725
4726 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004727 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004728 T.start;
4729 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004730 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004731 }
4732 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004734 }
4735 [] PCU.receive { repeat; }
4736 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004738 }
4739 }
4740 }
4741 setverdict(pass);
4742}
4743
Harald Welted66c9b82019-05-25 09:03:15 +02004744/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4745testcase TC_pcu_time_ind() runs on test_CT {
4746 var PCUIF_send_data pcu_sd;
4747 var integer num_time_ind := 0;
4748 var integer first_fn, last_fn;
4749 var float test_duration := 5.0;
4750 timer T;
4751
4752 f_init_pcu_test();
4753 f_TC_pcu_act_req(0, 0, 7, true);
4754
4755 PCU.clear;
4756 T.start(test_duration);
4757 alt {
4758 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4759 num_time_ind := num_time_ind + 1;
4760 if (not isbound(first_fn)) {
4761 first_fn := pcu_sd.data.u.time_ind.fn;
4762 }
4763 last_fn := pcu_sd.data.u.time_ind.fn;
4764 repeat;
4765 }
4766 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4767 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4768 repeat;
4769 }
4770 [] PCU.receive {
4771 repeat;
4772 }
4773 [] T.timeout {}
4774 }
4775 var integer fn_expired := last_fn - first_fn;
4776 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4777
4778 /* verify the number of frames expired matches our expectation */
4779 const float c_GSM_FN_DURATION_MS := 4.61538;
4780 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004781 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004782 if (not match(fn_expired, t_fn_expected)) {
4783 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4784 }
4785
4786 /* There are three TIME.ind in every fn MOD 13 */
4787 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4788 /* Add some tolerance */
4789 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4790 if (not match(num_time_ind, t_time_ind_exp)) {
4791 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4792 }
4793
4794 setverdict(pass);
4795}
4796
Harald Welte4832c862019-05-25 14:57:18 +02004797/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4798testcase TC_pcu_rts_req() runs on test_CT {
4799 var PCUIF_send_data pcu_sd;
4800 var integer first_fn, last_fn;
4801 var integer num_rts_pdtch := 0;
4802 var integer num_rts_ptcch := 0;
4803 var float test_duration := 5.0;
4804 timer T;
4805
4806 f_init_pcu_test();
4807 f_TC_pcu_act_req(0, 0, 7, true);
4808
4809 PCU.clear;
4810 T.start(test_duration);
4811 alt {
4812 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4813 -> value pcu_sd {
4814 num_rts_pdtch := num_rts_pdtch + 1;
4815 if (not isbound(first_fn)) {
4816 first_fn := pcu_sd.data.u.rts_req.fn;
4817 }
4818 last_fn := pcu_sd.data.u.rts_req.fn;
4819 repeat;
4820 }
4821 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4822 -> value pcu_sd {
4823 num_rts_ptcch := num_rts_ptcch + 1;
4824 if (not isbound(first_fn)) {
4825 first_fn := pcu_sd.data.u.rts_req.fn;
4826 }
4827 last_fn := pcu_sd.data.u.rts_req.fn;
4828 repeat;
4829 }
4830 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4831 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4832 repeat;
4833 }
4834 [] PCU.receive {
4835 repeat;
4836 }
4837 [] T.timeout {}
4838 }
4839 var integer fn_expired := last_fn - first_fn;
4840 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4841 ", num_rts_ptcch=", num_rts_ptcch);
4842
4843 /* verify the number of frames expired matches our expectation */
4844 const float c_GSM_FN_DURATION_MS := 4.61538;
4845 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004846 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004847 if (not match(fn_expired, t_fn_expected)) {
4848 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4849 }
4850
4851 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4852 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4853 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4854 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4855 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4856 t_ptcch_exp);
4857 }
4858
4859 /* We have 12 PDTCH blocks every 52-multiframe */
4860 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4861 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4862 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4863 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4864 t_pdtch_exp);
4865 }
4866
4867 setverdict(pass);
4868}
4869
Harald Welte07bd2d22019-05-25 11:03:30 +02004870/* test for generating Abis side OML ALERT from the PCU */
4871testcase TC_pcu_oml_alert() runs on test_CT {
4872 var PCUIF_send_data pcu_sd;
4873 var integer num_time_ind := 0;
4874 var integer first_fn, last_fn;
4875 var float test_duration := 5.0;
4876 timer T;
4877
4878 f_init_pcu_test();
4879 f_TC_pcu_act_req(0, 0, 7, true);
4880
4881 /* re-connect CTRL port from BTS to BSC */
4882 f_ipa_ctrl_stop();
4883 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4884
4885 /* Send that OML Alert */
4886 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4887
4888 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4889 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4890 setverdict(pass);
4891}
4892
Harald Welteeaa9a862019-05-26 23:01:08 +02004893template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4894 template (value) RoutingAreaIdentificationV rai,
4895 template (value) OCT1 cause) := {
4896 discriminator := '0000'B, /* overwritten */
4897 tiOrSkip := {
4898 skipIndicator := '0000'B
4899 },
4900 msgs := {
4901 rrm := {
4902 gPRS_suspensionRequest := {
4903 messageType := '00110100'B,
4904 tLLI := tlli,
4905 routingAreaIdentification := rai,
4906 suspensionCause := cause,
4907 service_Support := omit
4908 }
4909 }
4910 }
4911}
4912
4913/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4914private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4915 var PCUIF_Message first_info;
4916 var integer pcu_conn_id := -1;
4917 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4918 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4919 var OCT4 tlli := '01020304'O;
4920 var OCT1 cause := '23'O;
4921 timer T := 5.0;
4922
4923 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4924
4925 f_l1_tune(L1CTL);
4926 RSL.clear;
4927
4928 f_est_dchan();
4929 L1CTL.clear;
4930
4931 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4932
4933 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4934 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4935 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4936
4937 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4938 T.start;
4939 alt {
4940 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4941 setverdict(pass);
4942 }
4943 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4944 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4945 }
4946 [] PCU.receive {
4947 repeat;
4948 }
4949 [] T.timeout {
4950 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4951 }
4952 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004953
4954 /* release the channel */
4955 f_rsl_chan_deact();
4956 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4957 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004958}
4959testcase TC_pcu_rr_suspend() runs on test_CT {
4960 var ConnHdlrPars pars;
4961 var ConnHdlr vc_conn;
4962
4963 f_init();
4964
4965 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4966 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4967 vc_conn.done;
4968}
Harald Welte07bd2d22019-05-25 11:03:30 +02004969
Harald Weltea2e0e942019-05-27 18:12:53 +02004970/* Ensure that PCUIF socket can accept only a single connection */
4971testcase TC_pcu_socket_connect_multi() runs on test_CT {
4972 timer T := 5.0;
4973
4974 /* this (among other things) establishes the first connection to the PCUIF socket */
4975 f_init();
4976
4977 /* try to establish a second connection, expect it to fail */
4978 PCU.send(UD_connect:{mp_pcu_socket, -1});
4979 T.start;
4980 alt {
4981 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4982 setverdict(pass);
4983 }
4984 [] PCU.receive(UD_connect_result:?) {
4985 setverdict(fail, "Unexpected unix domain connect result");
4986 }
4987 [] T.timeout {
4988 setverdict(pass);
4989 }
4990 }
4991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4992}
4993
Harald Weltec8effb72019-05-27 18:23:04 +02004994/* Ensure that PCUIF socket can disconnect + reconnect */
4995testcase TC_pcu_socket_reconnect() runs on test_CT {
4996 /* this (among other things) establishes the first connection to the PCUIF socket */
4997 f_init();
4998
4999 f_sleep(1.0);
5000
5001 f_pcuif_close(PCU, g_pcu_conn_id);
5002 g_pcu_conn_id := -1;
5003
5004 f_sleep(1.0);
5005
5006 /* re-connect */
5007 PCU.clear;
5008 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5009 setverdict(pass);
5010
5011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5012}
5013
Harald Weltebe030482019-05-27 22:29:35 +02005014/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005015private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5016runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005017 var L1ctlDlMessage l1_dl;
5018 var SystemInformation si;
5019 timer T := 5.0;
5020 T.start;
5021 alt {
5022 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
5023 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
5024 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
5025 log("Ignoring non-RR SI ", l1_dl);
5026 repeat;
5027 }
5028 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005029 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005030 repeat;
5031 }
5032 }
5033 [] pt.receive {
5034 repeat;
5035 }
5036 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5038 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005039 }
5040 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005041 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005042}
5043
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005044/* Check if GPRS Indicator is present in RR System Information of a given type */
5045private function f_si_has_gprs_indicator(RrMessageType si_type)
5046runs on test_CT return boolean {
5047 var SystemInformation si := f_get_si(L1CTL, si_type);
5048
5049 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
5050 var RestOctets ro := si.payload.si3.rest_octets;
5051 var SI3RestOctets rest := dec_SI3RestOctets(ro);
5052 return rest.gprs_ind.presence == '1'B;
5053 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
5054 var RestOctets ro := si.payload.si4.rest_octets;
5055 var SI4RestOctets rest := dec_SI4RestOctets(ro);
5056 return rest.gprs_ind.presence == '1'B;
5057 }
5058
5059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5060 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005061}
5062
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005063/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5064private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5065runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005066 /* don't call f_init() as this would connect PCU socket */
5067 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005068
5069 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005070 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005071 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005072
5073 f_init_l1ctl();
5074 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005075 f_sleep(2.0);
5076 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005077
5078 if (f_si_has_gprs_indicator(si_type)) {
5079 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005080 } else {
5081 setverdict(pass);
5082 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005083
Harald Weltebe030482019-05-27 22:29:35 +02005084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5085}
5086
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005087testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5088 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5089}
Harald Weltebe030482019-05-27 22:29:35 +02005090
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005091testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5092 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5093}
5094
5095/* Ensure that GPRS capability is advertised after PCU socket connect */
5096private function f_TC_pcu_socket_connect(RrMessageType si_type)
5097runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005098 /* this (among other things) establishes the first connection to the PCUIF socket */
5099 f_init();
5100 f_init_l1ctl();
5101 f_l1_tune(L1CTL);
5102
5103 f_sleep(2.0);
5104 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005105
5106 if (not f_si_has_gprs_indicator(si_type)) {
5107 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005108 } else {
5109 setverdict(pass);
5110 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005111
Harald Weltebe030482019-05-27 22:29:35 +02005112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5113}
5114
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005115testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5116 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5117}
Harald Weltebe030482019-05-27 22:29:35 +02005118
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005119testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5120 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5121}
5122
5123/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5124private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5125runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005126 /* this (among other things) establishes the first connection to the PCUIF socket */
5127 f_init();
5128 f_init_l1ctl();
5129 f_l1_tune(L1CTL);
5130
5131 f_pcuif_close(PCU, g_pcu_conn_id);
5132 g_pcu_conn_id := -1;
5133
5134 f_sleep(1.0);
5135
5136 /* re-connect */
5137 PCU.clear;
5138 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5139
5140 f_sleep(2.0);
5141 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005142
5143 if (f_si_has_gprs_indicator(si_type)) {
5144 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005145 } else {
5146 setverdict(pass);
5147 }
5148
5149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5150}
5151
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005152testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5153 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5154}
5155
5156testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5157 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5158}
5159
Oliver Smithf5239c72019-08-28 10:01:25 +02005160/* 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) */
5161testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5162 var SystemInformation si3 := valueof(ts_SI3_default);
5163
5164 f_init();
5165
5166 /* Verify cell_id */
5167 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5168 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5169 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005170 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5171 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5172 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005173 }
5174
5175 /* Verify LAC */
5176 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5177 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5178 if (lac_si3 != lac_pcu) {
5179 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5180 }
5181
5182 setverdict(pass);
5183}
Harald Welted66c9b82019-05-25 09:03:15 +02005184
Harald Welte3d04ae62018-04-04 20:29:05 +02005185/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005186 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005187 ***********************************************************************/
5188
5189private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5190runs on ConnHdlr {
5191 var PCUIF_send_data sd;
5192 /* Expect BTS to immediately acknowledge activation as PDCH */
5193 PCU.clear;
5194 f_rsl_chan_act(g_pars.chan_mode);
5195 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005196 timer T_wait := 2.0;
5197 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005198 alt {
5199 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5200 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005201 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5202 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5203 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005204 }
5205 }
5206 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005207 [] T_wait.timeout {
5208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5209 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5210 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005211 }
5212 /* try to activate this PDCH from the PCU point of view */
5213 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5214 /* FIXME: is there a response? */
5215}
5216
5217private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5218runs on ConnHdlr {
5219 var PCUIF_send_data sd;
5220 /* Send RSL CHAN REL (deactivate) */
5221 PCU.clear;
5222 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5223 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005224 timer T_wait := 2.0;
5225 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005226 alt {
5227 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5228 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005229 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5230 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5231 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005232 }
5233 }
5234 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005235 [] T_wait.timeout {
5236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5237 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5238 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005239 }
5240 /* Emulate PCU asking BTS to deactivate PDCH */
5241 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5242 alt {
5243 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5244 setverdict(pass);
5245 }
5246 [] RSL.receive { repeat; }
5247 }
5248}
5249
5250/* Activate Osmocom-style dynamic PDCH from BSC side */
5251function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5252 var PCUIF_Message first_info;
5253 var integer ts_nr := g_chan_nr.tn;
5254 var integer trx_nr := 0;
5255 var integer bts_nr := 0;
5256 var integer pcu_conn_id := -1;
5257
5258 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5259
5260 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5261 f_sleep(3.0);
5262 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5263 setverdict(pass);
5264}
5265testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5266 var ConnHdlrPars pars;
5267 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005268 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005269
5270 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5271 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5272 vc_conn.done;
5273}
5274
5275/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5276function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5277 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005278 var integer pcu_conn_id := -1;
5279
5280 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5281
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005282 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5283 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5284 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005285 setverdict(pass);
5286}
5287testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5288 var ConnHdlrPars pars;
5289 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005290 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005291
5292 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5293 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5294 vc_conn.done;
5295}
5296
5297/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5298function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5299 var PCUIF_Message first_info;
5300 var integer ts_nr := g_chan_nr.tn;
5301 var integer trx_nr := 0;
5302 var integer bts_nr := 0;
5303 var integer pcu_conn_id := -1;
5304
5305 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5306
5307 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005308 /* Send a second Chan Activ and expect it to be NACKed */
5309 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5310 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005311 setverdict(pass);
5312}
5313testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5314 var ConnHdlrPars pars;
5315 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005316 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005317
5318 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5319 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5320 vc_conn.done;
5321}
5322
5323/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5324function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5325 var PCUIF_Message first_info;
5326 var integer ts_nr := g_chan_nr.tn;
5327 var integer trx_nr := 0;
5328 var integer bts_nr := 0;
5329 var integer pcu_conn_id := -1;
5330 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5331
5332 /* register for the TCH/F channel number */
5333 f_rslem_register(0, chan_nr);
5334
5335 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5336
5337 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5338 "RSL CHAN ACT");
5339 setverdict(pass);
5340}
5341testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5342 var ConnHdlrPars pars;
5343 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005344 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005345
5346 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5347 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5348 vc_conn.done;
5349}
5350
5351/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5352function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5353 var PCUIF_Message first_info;
5354 var integer ts_nr := g_chan_nr.tn;
5355 var integer trx_nr := 0;
5356 var integer bts_nr := 0;
5357 var integer pcu_conn_id := -1;
5358 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5359 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5360
5361 /* register for the TCH/H channel numbers */
5362 f_rslem_register(0, chan_nr[0]);
5363 f_rslem_register(0, chan_nr[1]);
5364
5365 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5366
5367 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5368 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5369 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5370 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5371 setverdict(pass);
5372}
5373testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5374 var ConnHdlrPars pars;
5375 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005376 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005377
5378 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5379 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5380 vc_conn.done;
5381}
5382
Harald Welte9bbbfb52018-04-05 09:33:19 +02005383/***********************************************************************
5384 * IPA Style Dynamic Timeslot Support
5385 ***********************************************************************/
5386
5387private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5388runs on ConnHdlr {
5389 var PCUIF_send_data sd;
5390 /* Expect BTS to immediately acknowledge activation as PDCH */
5391 PCU.clear;
5392 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5393 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005394 timer T_wait := 2.0;
5395 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005396 alt {
5397 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5398 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005399 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5400 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5401 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005402 }
5403 }
5404 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005405 [] T_wait.timeout {
5406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5407 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5408 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005409 }
5410 /* try to activate this PDCH from the PCU point of view */
5411 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5412 /* FIXME: is there a response? */
5413
5414 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5415}
5416
5417private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5418runs on ConnHdlr {
5419 var PCUIF_send_data sd;
5420 /* Send RSL CHAN REL (deactivate) */
5421 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5422 PCU.clear;
5423 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005424 timer T_wait := 2.0;
5425 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005426 alt {
5427 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5428 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005429 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5430 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5431 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005432 }
5433 }
5434 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005435 [] T_wait.timeout {
5436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5437 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5438 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005439 }
5440 /* Emulate PCU asking BTS to deactivate PDCH */
5441 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5442 alt {
5443 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5444 setverdict(pass);
5445 }
5446 [] RSL.receive { repeat; }
5447 }
5448}
5449
5450/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5451function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5452 var PCUIF_Message first_info;
5453 var integer ts_nr := g_chan_nr.tn;
5454 var integer trx_nr := 0;
5455 var integer bts_nr := 0;
5456 var integer pcu_conn_id := -1;
5457
5458 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5459
5460 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5461 f_sleep(3.0);
5462 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5463
5464 setverdict(pass);
5465
5466}
5467testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5468 var ConnHdlrPars pars;
5469 var ConnHdlr vc_conn;
5470 f_init();
5471
5472 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5473 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5474 vc_conn.done;
5475}
5476
5477/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5478function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5479 var PCUIF_Message first_info;
5480 var integer ts_nr := g_chan_nr.tn;
5481 var integer trx_nr := 0;
5482 var integer bts_nr := 0;
5483 var integer pcu_conn_id := -1;
5484
5485 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5486
5487 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5488 "RSL CHAN ACT");
5489 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5490 "RF CHAN REL", true);
5491 setverdict(pass);
5492}
5493testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5494 var ConnHdlrPars pars;
5495 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005496 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005497
5498 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5499 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5500 vc_conn.done;
5501}
5502
5503/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5504function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5505 var PCUIF_Message first_info;
5506 var integer ts_nr := g_chan_nr.tn;
5507 var integer trx_nr := 0;
5508 var integer bts_nr := 0;
5509 var integer pcu_conn_id := -1;
5510
5511 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5512
5513 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5514 "RSL CHAN ACT");
5515
5516 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5517 alt {
5518 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5519 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005521 }
5522 [] RSL.receive { repeat; }
5523 }
5524
5525 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5526 "RF CHAN REL", true);
5527 setverdict(pass);
5528}
5529testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5530 var ConnHdlrPars pars;
5531 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005532 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005533
5534 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5535 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5536 vc_conn.done;
5537}
5538
5539/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5540function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5541 var PCUIF_Message first_info;
5542 var integer ts_nr := g_chan_nr.tn;
5543 var integer trx_nr := 0;
5544 var integer bts_nr := 0;
5545 var integer pcu_conn_id := -1;
5546
5547 /* register for the TCH/F channel number */
5548 f_rslem_register(0, g_chan_nr);
5549
5550 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5551
5552 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5553
5554 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5555 "RSL CHAN ACT");
5556
5557 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5558
5559 setverdict(pass);
5560}
5561testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5562 var ConnHdlrPars pars;
5563 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005564 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005565
5566 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5567 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5568 vc_conn.done;
5569}
5570
5571
Harald Welte0472ab42018-03-12 15:02:26 +01005572/***********************************************************************
5573 * LAPDm / RLL related
5574 ***********************************************************************/
5575
5576private function f_tx_lapdm(template (value) LapdmFrame l,
5577 template (value) RslLinkId link_id) runs on ConnHdlr {
5578 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005579 var template (value) SacchL1Header l1h;
5580
5581 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005582 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005583 /* Compose dummy L1 header */
5584 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5585 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 +02005586 } else {
5587 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005588 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 +01005589 }
Harald Welte0472ab42018-03-12 15:02:26 +01005590}
5591
5592type record RllTestCase {
5593 uint3_t sapi,
5594 RslLinkId link_id,
5595 octetstring l3,
5596 boolean exp
5597}
5598type record of RllTestCase RllTestCases;
5599template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5600 sapi := sapi,
5601 link_id := id,
5602 l3 := l3,
5603 exp := exp
5604}
5605
5606/* execute the same callback function with a set of different parameters (tcs) on a
5607 * variety of logical channels */
5608private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5609 var ConnHdlrPars pars;
5610 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005611 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005612
5613 /* test on each of the channels we have */
5614 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5615 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5616
5617 /* test each of the test cases on the current channel */
5618 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5619 pars.spec.rll := tcs[j];
5620 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5621 vc_conn := f_start_handler(fn, pars);
5622 vc_conn.done;
5623 }
5624 }
5625
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005627}
5628
5629/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5630private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5631 var RllTestCase tc := g_pars.spec.rll;
5632 timer T := 3.0;
5633
5634 f_l1_tune(L1CTL);
5635 RSL.clear;
5636
5637 /* activate the logical channel */
5638 f_est_dchan();
5639 L1CTL.clear;
5640
5641 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5642 T.start;
5643 alt {
5644 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5645 if (tc.exp) {
5646 setverdict(pass);
5647 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005649 }
5650 }
5651 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5652 if (tc.exp) {
5653 setverdict(pass);
5654 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005656 }
5657 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005658 /* We also expect to receive the measurements */
5659 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005660 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005662 }
5663 [not tc.exp] T.timeout {
5664 setverdict(pass);
5665 }
5666 }
5667
5668 f_rsl_chan_deact();
5669 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5670 f_rslem_unregister(0, g_chan_nr);
5671}
5672testcase TC_rll_est_ind() runs on test_CT {
5673 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005674 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005675 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005676 /* normal SAPI0 establishment */
5677 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005678 /* SAPI 3 doesn't support contention resolution */
5679 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5680 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5681 /* normal SAPI3 establishment on main DCCH */
5682 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5683 /* normal SAPI3 establishment on SACCH */
5684 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5685 };
5686 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5687}
5688
5689/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5690private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5691 var RllTestCase tc := g_pars.spec.rll;
5692 var L1ctlDlMessage dl;
5693 timer T := 3.0;
5694
5695 f_l1_tune(L1CTL);
5696 RSL.clear;
5697
5698 /* activate the logical channel */
5699 f_est_dchan();
5700 L1CTL.clear;
5701
5702 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5703 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5704 T.start;
5705 alt {
5706 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5707 var LapdmFrame lapdm;
5708 var octetstring l2 := dl.payload.data_ind.payload;
5709 if (dl.dl_info.link_id.c == SACCH) {
5710 /* remove L1 header */
5711 l2 := substr(l2, 2, lengthof(l2)-2);
5712 }
5713 lapdm.ab := dec_LapdmFrameAB(l2);
5714 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5715 setverdict(pass);
5716 } else {
5717 repeat;
5718 }
5719 }
5720 [] L1CTL.receive { repeat; }
5721 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005723 }
5724 }
5725
5726 f_rsl_chan_deact();
5727 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5728 f_rslem_unregister(0, g_chan_nr);
5729}
5730testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5731 var RllTestCases tcs := {
5732 /* normal SAPI3 establishment on main DCCH */
5733 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5734 };
5735 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5736}
5737testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5738 var RllTestCases tcs := {
5739 /* normal SAPI3 establishment on SACCH */
5740 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5741 }
5742 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5743}
5744
5745/* altstep to receive a LAPDm frame matching the given template */
5746private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5747 var L1ctlDlMessage dl;
5748 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5749 var LapdmFrame lapdm;
5750 var octetstring l2 := dl.payload.data_ind.payload;
5751 if (dl.dl_info.link_id.c == SACCH) {
5752 /* remove L1 header */
5753 l2 := substr(l2, 2, lengthof(l2)-2);
5754 }
5755 if (ischosen(exp.ab)) {
5756 lapdm.ab := dec_LapdmFrameAB(l2);
5757 } else if (ischosen(exp.b4)) {
5758 lapdm.b4 := dec_LapdmFrameB4(l2);
5759 } else if (ischosen(exp.bbis)) {
5760 lapdm.bbis := dec_LapdmFrameBbis(l2);
5761 }
5762 log("Rx LAPDm ", lapdm);
5763 if (match(lapdm, exp)) {
5764 setverdict(pass);
5765 } else {
5766 repeat;
5767 }
5768 }
5769 [] L1CTL.receive { repeat; }
5770}
5771private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5772 timer T := t;
5773 T.start;
5774 alt {
5775 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005777 }
5778 [] as_l1_exp_lapdm(exp);
5779 }
5780}
5781
5782/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5783private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5784 /* send SABM from MS -> BTS */
5785 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5786 /* expect RLL EST IND on Abis */
5787 alt {
5788 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5789 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5790 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005792 }
5793 [] RSL.receive { repeat; }
5794 }
5795 /* expect UA from BTS -> MS */
5796 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5797}
5798
5799/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5800private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5801 var RllTestCase tc := g_pars.spec.rll;
5802
5803 f_l1_tune(L1CTL);
5804 RSL.clear;
5805
5806 /* activate the logical channel */
5807 f_est_dchan();
5808 L1CTL.clear;
5809
5810 /* first establish the link-layer */
5811 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5812
5813 /* then send the DISC */
5814 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5815 /* ... and expect the REL IND on the RSL side */
5816 alt {
5817 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5818 setverdict(pass);
5819 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005820 /* We also expect to receive the measurements */
5821 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005822 }
5823
5824 /* release the channel */
5825 f_rsl_chan_deact();
5826 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5827 f_rslem_unregister(0, g_chan_nr);
5828}
5829testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5830 var RllTestCases tcs := {
5831 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5832 };
5833 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5834}
5835
5836testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5837 var RllTestCases tcs := {
5838 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5839 };
5840 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5841}
5842testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5843 var RllTestCases tcs := {
5844 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5845 };
5846 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5847}
5848testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5849 var RllTestCases tcs := {
5850 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5851 };
5852 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5853}
5854
5855/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5856private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5857 var RllTestCase tc := g_pars.spec.rll;
5858 f_l1_tune(L1CTL);
5859 RSL.clear;
5860
5861 /* activate the logical channel */
5862 f_est_dchan();
5863 L1CTL.clear;
5864
5865 /* first establish the link-layer */
5866 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5867
5868 /* then send the REL REQ via RSL */
5869 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5870 /* ... and expect the DISC on the Um side */
5871 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005872 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005873 /* FIXME: send a UA in resposne to the DISC */
5874 }
5875 }
5876
5877 /* release the channel */
5878 f_rsl_chan_deact();
5879 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5880 f_rslem_unregister(0, g_chan_nr);
5881}
5882testcase TC_rll_rel_req() runs on test_CT {
5883 var RllTestCases tcs := {
5884 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5885 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5886 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5887 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5888 };
5889 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5890}
5891
5892/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5893testcase TC_rll_data_req() runs on test_CT {
5894}
5895
5896/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5897testcase TC_rll_data_ind() runs on test_CT {
5898}
5899
5900/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5901private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5902 var RllTestCase tc := g_pars.spec.rll;
5903
5904 f_l1_tune(L1CTL);
5905 RSL.clear;
5906
5907 f_est_dchan();
5908 L1CTL.clear;
5909
5910 /* Send UNITDATA REQ on RSL side */
5911 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5912 /* Expect it to arrive on the other side */
5913 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005914 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005915 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005916 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005917 }
5918
5919 /* release the channel */
5920 f_rsl_chan_deact();
5921 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5922 f_rslem_unregister(0, g_chan_nr);
5923}
5924testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5925 var octetstring l3 := f_rnd_octstring(15);
5926 var RllTestCases tcs := {
5927 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5928 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5929 };
5930 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5931}
5932testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5933 var octetstring l3 := f_rnd_octstring(19);
5934 var RllTestCases tcs := {
5935 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5936 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5937 };
5938 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5939}
5940
5941/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5942private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5943 var RllTestCase tc := g_pars.spec.rll;
5944
5945 f_l1_tune(L1CTL);
5946 RSL.clear;
5947
5948 f_est_dchan();
5949 L1CTL.clear;
5950
5951 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005952 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005953 /* Expdct RLL UNITDATA IND on RSL side */
5954 alt {
5955 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5956 setverdict(pass);
5957 }
5958 [] RSL.receive { repeat; }
5959 }
5960
5961 /* release the channel */
5962 f_rsl_chan_deact();
5963 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5964 f_rslem_unregister(0, g_chan_nr);
5965}
5966testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005967 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005968 var RllTestCases tcs := {
5969 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5970 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5971 };
5972 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5973}
5974testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5975 var octetstring l3 := f_rnd_octstring(18);
5976 var RllTestCases tcs := {
5977 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5978 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5979 };
5980 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5981}
5982
Harald Weltee613f962018-04-18 22:38:16 +02005983/***********************************************************************
5984 * Encryption Related
5985 ***********************************************************************/
5986
5987/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5988function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5989 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5990 if (link_id.c == SACCH) {
5991 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5992 } else {
5993 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5994 }
5995}
5996
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005997/* Expect (or not expect) other kinds of messages */
5998private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5999 [exp_any] RSL.receive { repeat; }
6000 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006002 }
6003}
6004
Harald Weltee613f962018-04-18 22:38:16 +02006005/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006006private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006007 RslLinkId link_id,
6008 octetstring l3,
6009 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006010 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006011) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006012 timer T := 3.0;
6013 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6014 T.start;
6015 /* Expect RLL UNITDATA IND on RSL side */
6016 alt {
6017 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6018 setverdict(pass);
6019 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006020 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006021 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006022 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006024 }
Harald Weltee613f962018-04-18 22:38:16 +02006025 }
6026}
6027
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006028/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6029private function f_data_mo(
6030 RslLinkId link_id,
6031 boolean p, uint3_t nr, uint3_t ns,
6032 octetstring l3,
6033 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006034 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006035) runs on ConnHdlr {
6036 timer T := 3.0;
6037 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6038 T.start;
6039 /* Expect RLL DATA IND on RSL side */
6040 alt {
6041 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6042 setverdict(pass);
6043 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006044 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006045 [] as_rsl_any_ind(exp_any);
6046 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006048 }
6049 }
6050}
6051
Harald Weltee613f962018-04-18 22:38:16 +02006052/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
6053function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
6054 f_l1_tune(L1CTL);
6055 f_est_dchan(true);
6056
6057 /* now we actually need to transmit some data both ways to check if the encryption works */
6058 var L1ctlDlMessage dl;
6059
Stefan Sperling603d98e2018-07-25 16:47:28 +02006060 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006061 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6062
6063 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6064 f_unitdata_mt(link_id, l3);
6065
6066 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6067 f_unitdata_mo(link_id, l3);
6068
6069 /* release the channel */
6070 f_rsl_chan_deact();
6071 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6072 f_rslem_unregister(0, g_chan_nr);
6073}
6074testcase TC_chan_act_a51() runs on test_CT {
6075 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6076 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6077 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6078}
6079testcase TC_chan_act_a52() runs on test_CT {
6080 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6081 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6082 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6083}
6084testcase TC_chan_act_a53() runs on test_CT {
6085 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6086 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6087 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6088}
6089
Eric Wildf1827a72019-05-28 17:37:35 +02006090/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6091 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
6092function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
6093 f_l1_tune(L1CTL);
6094 f_est_dchan(true);
6095
6096 /* now we actually need to transmit some data both ways to check if the encryption works */
6097 var L1ctlDlMessage dl;
6098
6099 var octetstring l3 := f_rnd_octstring(20);
6100 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6101
6102 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6103 f_unitdata_mt(link_id, l3);
6104
6105 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6106 f_unitdata_mo(link_id, l3);
6107
6108 var RSL_Message rsl;
6109 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6110
6111 /* modify key to break proper encryption */
6112 g_pars.encr.key := f_rnd_octstring(8);
6113 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6114 rsl.ies := rsl.ies & { ei };
6115 RSL.send(rsl);
6116
6117 timer T0 := 1.0;
6118 T0.start;
6119 /* Expect RSL MODIFY ACK */
6120 alt {
6121 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6122 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6124 }
6125 [] T0.timeout {
6126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6127 }
6128 }
6129
6130 var octetstring l3msg := f_rnd_octstring(15);
6131 timer T1 := 3.0;
6132 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6133 due to broken encryption */
6134 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6135 T1.start;
6136 alt {
6137 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6139 }
6140 [] T1.timeout {
6141 setverdict(pass);
6142 }
6143 }
6144
6145 /* release the channel */
6146 f_rsl_chan_deact();
6147 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6148 f_rslem_unregister(0, g_chan_nr);
6149}
6150testcase TC_rsl_modify_encr() runs on test_CT {
6151 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6152 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6153 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6154}
Harald Weltee613f962018-04-18 22:38:16 +02006155
6156/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6157function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6158 /* L3 payload doesn't matter, as it is passed transparently */
6159 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6160 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6161 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6162
6163 f_l1_tune(L1CTL);
6164
6165 /* first establish a dedicated channel in the clear */
6166 f_est_dchan(false);
6167
6168 /* Establish ABM */
6169 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6170
6171 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6172 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6173 /* expect the L3 to arrive still unencrypted on the MS side */
6174 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6175
6176 /* configure L1 to apply ciphering */
6177 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6178 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6179
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006180 /* send first ciphered I-frame in response and expect it on RSL */
6181 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006182
6183 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6184 * and hence enable encryption also on the downlink */
6185
6186 /* expect bi-directional communication work in encrypted mode */
6187 f_unitdata_mo(link_id, f_rnd_octstring(15));
6188 f_unitdata_mt(link_id, f_rnd_octstring(15));
6189
6190 /* release the channel */
6191 f_rsl_chan_deact();
6192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6193 f_rslem_unregister(0, g_chan_nr);
6194}
6195testcase TC_encr_cmd_a51() runs on test_CT {
6196 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6197 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6198 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6199}
6200testcase TC_encr_cmd_a52() runs on test_CT {
6201 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6202 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6203 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6204}
6205testcase TC_encr_cmd_a53() runs on test_CT {
6206 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6207 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6208 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6209}
6210
6211private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6212 var LapdmFrame lf;
6213 var octetstring reenc;
6214
6215 /* decode the LAPDm frame */
6216 if (ischosen(exp_match.ab)) {
6217 lf.ab := dec_LapdmFrameAB(enc);
6218 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006220 }
6221
6222 /* check if decoder result matches expectation */
6223 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006225 } else {
6226 log(name, ": matched");
6227 setverdict(pass);
6228 }
6229
6230 /* test if re-encoded frame equals original input */
6231 reenc := enc_LapdmFrame(lf);
6232 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006234 } else {
6235 setverdict(pass);
6236 }
6237}
6238
6239testcase TC_lapdm_selftest() runs on test_CT {
6240 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6241 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6242 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6243 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6244 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6245 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6246 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6247}
6248
Stefan Sperling4880be42018-08-07 18:12:59 +02006249/***********************************************************************
6250 * DTX Related (see GSM 05.08, section 8.3)
6251 ***********************************************************************/
6252
6253/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6254function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6255 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6256 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6257 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6258 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6259}
6260function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6261 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6262 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6263}
6264function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6265 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6266 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6267 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6268 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6269}
6270function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6271 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6272 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6273 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6274 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6275 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6276 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6277 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6278 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6279}
6280
6281function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6282 var L1ctlDlMessage dl;
6283 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6284 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6285 var GsmFrameNumber first_fn;
6286 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006287 var integer nfill_frames_sacch := 0;
6288 var integer nfill_frames_nonsacch := 0;
6289 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006290 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6291 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006292 const integer frame_dtx_tchf_mod := 104;
6293 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6294 * which operates in terms of blocks rather than frames. */
6295 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6296 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006297 timer T := 5.0;
6298
6299 f_l1_tune(L1CTL);
6300 RSL.clear;
6301 L1CTL.clear;
6302
6303 /* activate TCHF signalling channel */
6304 f_est_dchan(false);
6305
6306 T.start;
6307 alt {
6308 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6309 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6310 var octetstring l2 := dl.payload.data_ind.payload;
6311
6312 if (is_first_frame) {
6313 is_first_frame := false;
6314 first_fn := dl.dl_info.frame_nr;
6315 }
6316
6317 if (dl.dl_info.link_id.c == SACCH) {
6318 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6319 if (not match(l2_fill_frame_sacch, l2)) {
6320 repeat;
6321 }
6322 } else if (not match(l2_fill_frame, l2)) {
6323 repeat;
6324 }
6325
6326 if (dtxd) {
6327 if (not f_g_chan_is_tchf()) {
6328 T.stop;
6329 f_rsl_chan_deact();
6330 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006331 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 +02006332 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006333 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006334 T.stop;
6335 f_rsl_chan_deact();
6336 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006337
6338 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6339 * 2 SACCH, 1 TCH/F */
6340 expected_fill_frames := 3;
6341
6342 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6343 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6344 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006346 } else {
6347 setverdict(pass);
6348 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006349 } else {
6350 if (dl.dl_info.link_id.c == SACCH) {
6351 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006352 repeat;
6353 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006354 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6355 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6356 * we should only see the subset of frames numbers which correspond to a block boundary.
6357 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6358 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6359 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6360 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6361 repeat;
6362 }
6363 }
6364 log("Received DTX TCH fill frame with bad frame number: ", fn,
6365 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6366 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6367 f_rsl_chan_deact();
6368 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006370 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006371 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006372 if (dl.dl_info.link_id.c == SACCH) {
6373 nfill_frames_sacch := nfill_frames_sacch + 1;
6374 } else {
6375 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6376 }
6377 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006378 T.stop;
6379 if (f_g_chan_is_tchf()) {
6380 /* Without DTX we can expect 25 fill frames for every 104 frames.
6381 * (24 FACCH + 1 SACCH filling) */
6382 expected_fill_frames := 25;
6383 } else if (f_g_chan_is_tchh()) {
6384 /* We can expect 2 fill frames for every 104 frames. */
6385 expected_fill_frames := 2;
6386 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6387 /* We can expect 5 fill frames for every 104 frames. */
6388 expected_fill_frames := 5;
6389 } else {
6390 f_rsl_chan_deact();
6391 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006393 }
6394
6395 f_rsl_chan_deact();
6396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006397
6398 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006399 setverdict(pass);
6400 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006401 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6402 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006404 }
6405 } else {
6406 repeat;
6407 }
6408 }
6409 }
6410 [] L1CTL.receive { repeat; }
6411 [] T.timeout {
6412 f_rsl_chan_deact();
6413 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006415 }
6416 }
6417}
6418
6419function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6420 f_test_l2_fill_frames(false);
6421}
6422
6423function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6424 f_test_l2_fill_frames(true);
6425}
6426
6427function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6428 var ConnHdlr vc_conn;
6429 var ConnHdlrPars pars;
6430 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006431 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006432 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6433 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6434 if (dtxd) {
6435 if (i >= 4) { /* DTX is only allowed on TCH/F */
6436 break;
6437 }
6438 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6439 } else {
6440 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6441 }
6442 vc_conn.done;
6443 }
6444}
6445
6446/* Verify that L2 fill frames are sent on TCH in signaling mode if
6447 * there is nothing to transmit while DTX is disabled on downlink. */
6448testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6449 f_tch_sign_l2_fill_frame(false);
6450}
6451
6452/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6453 * there is nothing to transmit while DTX is enabled on downlink. */
6454testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6455 f_tch_sign_l2_fill_frame(true);
6456}
Harald Welte0472ab42018-03-12 15:02:26 +01006457
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006458testcase TC_chopped_ipa_ping() runs on test_CT {
6459 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6460}
6461
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006462testcase TC_chopped_ipa_payload() runs on test_CT {
6463 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6464}
6465
Harald Welte0472ab42018-03-12 15:02:26 +01006466/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6467/* protocol error as per 44.006 */
6468/* link layer failure (repetition of I-frame N200 times without ACK */
6469/* repetition of SABM or DISC N200 times without ACK */
6470/* receptiom of SABM in multi-frame established state */
6471
6472
Harald Welte68e495b2018-02-25 00:05:57 +01006473/* TODO Areas:
6474
6475* channel activation
6476** with BS_Power / MS_Power, bypassing power control loop
6477** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006478** with timing advance from initial activation on
6479* mode modify
6480** encryption
6481** multirate
6482* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006483** unsupported algorithm
6484* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006485* BS Power Control
6486* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006487* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006488* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006489** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006490* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006491** DATA_IND from BTS->PCU
6492** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006493
6494*/
Harald Welte70767382018-02-21 12:16:40 +01006495
6496control {
6497 execute( TC_chan_act_stress() );
6498 execute( TC_chan_act_react() );
6499 execute( TC_chan_deact_not_active() );
6500 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006501 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006502 execute( TC_sacch_filling() );
6503 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006504 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006505 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006506 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006507 execute( TC_sacch_chan_act_ho_async() );
6508 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006509 execute( TC_rach_content() );
6510 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006511 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006512 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006513 execute( TC_rach_load_idle_thresh0() );
6514 execute( TC_rach_load_idle_below_thresh() );
6515 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006516 execute( TC_meas_res_sign_tchf() );
6517 execute( TC_meas_res_sign_tchh() );
6518 execute( TC_meas_res_sign_sdcch4() );
6519 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006520 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006521 execute( TC_tx_power_start_ramp_up_bcch() );
Eric Wildae8f2622019-06-18 17:05:11 +02006522 execute( TC_rsl_bs_pwr_static_ass() );
6523 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006524 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006525 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006526 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006527 execute( TC_rsl_ms_pwr_dyn_up() );
6528 execute( TC_rsl_ms_pwr_dyn_down() );
6529 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6530 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006531 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006532 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006533 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006534 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006535 execute( TC_paging_imsi_80percent() );
6536 execute( TC_paging_tmsi_80percent() );
6537 execute( TC_paging_imsi_200percent() );
6538 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006539 execute( TC_rsl_protocol_error() );
6540 execute( TC_rsl_mand_ie_error() );
6541 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006542 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006543 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006544 execute( TC_si_sched_2bis() );
6545 execute( TC_si_sched_2ter() );
6546 execute( TC_si_sched_2ter_2bis() );
6547 execute( TC_si_sched_2quater() );
6548 execute( TC_si_sched_13() );
6549 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006550 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006551 execute( TC_ipa_crcx_twice_not_active() );
6552 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006553 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006554 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006555
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006556 if (mp_pcu_socket != "") {
6557 execute( TC_pcu_act_req() );
6558 execute( TC_pcu_act_req_wrong_ts() );
6559 execute( TC_pcu_act_req_wrong_bts() );
6560 execute( TC_pcu_act_req_wrong_trx() );
6561 execute( TC_pcu_deact_req() );
6562 execute( TC_pcu_deact_req_wrong_ts() );
6563 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006564 if (mp_l1_supports_gprs) {
6565 execute( TC_pcu_data_req_pdtch() );
6566 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006567 execute( TC_pcu_data_req_wrong_bts() );
6568 execute( TC_pcu_data_req_wrong_trx() );
6569 execute( TC_pcu_data_req_wrong_ts() );
6570 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006571 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006572 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006573 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006574 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006575 execute( TC_pcu_data_req_imm_ass_pch() );
6576 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006577 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006578 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006579 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006580 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006581 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006582 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006583 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006584 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006585 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006586 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006587 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006588 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006589 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006590 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006591 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006592 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006593 execute( TC_dyn_osmo_pdch_act_deact() );
6594 execute( TC_dyn_osmo_pdch_double_act() );
6595 execute( TC_dyn_ipa_pdch_act_deact() );
6596 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6597
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006598 } else {
6599 log("PCU socket path not available, skipping PCU tests");
6600 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006601
Harald Welte3d04ae62018-04-04 20:29:05 +02006602 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006603 execute( TC_dyn_osmo_pdch_tchf_act() );
6604 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006605 execute( TC_dyn_ipa_pdch_tchf_act() );
6606 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006607
6608 execute( TC_rll_est_ind() );
6609 execute( TC_rll_est_req_DCCH_3() );
6610 execute( TC_rll_est_req_ACCH_3() );
6611 execute( TC_rll_rel_ind_DCCH_0() );
6612 execute( TC_rll_rel_ind_DCCH_3() );
6613 execute( TC_rll_rel_ind_ACCH_0() );
6614 execute( TC_rll_rel_ind_ACCH_3() );
6615 execute( TC_rll_rel_req() );
6616 execute( TC_rll_unit_data_req_DCCH() );
6617 execute( TC_rll_unit_data_req_ACCH() );
6618 execute( TC_rll_unit_data_ind_DCCH() );
6619 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006620
6621 execute( TC_chan_act_a51() );
6622 execute( TC_chan_act_a52() );
6623 execute( TC_chan_act_a53() );
6624 execute( TC_encr_cmd_a51() );
6625 execute( TC_encr_cmd_a52() );
6626 execute( TC_encr_cmd_a53() );
6627
Harald Welteee25aae2019-05-19 14:32:37 +02006628 execute( TC_err_rep_wrong_mdisc() );
6629 execute( TC_err_rep_wrong_msg_type() );
6630 execute( TC_err_rep_wrong_sequence() );
6631
Harald Weltee613f962018-04-18 22:38:16 +02006632 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006633
6634 execute( TC_tch_sign_l2_fill_frame() );
6635 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006636
6637 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006638 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006639}
6640
6641
6642}