blob: 8a297fb6ecfa669faf1ac7987c3b1492cff16f2e [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 Pedrol121724c2018-09-28 15:58:12 +0200103 integer mp_ms_actual_ta_exp := 0;
104 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100105 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200106 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200107 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200108 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
109 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100110}
111
Harald Welte629cc6b2018-03-11 17:19:05 +0100112type record of RslChannelNr ChannelNrs;
113
Harald Welte70767382018-02-21 12:16:40 +0100114type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100115 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100116 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100117 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100118 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100119 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100120 port RSL_CCHAN_PT RSL_CCHAN;
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700121 timer g_rslem_up_timer;
Harald Welte68e495b2018-02-25 00:05:57 +0100122
123 /* L1CTL port (for classic tests) */
124 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100125
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700126 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700127 port TRXC_CODEC_PT BTS_TRXC;
128 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100129
Harald Weltef50e3ae2018-09-10 10:27:56 +0200130 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100131 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200132 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100133
Harald Welte883340c2018-02-28 18:59:29 +0100134 /* PCU Interface of BTS */
135 port PCUIF_CODEC_PT PCU;
136 var integer g_pcu_conn_id;
137 /* Last PCU INFO IND we received */
138 var PCUIF_Message g_pcu_last_info;
139
Harald Welte48494ca2018-02-25 16:59:50 +0100140 /* SI configuration */
141 var SystemInformationConfig si_cfg := {
142 bcch_extended := false,
143 si1_present := false,
144 si2bis_present := false,
145 si2ter_present := false,
146 si2quater_present := false,
147 si7_present := false,
148 si8_present := false,
149 si9_present := false,
150 si13_present := false,
151 si13alt_present := false,
152 si15_present := false,
153 si16_present := false,
154 si17_present := false,
155 si2n_present := false,
156 si21_present := false,
157 si22_present := false
158 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100159
160 /* all logical channels available on the BTS */
161 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100162 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100163}
164
165/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200166type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100167 port L1CTL_PT L1CTL;
168
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700169 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700170 port TRXC_CODEC_PT BTS_TRXC;
171 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100172
173 timer g_Tguard;
174 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
175
176 var ConnHdlrPars g_pars;
177 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100178 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200179
180 /* PCU Interface of BTS */
181 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100182}
183
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700184private altstep as_rsl_init_guard() runs on test_CT {
185 [] g_rslem_up_timer.timeout {
186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
187 "Timeout waiting for RSL bring up");
188 }
189}
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700190
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700191function f_init_rsl(charstring id) runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100192 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
193 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
194
195 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
196 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
197 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
198
199 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
200 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700201
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700202 /* TTCN-3 offers no way to guard 'interleave' statements */
203 g_rslem_up_timer.start(mp_ipa_up_timeout);
204 var default d := activate(as_rsl_init_guard());
205
206 /* We expect all 4 transceivers to connect here (separate IPA/RSL connections).
207 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
208 interleave {
209 /* These events are sent by the RSL_Emulation_CT */
210 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX0));
211 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX1));
212 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX2));
213 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX3));
214 /* These messages (RF RESource INDication) are sent by the IUT itself */
215 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX0));
216 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX1));
217 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX2));
218 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX3));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700219 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220
221 g_rslem_up_timer.stop;
222 deactivate(d);
Harald Welte70767382018-02-21 12:16:40 +0100223}
224
225type record ConnHdlrPars {
226 RslChannelNr chan_nr,
227 RSL_IE_ChannelMode chan_mode,
228 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100229 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200230 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200231 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700232 BtsBand bts0_band optional,
233
234 /* Frequency hopping parameters (disabled if absent) */
235 MaioHsn maio_hsn optional,
236 /* MA bitmap to be indicated in RR Immediate Assignment */
237 MobileAllocation ma_map,
238 /* The actual Mobile Allocation (ARFCN list) to be used */
239 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100240}
241
242/* Test-specific parameters */
243type union TestSpecUnion {
244 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100245}
246
Harald Welte82ccef72018-02-25 16:17:33 +0100247template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100248 max_retrans := RACH_MAX_RETRANS_7,
249 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100250 cell_barr_access := false,
251 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100252 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100253};
254
Harald Weltef10153f2018-02-25 16:34:05 +0100255template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100256 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200257 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100258 acs := '0'B,
259 neci := true,
260 rxlev_access_min := 0
261}
262
263template (value) LocationAreaIdentification ts_LAI_default := {
264 mcc_mnc := '262F42'H,
265 lac := 42
266}
267
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700268private template (value) GPRSIndicator ts_GPRSIndicator_def := {
269 ra_colour := 0,
270 si13_pos := '0'B
271}
272
273private template (value) SI3RestOctets ts_SI3RestOctets_def
274modifies ts_SI3RestOctets := {
275 gprs_ind := {
276 presence := CSN1_H,
277 ind := ts_GPRSIndicator_def
278 }
279}
280
281private template (value) SI4RestOctets ts_SI4RestOctets_def
282modifies ts_SI4RestOctets := {
283 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700284 presence := CSN1_H,
285 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700286 }
287}
288
Harald Welte7484fc42018-02-24 14:09:45 +0100289/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100290template (value) SystemInformation ts_SI3_default := {
291 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100292 payload := {
293 si3 := {
294 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100295 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100296 ctrl_chan_desc := {
297 msc_r99 := true,
298 att := true,
299 bs_ag_blks_res := 1,
300 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100301 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100302 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
303 spare := '00'B,
304 bs_pa_mfrms := 0, /* 2 multiframes */
305 t3212 := 1 /* 6 minutes */
306 },
Harald Welte82ccef72018-02-25 16:17:33 +0100307 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100308 dn_ind := false,
309 pwrc := false,
310 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100311 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100312 },
Harald Weltef10153f2018-02-25 16:34:05 +0100313 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100314 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700315 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100316 }
317 }
318}
Harald Welte70767382018-02-21 12:16:40 +0100319
Harald Weltef8df4cb2018-03-10 15:15:08 +0100320template (value) SystemInformation ts_SI2_default := {
321 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100322 payload := {
323 si2 := {
324 bcch_freq_list := '00000000000000000000000000000000'O,
325 ncc_permitted := '11111111'B,
326 rach_control := ts_RachCtrl_default
327 }
328 }
329}
330
Harald Weltef8df4cb2018-03-10 15:15:08 +0100331template (value) SystemInformation ts_SI4_default := {
332 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100333 payload := {
334 si4 := {
335 lai := ts_LAI_default,
336 cell_sel_par := ts_CellSelPar_default,
337 rach_control := ts_RachCtrl_default,
338 cbch_chan_desc := omit,
339 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700340 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100341 }
342 }
343}
344
345function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
346runs on test_CT {
347 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700348 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100349}
350
351function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
352runs on test_CT {
353 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
354 log("Setting ", rsl_si_type, ": ", si_dec);
355 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
356}
357
Harald Welte505cf9b2018-09-15 17:47:23 +0300358friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100359 map(self:BTSVTY, system:BTSVTY);
360 f_vty_set_prompts(BTSVTY);
361 f_vty_transceive(BTSVTY, "enable");
362}
363
Harald Welte505cf9b2018-09-15 17:47:23 +0300364friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200365 map(self:BSCVTY, system:BSCVTY);
366 f_vty_set_prompts(BSCVTY, "OsmoBSC");
367 f_vty_transceive(BSCVTY, "enable");
368}
369
Harald Welte883340c2018-02-28 18:59:29 +0100370/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200371private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
372 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100373 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200374 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
375 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100376 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200377 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100379 }
380}
381
Harald Weltef26de0b2018-04-04 20:28:05 +0200382private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
383 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100384 timer T := 2.0;
385 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100386 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200387 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100388 return;
389 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200390 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100391
392 T.start;
393 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200394 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100395 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100397 }
398 }
399}
400
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700401private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
402 out integer trxc_conn_id) {
403 var Result res;
404
405 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
406 "", -1, -1, { udp := {} }, {});
407 if (not ispresent(res.connId)) {
408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
409 "Could not connect to the control (TRXC) interface " &
410 "of FakeTRX, check your configuration");
411 }
412 trxc_conn_id := res.connId;
413}
414
Harald Welte70767382018-02-21 12:16:40 +0100415/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200416function f_init() runs on test_CT {
417 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100418 g_AllChannels := {
419 /* TS 1..4: TCH/F */
420 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
421 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
422 /* TS 5: TCH/H */
423 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
424 /* TS 0: SDCCH/4 */
425 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
426 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
427 /* TS 6: SDCCH/8 */
428 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
429 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
430 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
431 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
432 };
433
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200434 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700435 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200436 g_AllChanTypes := {
437 /* TS 1..4: TCH/F */
438 valueof(ts_RslChanNr_Bm(1)),
439 /* TS 5: TCH/H */
440 valueof(ts_RslChanNr_Lm(5,1)),
441 /* TS 0: SDCCH/4 */
442 valueof(ts_RslChanNr_SDCCH4(0,2)),
443 /* TS 6: SDCCH/8 */
444 valueof(ts_RslChanNr_SDCCH8(6,4))
445 };
446 } else {
447 g_AllChanTypes := {
448 /* TS 1..4: TCH/F */
449 valueof(ts_RslChanNr_Bm(1)),
450 /* TS 0: SDCCH/4 */
451 valueof(ts_RslChanNr_SDCCH4(0,2)),
452 /* TS 6: SDCCH/8 */
453 valueof(ts_RslChanNr_SDCCH8(6,4))
454 };
455 }
Harald Welte70767382018-02-21 12:16:40 +0100456 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100457 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100458 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200459 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100460
461 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100462 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
463 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
464 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
465 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100466
Harald Weltef26de0b2018-04-04 20:28:05 +0200467 map(self:PCU, system:PCU);
468 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100469
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700470 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100471 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700472
473 /* Init TRXC interface to FakeTRX */
474 map(self:BTS_TRXC, system:BTS_TRXC);
475 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
476
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700477 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700478 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 +0700479 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700480 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
481 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100482 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200483
484 /* Wait some extra time to make sure the BTS emits a stable carrier.
485 * (this is only relevant when running the tests with a physical BTS.) */
486 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100487}
488
Harald Welte68e495b2018-02-25 00:05:57 +0100489/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
490function f_init_l1ctl() runs on test_CT {
491 map(self:L1CTL, system:L1CTL);
492 f_connect_reset(L1CTL);
493}
494
Harald Welte70767382018-02-21 12:16:40 +0100495type function void_fn(charstring id) runs on ConnHdlr;
496
497/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700498function f_start_handler(void_fn fn, ConnHdlrPars pars,
499 boolean pcu_comp := false,
500 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100501runs on test_CT return ConnHdlr {
502 var charstring id := testcasename();
503 var ConnHdlr vc_conn;
504
505 vc_conn := ConnHdlr.create(id);
506 /* connect to RSL Emulation main component */
507 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
508 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700509
510 /* The ConnHdlr component may want to talk to some ports directly,
511 * so we disconnect it from the test_CT and connect it to the component.
512 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200513 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200514 unmap(self:PCU, system:PCU);
515 map(vc_conn:PCU, system:PCU);
516 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700517 if (trxc_comp) {
518 unmap(self:BTS_TRXC, system:BTS_TRXC);
519 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
520 }
Harald Welte70767382018-02-21 12:16:40 +0100521
522 vc_conn.start(f_handler_init(fn, id, pars));
523 return vc_conn;
524}
525
Harald Welte70767382018-02-21 12:16:40 +0100526private altstep as_Tguard() runs on ConnHdlr {
527 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100529 }
530}
531
Harald Welte990a3612019-05-27 14:02:13 +0200532friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
533 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100534}
535
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700536private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100537 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700538 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100539}
540
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700541private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100542 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700543 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100544}
545
546/* first function started in ConnHdlr component */
547private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
548runs on ConnHdlr {
549 g_pars := pars;
550 g_chan_nr := pars.chan_nr;
551
552 map(self:L1CTL, system:L1CTL);
553 f_connect_reset(L1CTL);
554
Harald Welted48c0c72019-06-05 10:01:15 +0200555 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700556 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100557 }
Harald Welte70767382018-02-21 12:16:40 +0100558
559 g_Tguard.start(pars.t_guard);
560 activate(as_Tguard());
561
562 f_rslem_register(0, pars.chan_nr);
563
564 /* call the user-supplied test case function */
565 fn.apply(id);
566}
567
Harald Welteb1726c92018-03-30 11:56:38 +0200568function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
569 boolean ignore_other := false)
570runs on ConnHdlr return RSL_Message {
571 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100572 timer T := 3.0;
573 RSL.send(tx);
574 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100575 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200576 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100577 T.stop;
578 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100579 }
Harald Welte1eba3742018-02-25 12:48:14 +0100580 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100582 }
Harald Welte21240e62018-03-11 21:43:35 +0100583 [not ignore_other] as_l1_sacch();
584 [not ignore_other] as_meas_res();
585 [not ignore_other] as_l1_dcch();
586 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100588 }
Harald Welte21240e62018-03-11 21:43:35 +0100589 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100590 }
Harald Welteb1726c92018-03-30 11:56:38 +0200591 return rx;
592}
593
594function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
595 boolean ignore_other := false)
596runs on ConnHdlr {
597 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
Harald Welte8b01c792019-05-19 22:51:25 +0200600function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
601 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
602 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200603 if (encr_enable) {
604 /* append encryption related IEs, if requested */
605 var RSL_IE_EncryptionInfo encr_info;
606 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
607 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
608encr_info})) };
609 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200610 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200611 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100612}
613
Harald Welte70767382018-02-21 12:16:40 +0100614function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100615 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 +0100616 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100617}
618
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700619/* Default Mobile Allocation to be used for frequency hopping */
620private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
621 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
622
Harald Welte2f2b2b72019-05-31 22:24:57 +0200623friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100624 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700625 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100626 float t_guard := 20.0) := {
627 chan_nr := valueof(chan_nr),
628 chan_mode := valueof(chan_mode),
629 t_guard := t_guard,
630 l1_pars := {
631 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100632 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100633 meas_ul := {
634 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200635 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100636 rxqual := 0
637 },
638 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200639 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100640 rxqual := 0
641 }
642 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200643 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100644 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200645 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200646 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100647 },
Harald Weltee613f962018-04-18 22:38:16 +0200648 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200649 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700650 bts0_band := omit,
651 maio_hsn := maio_hsn,
652 ma_map := c_MA_null,
653 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100654}
655
Harald Welte93640c62018-02-25 16:59:33 +0100656/***********************************************************************
657 * Channel Activation / Deactivation
658 ***********************************************************************/
659
Harald Welte70767382018-02-21 12:16:40 +0100660/* Stress test: Do 500 channel activations/deactivations in rapid succession */
661function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
662 for (var integer i := 0; i < 500; i := i+1) {
663 f_rsl_chan_act(g_pars.chan_mode);
664 f_rsl_chan_deact();
665 }
666 setverdict(pass);
667}
668testcase TC_chan_act_stress() runs on test_CT {
669 var ConnHdlr vc_conn;
670 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200671 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100672 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
673 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100675}
676
677/* Test if re-activation of an already active channel fails as expected */
678function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
679 f_rsl_chan_act(g_pars.chan_mode);
680 /* attempt to activate the same lchan again -> expect reject */
681 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
682 alt {
683 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100685 }
686 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
687 setverdict(pass);
688 }
689 }
690 f_rsl_chan_deact();
691}
692testcase TC_chan_act_react() runs on test_CT {
693 var ConnHdlr vc_conn;
694 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100695 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100696 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
697 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100699}
700
701/* Attempt to de-activate a channel that's not active */
702function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
703 timer T := 3.0;
704 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
705 T.start;
706 alt {
707 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
708 setverdict(pass);
709 }
710 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100712 }
713 }
714}
715testcase TC_chan_deact_not_active() runs on test_CT {
716 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100717 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100718 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
719 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100721}
722
723/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
724function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
725 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
726 alt {
727 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100729 }
730 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
731 setverdict(pass);
732 }
733 }
734}
735private type record WrongChanNrCase {
736 RslChannelNr chan_nr,
737 charstring description
738}
739private type record of WrongChanNrCase WrongChanNrCases;
740private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
741 chan_nr := chan_nr,
742 description := desc
743}
744
745testcase TC_chan_act_wrong_nr() runs on test_CT {
746 var ConnHdlr vc_conn;
747 var ConnHdlrPars pars;
748
Harald Welte294b0a22018-03-10 23:26:48 +0100749 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100750
751 var WrongChanNrCases wrong := {
752 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
753 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
754 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
755 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
756 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
757 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
758 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
759 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
760 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
761 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
762 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
763 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
764 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
765 };
766
767 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
768 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
769 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
770 vc_conn.done;
771 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100773}
774
Harald Weltee613f962018-04-18 22:38:16 +0200775/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200776friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200777 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200778 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200779
780 /* test on each of the channels we have */
781 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
782 pars.chan_nr := valueof(g_AllChanTypes[i]);
783
784 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
785 vc_conn := f_start_handler(fn, pars);
786 vc_conn.done;
787 }
788
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200790}
791
Harald Welte93640c62018-02-25 16:59:33 +0100792/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100793 * SACCH handling
794 ***********************************************************************/
795
796private function f_exp_sacch(boolean exp) runs on ConnHdlr {
797 timer T_sacch := 3.0;
798 T_sacch.start;
799 alt {
800 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100802 }
803 [not exp] T_sacch.timeout {
804 setverdict(pass);
805 }
806 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
807 setverdict(pass);
808 }
809 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100811 }
812 [] L1CTL.receive { repeat; }
813 [] RSL.receive { repeat; }
814 }
815}
816
817/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
818private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
819 f_l1_tune(L1CTL);
820 RSL.clear;
821
822 /* activate the logical channel */
823 f_est_dchan();
824 L1CTL.clear;
825
826 /* check that SACCH actually are received as expected */
827 f_exp_sacch(true);
828
829 /* deactivate SACCH on the logical channel */
830 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
831 f_sleep(1.0);
832 L1CTL.clear;
833
834 /* check that no SACCH are received anymore */
835 f_exp_sacch(false);
836
837 /* release the channel */
838 f_rsl_chan_deact();
839 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
840}
841testcase TC_deact_sacch() runs on test_CT {
842 var ConnHdlr vc_conn;
843 var ConnHdlrPars pars;
844 f_init();
845 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
846 //for (var integer i := 0; i < 1; i := i+1) {
847 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
848 log(testcasename(), ": Starting for ", g_AllChannels[i]);
849 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
850 vc_conn.done;
851 }
852 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100854}
855
Harald Welte55700662018-03-12 13:15:43 +0100856/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100857private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
858 var L1ctlDlMessage dl;
859 /* check that the specified SI5 value is actually sent */
860 timer T_sacch := 3.0;
861 L1CTL.clear;
862 T_sacch.start;
863 alt {
864 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
865 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
866 if (match(l3, l3_exp)) {
867 setverdict(pass);
868 } else {
869 repeat;
870 }
871 }
872 [] L1CTL.receive { repeat; }
873 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100875 }
876 }
877}
878
Harald Welte55700662018-03-12 13:15:43 +0100879/* verify that given SACCH payload is not present */
880private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
881 var L1ctlDlMessage dl;
882 /* check that the specified SI5 value is actually sent */
883 timer T_sacch := 3.0;
884 L1CTL.clear;
885 T_sacch.start;
886 alt {
887 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
888 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
889 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100891 } else {
892 repeat;
893 }
894 }
895 [] L1CTL.receive { repeat; }
896 [] T_sacch.timeout {
897 setverdict(pass);
898 }
899 }
900}
901
Harald Welte629cc6b2018-03-11 17:19:05 +0100902/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100903private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
904 /* Set a known default SACCH filling for SI5 */
905 var octetstring si5 := f_rnd_octstring(19);
906 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
907
908 f_l1_tune(L1CTL);
909 RSL.clear;
910
911 /* activate the logical channel */
912 f_est_dchan();
913
914 /* check that the specified SI5 value is actually sent */
915 f_sacch_present(si5);
916
917 /* release the channel */
918 RSL.clear;
919 f_rsl_chan_deact();
920 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
921}
922testcase TC_sacch_filling() runs on test_CT {
923 var ConnHdlr vc_conn;
924 var ConnHdlrPars pars;
925 f_init();
926 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
927 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
928 log(testcasename(), ": Starting for ", g_AllChannels[i]);
929 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
930 vc_conn.done;
931 }
932 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100934}
935
Harald Welte629cc6b2018-03-11 17:19:05 +0100936/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100937private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
938 /* Set a known default SACCH filling for SI5 */
939 var octetstring si5 := f_rnd_octstring(19);
940 var octetstring si5_diff := f_rnd_octstring(19);
941 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
942
943 f_l1_tune(L1CTL);
944 RSL.clear;
945
946 log("Activating channel, expecting standard SI5");
947 /* activate the logical channel */
948 f_est_dchan();
949 /* check that the specified SI5 value is actually sent */
950 f_sacch_present(si5);
951
952 /* set channel-specific different SI5 */
953 log("Setting channel specific SACCH INFO, expecting it");
954 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
955 /* check that the specified lchan-specific value is now used */
956 f_sacch_present(si5_diff);
957
958 /* deactivate the channel and re-activate it, this should result in default SI5 */
959 log("De-activating and re-activating channel, expecting standard SI5");
960 f_rsl_chan_deact();
961 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
962 /* Verify that the TRX-wide default SACCH filling is present again */
963 f_sacch_present(si5);
964
965 /* release the channel */
966 RSL.clear;
967 f_rsl_chan_deact();
968 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
969}
970testcase TC_sacch_info_mod() runs on test_CT {
971 var ConnHdlr vc_conn;
972 var ConnHdlrPars pars;
973 f_init();
974 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
975 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
976 log(testcasename(), ": Starting for ", g_AllChannels[i]);
977 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
978 vc_conn.done;
979 }
980 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100982}
983
Harald Welte075d84c2018-03-12 13:07:24 +0100984/* Test SACCH scheduling of multiple different SI message types */
985private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
986 var octetstring si5 := f_rnd_octstring(19);
987 var octetstring si5bis := f_rnd_octstring(19);
988 var octetstring si5ter := f_rnd_octstring(19);
989 var octetstring si6 := f_rnd_octstring(19);
990
991 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
992 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
993 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
994 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
995
996 f_l1_tune(L1CTL);
997 RSL.clear;
998
999 /* activate the logical channel */
1000 f_est_dchan();
1001 L1CTL.clear;
1002
1003 /* check that SACCH actually are received as expected */
1004 f_sacch_present(si5);
1005 f_sacch_present(si5bis);
1006 f_sacch_present(si5ter);
1007 f_sacch_present(si6);
1008
1009 /* release the channel */
1010 f_rsl_chan_deact();
1011 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1012}
1013testcase TC_sacch_multi() runs on test_CT {
1014 var ConnHdlr vc_conn;
1015 var ConnHdlrPars pars;
1016 f_init();
1017 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1018 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1019 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1020 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1021 vc_conn.done;
1022 }
1023 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001025}
1026
Harald Welte55700662018-03-12 13:15:43 +01001027/* Test if SACH information is modified as expected */
1028private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1029 var octetstring si5 := f_rnd_octstring(19);
1030 var octetstring si6 := f_rnd_octstring(19);
1031
1032 /* First, configure both SI5 and SI6 to be transmitted */
1033 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1034 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1035
1036 f_l1_tune(L1CTL);
1037 RSL.clear;
1038
1039 /* activate the logical channel */
1040 f_est_dchan();
1041 L1CTL.clear;
1042
1043 /* check that SACCH actually are received as expected */
1044 f_sacch_present(si5);
1045 f_sacch_present(si6);
1046
1047 /* disable SI6 */
1048 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1049
1050 /* check that SI5 is still transmitted */
1051 f_sacch_present(si5);
1052 /* check if SI6 is now gone */
1053 f_sacch_missing(si6);
1054
1055 /* release the channel */
1056 f_rsl_chan_deact();
1057 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1058}
1059testcase TC_sacch_multi_chg() runs on test_CT {
1060 var ConnHdlr vc_conn;
1061 var ConnHdlrPars pars;
1062 f_init();
1063 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1064 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1065 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1066 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1067 vc_conn.done;
1068 }
1069 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001071}
1072
Harald Weltec8d363c2019-05-19 20:36:48 +02001073/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1074private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1075 var octetstring si5 := f_rnd_octstring(19);
1076 var octetstring si6 := f_rnd_octstring(19);
1077 var octetstring si5_specific := f_rnd_octstring(19);
1078 var octetstring si6_specific := f_rnd_octstring(19);
1079
1080 /* First, configure both SI5 and SI6 to be transmitted */
1081 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1082 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1083
1084 f_l1_tune(L1CTL);
1085 RSL.clear;
1086
1087 /* activate channel with different SACCH filling */
1088 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1089 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1090 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1091 }));
1092 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1093 RSL_IE_Body:{sacch_info := sacch_info})) };
1094 f_est_dchan(more_ies := addl_ies);
1095
1096 /* check that SACCH actually are received as expected */
1097 f_sacch_present(si5_specific);
1098 f_sacch_present(si6_specific);
1099
1100 /* release the channel */
1101 f_rsl_chan_deact();
1102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1103}
1104testcase TC_sacch_chan_act() runs on test_CT {
1105 var ConnHdlr vc_conn;
1106 var ConnHdlrPars pars;
1107 f_init();
1108
1109 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1110 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1111 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1112 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1113 vc_conn.done;
1114 }
1115 /* TODO: do the above in parallel, rather than sequentially? */
1116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1117}
1118
Harald Welte8b01c792019-05-19 22:51:25 +02001119/* verify that SACCH DL transmission is started only if MS power IE present
1120 * see section 4.1.3 of 3GPP TS 48.058 */
1121private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1122 var octetstring si5 := f_rnd_octstring(19);
1123
1124 f_l1_tune(L1CTL);
1125 RSL.clear;
1126
1127 /* Step 1: Activate ASYNC HO channel without MS power IE */
1128
1129 /* Activate channel on BTS side */
1130 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1131 /* don't perform immediate assignment here, as we're testing non-IA case */
1132 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001133 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001134
1135 /* Verify that no DL SACCH is being received */
1136 f_sacch_missing(?);
1137
1138 f_rsl_chan_deact();
1139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1140
1141
1142 /* Step 2: Activate ASYNC HO channel with MS power IE */
1143
1144 /* Activate channel on BTS side */
1145 var RSL_IE_List addl_ies := {
1146 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1147 };
1148 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1149 /* don't perform immediate assignment here, as we're testing non-IA case */
1150 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001151 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001152
1153 /* Verify that DL SACCH is being received */
1154 f_sacch_present(si5);
1155
1156 f_rsl_chan_deact();
1157 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1158}
1159testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1160 var ConnHdlr vc_conn;
1161 var ConnHdlrPars pars;
1162 f_init();
1163
1164 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1165 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1166 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1167 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1168 vc_conn.done;
1169 }
1170 /* TODO: do the above in parallel, rather than sequentially? */
1171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1172}
1173
1174/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1175 * see section 4.1.4 of 3GPP TS 48.058 */
1176private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1177 var octetstring si5 := f_rnd_octstring(19);
1178 var RSL_IE_List addl_ies;
1179
1180 f_l1_tune(L1CTL);
1181 RSL.clear;
1182
1183 /* Step 1: Activate SYNC HO channel without MS power IE */
1184
1185 /* Activate channel on BTS side */
1186 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1187 /* don't perform immediate assignment here, as we're testing non-IA case */
1188 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001189 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001190
1191 /* Verify that no DL SACCH is being received */
1192 f_sacch_missing(?);
1193
1194 f_rsl_chan_deact();
1195 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1196
1197
1198 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1199
1200 /* Activate channel on BTS side */
1201 addl_ies := {
1202 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1203 };
1204 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1205 /* don't perform immediate assignment here, as we're testing non-IA case */
1206 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001207 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001208
1209 /* Verify that no DL SACCH is being received */
1210 f_sacch_missing(?);
1211
1212 f_rsl_chan_deact();
1213 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1214
1215
1216 /* Step 2b: Activate SYNC HO channel with TA IE */
1217
1218 /* Activate channel on BTS side */
1219 addl_ies := {
1220 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1221 };
1222 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1223 /* don't perform immediate assignment here, as we're testing non-IA case */
1224 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001225 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001226
1227 /* Verify that no DL SACCH is being received */
1228 f_sacch_missing(?);
1229
1230 f_rsl_chan_deact();
1231 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1232
1233
1234 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1235
1236 /* Activate channel on BTS side */
1237 addl_ies := {
1238 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1239 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1240 };
1241 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1242 /* don't perform immediate assignment here, as we're testing non-IA case */
1243 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001244 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001245
1246 /* Verify that DL SACCH is being received */
1247 f_sacch_present(si5);
1248
1249 f_rsl_chan_deact();
1250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1251}
1252testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1253 var ConnHdlr vc_conn;
1254 var ConnHdlrPars pars;
1255 f_init();
1256
1257 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1258 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1259 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1260 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1261 vc_conn.done;
1262 }
1263 /* TODO: do the above in parallel, rather than sequentially? */
1264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1265}
Harald Welte629cc6b2018-03-11 17:19:05 +01001266
1267
1268/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001269 * RACH Handling
1270 ***********************************************************************/
1271
Harald Welte8c24c2b2018-02-26 08:31:31 +01001272/* like L1SAP_IS_PACKET_RACH */
1273private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001274 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001275 return true;
1276 }
1277 return false;
1278}
1279
1280/* generate a random RACH for circuit-switched */
1281private function f_rnd_ra_cs() return OCT1 {
1282 var OCT1 ra;
1283 do {
1284 ra := f_rnd_octstring(1);
1285 } while (ra_is_ps(ra));
1286 return ra;
1287}
1288
Harald Welte883340c2018-02-28 18:59:29 +01001289/* generate a random RACH for packet-switched */
1290private function f_rnd_ra_ps() return OCT1 {
1291 var OCT1 ra;
1292 do {
1293 ra := f_rnd_octstring(1);
1294 } while (not ra_is_ps(ra));
1295 return ra;
1296}
1297
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001298/* generate a random 11-bit RA (packet-switched only) */
1299private function f_rnd_ra11_ps() return BIT11 {
1300 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1301 return int2bit(ra11, 11);
1302}
1303
Harald Welte8c24c2b2018-02-26 08:31:31 +01001304/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1305testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001306 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001307 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001308 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001309
Harald Welte8c24c2b2018-02-26 08:31:31 +01001310 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001311 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001312 for (var integer i := 0; i < 1000; i := i+1) {
1313 var OCT1 ra := f_rnd_ra_cs();
1314 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1315 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001317 }
1318 fn_last := fn;
1319
1320 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001321 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001322 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001323 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001324 T.stop;
1325 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001326 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001328 }
1329 [] RSL_CCHAN.receive { repeat; }
1330 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001331 test_failed := true;
1332 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001333 }
1334 }
1335 }
Maxba06feb2019-03-05 10:52:46 +01001336 if (test_failed) {
1337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001338 }
Maxba06feb2019-03-05 10:52:46 +01001339 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001341}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001342
1343/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1344testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001345 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001346 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001347 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001348 f_l1_tune(L1CTL);
1349
1350 var GsmFrameNumber fn_last := 0;
1351 for (var integer i := 0; i < 1000; i := i+1) {
1352 var OCT1 ra := f_rnd_ra_cs();
1353 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1354 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001356 }
1357 fn_last := fn;
1358 }
1359 var integer rsl_chrqd := 0;
1360 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001361 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001362 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001363 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001364 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001365 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001366 repeat;
1367 }
1368 [] RSL_CCHAN.receive { repeat; }
1369 [] T.timeout { }
1370 }
1371 if (rsl_chrqd == 1000) {
1372 setverdict(pass);
1373 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001375 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001377}
1378
Harald Welte3453ab42019-05-24 21:19:58 +02001379private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1380 var charstring bts_str := "bts " & int2str(bts_nr);
1381 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1382}
1383
1384/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1385private template integer tr_rach_slots_per_interval := (90 .. 130);
1386
1387/* Expect 0 RACH load on an idle BTS that has just started up */
1388testcase TC_rach_load_idle_thresh0() runs on test_CT {
1389 var ASP_RSL_Unitdata rx_ud;
1390
1391 f_init_vty_bsc();
1392 /* send load indications even at 0% load */
1393 f_vty_load_ind_thresh(0);
1394 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1395 f_sleep(2.0);
1396
1397 f_init();
1398
1399 timer T := 5.0;
1400 T.start;
1401 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001402 [] 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 +02001403 setverdict(pass);
1404 repeat;
1405 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001406 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001407 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1408 repeat;
1409 }
1410 [] RSL_CCHAN.receive {
1411 repeat;
1412 }
1413 [] T.timeout { }
1414 }
1415
1416 f_vty_load_ind_thresh(10);
1417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1418}
1419
1420/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1421testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1422 var ASP_RSL_Unitdata rx_ud;
1423
1424 f_init_vty_bsc();
1425 f_init();
1426
1427 timer T := 5.0;
1428 T.start;
1429 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001430 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001431 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1432 repeat;
1433 }
1434 [] RSL_CCHAN.receive {
1435 repeat;
1436 }
1437 [] T.timeout {
1438 setverdict(pass);
1439 }
1440 }
1441
1442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1443}
1444
1445/* Expect 0 RACH load on an idle BTS that has just started up */
1446testcase TC_rach_load_count() runs on test_CT {
1447 var ASP_RSL_Unitdata rx_ud;
1448 var integer load_access_count := 0;
1449
1450 f_init_vty_bsc();
1451 /* send load indications even at 0% load */
1452 f_vty_load_ind_thresh(0);
1453 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1454 f_sleep(2.0);
1455 f_init();
1456
1457 f_init_l1ctl();
1458 f_sleep(1.0);
1459 f_l1_tune(L1CTL);
1460
1461 var GsmFrameNumber fn_last := 0;
1462 for (var integer i := 0; i < 1000; i := i+1) {
1463 var OCT1 ra := f_rnd_ra_cs();
1464 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1465 if (fn == fn_last) {
1466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1467 }
1468 fn_last := fn;
1469 }
1470
1471 timer T := 5.0;
1472 T.start;
1473 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001474 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001475 -> value rx_ud {
1476 var RSL_IE_Body ie;
1477 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1478 load_access_count := load_access_count + ie.rach_load.access_count;
1479 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1480 setverdict(fail, "Access count cannot be < Busy count");
1481 }
1482 repeat;
1483 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001484 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001485 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1486 repeat;
1487 }
1488 [] RSL_CCHAN.receive {
1489 repeat;
1490 }
1491 [] T.timeout { }
1492 }
1493 if (load_access_count == 1000) {
1494 setverdict(pass);
1495 } else {
1496 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1497 }
1498
1499 f_vty_load_ind_thresh(10);
1500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1501}
1502
Harald Welte54a2a2d2018-02-26 09:14:05 +01001503private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001504 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001505 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001506 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001507 f_sleep(0.5);
1508
1509 /* Transmit RACH request + wait for confirmation */
1510 var OCT1 ra := f_rnd_ra_cs();
1511 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1512
1513 /* Check for expected result */
1514 timer T := 1.5;
1515 T.start;
1516 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001517 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001518 setverdict(pass);
1519 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001520 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001522 }
1523 [] RSL_CCHAN.receive { repeat; }
1524 [not expect_pass] T.timeout {
1525 setverdict(pass);
1526 }
1527 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001529 }
1530 }
1531}
1532
1533/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1534testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001535 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001536 f_init_l1ctl();
1537 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001538 f_sleep(1.0);
1539
1540 /* default max-ta is 63 (full range of GSM timing advance */
1541
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001542 /* We allow early arrival up to 2 symbols */
1543 f_rach_toffs(-1*256, true);
1544 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001545 f_rach_toffs(-10*256, false);
1546
1547 /* 0 / 32 / 63 bits is legal / permitted */
1548 f_rach_toffs(0, true);
1549 f_rach_toffs(32*256, true);
1550 f_rach_toffs(63*256, true);
1551
1552 /* more than 63 bits is not legal / permitted */
1553 f_rach_toffs(64*256, false);
1554 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001556}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001557
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001558function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1559 var GsmFrameNumber fn;
1560 var RSL_Message rm;
1561
1562 f_l1_tune(L1CTL);
1563 RSL.clear;
1564
1565 /* Generate a random Handover Reference */
1566 var integer ho_ref := oct2int(f_rnd_octstring(1));
1567
1568 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1569 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1570 RSL_IE_Body:{ handover_ref := ho_ref }));
1571
1572 /* Activate a channel on the BTS side (no encryption) */
1573 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1574 act_type := t_RSL_IE_ActType_HO_SYNC);
1575
1576 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1577 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001578 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001579
1580 /* Send handover Access Burst */
1581 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1582
1583 /* TODO: test mismatching Handover Reference, and missing IE */
1584
1585 /* Wait for handover detection */
1586 timer T := 3.0;
1587 T.start;
1588 alt {
1589 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1590 log("Handover RACH has been detected: ", rm);
1591 setverdict(pass);
1592 }
1593 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1595 log2str("RSL_CHAN_RQD was not expected: ", rm));
1596 }
1597 [] RSL.receive { repeat; }
1598 [] T.timeout {
1599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1600 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1601 }
1602 }
1603
1604 /* Release the channel */
1605 f_rsl_chan_deact();
1606 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1607}
1608
1609/* Test handover RACH detection */
1610testcase TC_ho_rach() runs on test_CT {
1611 var ConnHdlrPars pars;
1612 var ConnHdlr vc_conn;
1613
1614 f_init();
1615
1616 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1617 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1618 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1619 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1620 vc_conn.done;
1621 }
1622
1623 /* TODO: do the above in parallel, rather than sequentially? */
1624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1625}
1626
Harald Welte93640c62018-02-25 16:59:33 +01001627/***********************************************************************
1628 * Measurement Processing / Reporting
1629 ***********************************************************************/
1630
Harald Welte70767382018-02-21 12:16:40 +01001631template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1632 spare := '0'B,
1633 lpd := 0,
1634 sapi := sapi,
1635 c_r := c_r,
1636 ea := true
1637}
1638
Harald Welted879bd92018-03-12 15:01:23 +01001639template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001640 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001641 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001642 len := 0, /* overwritten */
1643 m := false,
1644 el := 1,
1645 payload := pl
1646}
1647
1648/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1649altstep as_l1_sacch() runs on ConnHdlr {
1650 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001651 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001652 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001653 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 +01001654 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001655 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001656
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001657 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1658 g_pars.l1_pars.ms_power_level, false,
1659 g_pars.l1_pars.ms_actual_ta);
1660
1661 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1662 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1663
1664 log("Sending Measurement Report: ", l1h, l2);
1665 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001666 repeat;
1667 }
1668}
1669
1670altstep as_l1_dcch() runs on ConnHdlr {
1671 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001672 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001673 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1674 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001675 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1676 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001677 repeat;
1678 }
1679}
1680
1681type record MeasElem {
1682 uint6_t rxlev,
1683 uint3_t rxqual
1684}
1685
1686type record MeasElemFS {
1687 MeasElem full,
1688 MeasElem sub
1689}
1690
1691type record ConnL1Pars {
1692 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001693 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001694 MeasElemFS meas_ul,
1695 int16_t timing_offset_256syms,
1696 uint5_t bs_power_level,
1697 uint5_t ms_power_level,
1698 uint8_t ms_actual_ta
1699}
1700
1701/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1702private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1703 return 63 + (toffs256s/256);
1704}
1705
Harald Welted5684392018-03-10 18:22:04 +01001706private function f_max(integer a, integer b) return integer {
1707 if (a > b) {
1708 return a;
1709 } else {
1710 return b;
1711 }
1712}
1713
1714private function f_min(integer a, integer b) return integer {
1715 if (a < b) {
1716 return a;
1717 } else {
1718 return b;
1719 }
1720}
1721
1722/* compute negative tolerance val-tolerance, ensure >= min */
1723private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1724 val := val - tolerance;
1725 return f_max(val, min);
1726}
1727
1728/* compute positive tolerance val+tolerance, ensure <= max */
1729private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1730 val := val + tolerance;
1731 return f_min(val, max);
1732}
1733
1734/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1735private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1736return template integer {
1737 var template integer ret;
1738 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1739 return ret;
1740}
1741
1742
Harald Welte70767382018-02-21 12:16:40 +01001743/* build a template for matching measurement results against */
1744private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1745 var ConnL1Pars l1p := g_pars.l1_pars;
1746 var template RSL_IE_UplinkMeas ul_meas := {
1747 len := 3,
1748 rfu := '0'B,
1749 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001750 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001751 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001752 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001753 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001754 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1755 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001756 supp_meas_info := omit
1757 };
Harald Welte685d5982018-02-27 20:42:05 +01001758 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001759 ul_meas.len := (3+8);
1760 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001761 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001762 toa256_min := ?,
1763 toa256_max := ?,
1764 toa256_std_dev := ?
1765 }
Harald Welte685d5982018-02-27 20:42:05 +01001766 }
Harald Welte70767382018-02-21 12:16:40 +01001767 var template RSL_IE_BS_Power bs_power := {
1768 reserved := 0,
1769 epc := false,
1770 fpc := false,
1771 power_level := l1p.bs_power_level
1772 };
1773 var template RSL_IE_L1Info l1_info := {
1774 ms_power_lvl := l1p.ms_power_level,
1775 fpc := false,
1776 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001777 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001778 };
1779 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001780 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001781 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1782 ?, t_toffs);
1783}
1784
Philipp Maierdd841d32019-12-17 14:44:54 +01001785/* build a template for matching measurement results that do not contain any
1786 * MS related measurement (l1_info, l3_info and ms timing offset). */
1787private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1788 var ConnL1Pars l1p := g_pars.l1_pars;
1789 var template RSL_IE_UplinkMeas ul_meas := {
1790 len := 3,
1791 rfu := '0'B,
1792 dtx_d := l1p.dtx_enabled,
1793 rxlev_f_u := ?,
1794 reserved1 := '00'B,
1795 rxlev_s_u := ?,
1796 reserved2 := '00'B,
1797 rxq_f_u := ?,
1798 rxq_s_u := ?,
1799 supp_meas_info := omit
1800 };
1801 if (l1p.toa256_enabled) {
1802 ul_meas.len := (3+8);
1803 ul_meas.supp_meas_info := {
1804 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1805 toa256_min := ?,
1806 toa256_max := ?,
1807 toa256_std_dev := ?
1808 }
1809 }
1810 var template RSL_IE_BS_Power bs_power := {
1811 reserved := 0,
1812 epc := false,
1813 fpc := false,
1814 power_level := l1p.bs_power_level
1815 };
1816
1817 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1818}
1819
Harald Welte70767382018-02-21 12:16:40 +01001820/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001821altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001822 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001823 var boolean chan_est := false;
1824
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001825 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001826
1827 /* Receive osmocom specific measurement reports. This is the normal
1828 * case. Here we verify that the measurement reports we sent are
1829 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001830 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1831 /* increment counter of next to-be-expected meas rep */
1832 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1833 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001834 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001835
1836 /* The following two cases may only happen in the beginning
1837 * of the channel establishment phase. Once we have received
1838 * the "our" measurement report the first time, the channel
1839 * is established and empty or hardcoded TRXCON reports must
1840 * not occur anymore. */
1841 chan_est := true;
1842
1843 repeat;
1844 }
1845
1846 /* When the BTS has established the channel, the MS might need slightly
1847 * more time to establish the channel and actually start sending. The
1848 * result is then a measurement report that just lacks the measurement
1849 * information of the MS. This is normal and we tolerate this behavior. */
1850 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1851 /* increment counter of next to-be-expected meas rep */
1852 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1853 /* Re-start the timer expecting the next MEAS RES */
1854 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001855 repeat;
1856 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001857
1858 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1859 * measurements if the TTCN3 side does not supply measurement input in
1860 * time. In those cases TRXCON will either use a cached measurement
1861 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1862 * report the templates above will not match. We tolerate this
1863 * behavior, but only once. */
1864 [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 +01001865 /* increment counter of next to-be-expected meas rep */
1866 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1867 if (g_first_meas_res) {
1868 g_first_meas_res := false;
1869 repeat;
1870 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001872 }
Harald Welte70767382018-02-21 12:16:40 +01001873 }
1874 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001876 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001877 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001879 }
1880}
1881
Harald Weltee613f962018-04-18 22:38:16 +02001882private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1883 select (rsl_alg_id) {
1884 case (RSL_ALG_ID_A5_0) { return 0; }
1885 case (RSL_ALG_ID_A5_1) { return 1; }
1886 case (RSL_ALG_ID_A5_2) { return 2; }
1887 case (RSL_ALG_ID_A5_3) { return 3; }
1888 case (RSL_ALG_ID_A5_4) { return 4; }
1889 case (RSL_ALG_ID_A5_5) { return 5; }
1890 case (RSL_ALG_ID_A5_6) { return 6; }
1891 case (RSL_ALG_ID_A5_7) { return 7; }
1892 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1894 /* Make compiler happy by calling mtc.stop here. It is already
1895 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001896 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001897 }
1898 }
1899}
1900
1901private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1902 select (rsl_alg_id) {
1903 case (RSL_ALG_ID_A5_1) { return '000'B; }
1904 case (RSL_ALG_ID_A5_2) { return '001'B; }
1905 case (RSL_ALG_ID_A5_3) { return '010'B; }
1906 case (RSL_ALG_ID_A5_4) { return '011'B; }
1907 case (RSL_ALG_ID_A5_5) { return '100'B; }
1908 case (RSL_ALG_ID_A5_6) { return '101'B; }
1909 case (RSL_ALG_ID_A5_7) { return '110'B; }
1910 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1912 /* Make compiler happy by calling mtc.stop here. It is already
1913 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001914 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001915 }
1916 }
1917}
1918
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001919/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1920private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1921 var GsmFrameNumber fn;
1922 timer T := 8.0;
1923
1924 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1925 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1926
1927 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1928 /* Send the actual RACH */
1929 fn := f_L1CTL_RACH(L1CTL, ra);
1930
1931 T.start;
1932 alt {
1933 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1934 [] T.timeout {
1935 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1936 }
1937 }
1938 T.stop
1939 return fn;
1940}
Harald Weltee613f962018-04-18 22:38:16 +02001941
Harald Welte70767382018-02-21 12:16:40 +01001942/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001943private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001944 var GsmFrameNumber fn;
1945 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001946 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001947 var integer ra := 23;
1948
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001949 /* Send RACH request and wait for ChanReq */
1950 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001951
1952 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001953 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001954
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001955 /* Craft channel description (with or without frequency hopping parameters) */
1956 if (ispresent(g_pars.maio_hsn)) {
1957 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1958 } else {
1959 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1960 }
1961
Harald Welte70767382018-02-21 12:16:40 +01001962 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001963 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001964 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1965
1966 /* receive IMM.ASS on MS side */
1967 var ImmediateAssignment ia_um;
1968 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001969
1970 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1971 if (ch_desc.h != ia_um.chan_desc.h) {
1972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1973 }
1974
Harald Welte70767382018-02-21 12:16:40 +01001975 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001976 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001977 /* enable encryption, if requested */
1978 if (encr_enable) {
1979 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1980 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1981 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001982
1983 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001984}
1985
1986/* establish DChan, verify existance + contents of measurement reports */
1987function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001988 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001989 RSL.clear;
1990
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001991 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001992 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001993 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001994 }
Harald Welte70767382018-02-21 12:16:40 +01001995
1996 f_est_dchan();
1997
1998 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1999 * RSL measurement reports on Abis side */
2000 timer T := 8.0;
2001 T.start;
2002 alt {
2003 [] as_l1_sacch();
2004 [] as_meas_res();
2005 [] as_l1_dcch();
2006 [] L1CTL.receive { repeat; }
2007 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002008 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002009 * of any earlier errors, so if we reach this timeout, we're good */
2010 setverdict(pass);
2011 }
2012 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002014 }
2015 }
2016 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002017 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002018}
Harald Welte0472ab42018-03-12 15:02:26 +01002019
Eric Wildae8f2622019-06-18 17:05:11 +02002020function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
2021 timer T := 8.0;
2022 T.start;
2023 var RSL_Message rsl;
2024 alt {
2025 [] as_l1_sacch();
2026 [] L1CTL.receive { repeat; }
2027 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2028 if (rsl.ies[3].body.bs_power.power_level == level) {
2029 setverdict(pass)
2030 } else {
2031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2032 }
2033 }
2034 [] T.timeout {
2035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2036 }
2037 }
2038}
2039
2040/* see if the rsl meas res contains our expeced bs power level
2041bs power set during assignment */
2042function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2043 f_l1_tune(L1CTL);
2044 RSL.clear;
2045
2046 if (mp_bts_trxc_port != -1) {
2047 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2048 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2049 }
2050
2051 var uint5_t pwr_var := 1;
2052 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2053 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2054
2055 f_est_dchan(more_ies :={valueof(pwr)});
2056
2057 f_check_meas_bs_power_level(pwr_var);
2058
2059 f_rsl_chan_deact();
2060 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2061}
2062
2063/* see if the rsl meas res contains our expeced bs power level
2064bs power set after assignment */
2065function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2066 f_l1_tune(L1CTL);
2067 RSL.clear;
2068
2069 if (mp_bts_trxc_port != -1) {
2070 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2071 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2072 }
2073
2074 var uint5_t pwr_var := 1;
2075 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2076
2077 f_est_dchan();
2078
2079 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2080
2081 f_check_meas_bs_power_level(pwr_var);
2082
2083 f_rsl_chan_deact();
2084 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2085}
2086
2087testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2088 var ConnHdlr vc_conn;
2089 var ConnHdlrPars pars;
2090 f_init();
2091 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2092 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2093 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2094 pcu_comp := false, trxc_comp := true);
2095 vc_conn.done;
2096 }
2097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2098}
2099
2100testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2101 var ConnHdlr vc_conn;
2102 var ConnHdlrPars pars;
2103 f_init();
2104 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2105 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2106 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2107 pcu_comp := false, trxc_comp := true);
2108 vc_conn.done;
2109 }
2110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2111}
2112
Eric Wild61edb7e2019-06-03 12:38:31 +02002113/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2114second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2115These power levels are valid for all bands and require no special handling */
2116function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2117 var uint5_t pwr_var := 7;
2118 var L1ctlDlMessage l1_dl;
2119
2120 f_trxc_fake_rssi(rxlev2dbm(10));
2121 f_l1_tune(L1CTL);
2122 RSL.clear;
2123
2124 var RSL_IE_List addl_ies;
2125 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2126
2127 addl_ies := {
2128 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2129 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2130 };
2131
2132 /* establish with power parameters */
2133 f_est_dchan(more_ies := addl_ies);
2134
2135 /* set a high value to ensure L1 power control level increases */
2136 f_trxc_fake_rssi(rxlev2dbm(20));
2137
2138 timer T2 := 6.0;
2139 T2.start;
2140 alt {
2141 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002142 /* Update sent MS power to follow what BTS requests */
2143 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2144 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002145 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002146 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002147 T2.stop;
2148 }
2149 [] L1CTL.receive { repeat; }
2150 [] T2.timeout {
2151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2152 "Power Level in L1 header has not increased sufficiently");
2153 }
2154 }
2155
2156 /* set a low value to ensure L1 power control level decreases */
2157 f_trxc_fake_rssi(rxlev2dbm(0));
2158
2159 timer T4 := 6.0;
2160 T4.start;
2161 alt {
2162 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002163 /* Update sent MS power to follow what BTS requests */
2164 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2165 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002166 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002167 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002168 T4.stop;
2169 setverdict(pass, "Power level in L1 decreased/increased as expected");
2170 }
2171 [] L1CTL.receive { repeat; }
2172 [] T4.timeout {
2173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2174 "Power Level in L1 header has not decreased sufficiently");
2175 }
2176 }
2177
2178 f_rsl_chan_deact();
2179 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2180
2181}
2182
2183/* check that we do not exceed the max power */
2184function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2185 var uint5_t pwr_var := 7;
2186 var L1ctlDlMessage l1_dl;
2187
2188 /* set a low value to ensure power increases */
2189 f_trxc_fake_rssi(rxlev2dbm(10));
2190 f_l1_tune(L1CTL);
2191 RSL.clear;
2192
2193 var RSL_IE_List addl_ies;
2194 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2195
2196 addl_ies := {
2197 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2198 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2199 };
2200
2201 /* establish with power parameters */
2202 f_est_dchan(more_ies := addl_ies);
2203
2204 timer T1 := 10.0;
2205 T1.start;
2206 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002207 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2208 /* Update sent MS power to follow what BTS requests */
2209 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2210 repeat;
2211 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002212 [] L1CTL.receive { repeat; }
2213 [] T1.timeout {
2214 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2215 setverdict(fail, "Power level in L1 header should not have changed");
2216 }
2217 }
2218 }
2219
2220 f_rsl_chan_deact();
2221 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2222
2223}
2224
2225/* see if we reach the band max power */
2226function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2227 var L1ctlDlMessage l1_dl;
2228 var uint5_t pwr_var := 15;
2229 var uint5_t pwr_max_var := f_get_max_power_from_band();
2230
2231 /* set a low value to ensure power increases */
2232 f_trxc_fake_rssi(rxlev2dbm(10));
2233 f_l1_tune(L1CTL);
2234 RSL.clear;
2235
2236 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2237 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2238
2239 /* establish with fixed power level */
2240 f_est_dchan(more_ies :={valueof(pwr)});
2241
2242 /* check our initial power level */
2243 f_wait_for_l1_power_level(pwr_var);
2244
2245 /* update power param to enable power loop
2246 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2247 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2248
2249 /* wait, then check that our power level was reduced */
2250 timer T1 := 10.0;
2251 T1.start;
2252 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002253 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2254 /* Update sent MS power to follow what BTS requests */
2255 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2256 repeat;
2257 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002258 [] L1CTL.receive { repeat; }
2259 [] T1.timeout {
2260 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2261 if( f_power_level_is_highest_dbm(rcv) ){
2262 setverdict(pass, "Power level in L1 header reduced as expected");
2263 } else {
2264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2265 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2266 }
2267 }
2268 }
2269
2270 f_rsl_chan_deact();
2271 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2272
2273}
2274
2275/* see if we reach the band min power */
2276function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2277 var L1ctlDlMessage l1_dl;
2278
2279 /* set a high value to ensure power decreases */
2280 f_trxc_fake_rssi(rxlev2dbm(50));
2281 f_l1_tune(L1CTL);
2282 RSL.clear;
2283
2284 var uint5_t pwr_var := 5;
2285 var uint5_t pwr_target_val := 15;
2286
2287 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2288 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2289
2290 /* establish with fixed power level */
2291 f_est_dchan(more_ies :={valueof(pwr)});
2292
2293 /* check our initial power level */
2294 f_wait_for_l1_power_level(pwr_var);
2295
2296 /* update power param to enable power loop
2297 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002298 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002299
2300 /* wait, then check that our power level was increased */
2301 timer T1 := 10.0;
2302 T1.start;
2303 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002304 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2305 /* Update sent MS power to follow what BTS requests */
2306 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2307 repeat;
2308 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002309 [] L1CTL.receive { repeat; }
2310 [] T1.timeout {
2311 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2312 setverdict(pass, "Power level in L1 header increased to lowest power value");
2313 } else {
2314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2315 "Power level in L1 header NOT increased to lowest power value");
2316 }
2317 }
2318 }
2319
2320 f_rsl_chan_deact();
2321 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2322
2323}
2324
Eric Wild095024b2019-06-17 15:08:57 +02002325/* see if we change the power level without receiving power parameters, which should not happen
2326rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002327function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2328 var L1ctlDlMessage l1_dl;
2329
2330 /* set a high value to ensure power decreases */
2331 f_trxc_fake_rssi(rxlev2dbm(50));
2332 f_l1_tune(L1CTL);
2333 RSL.clear;
2334
2335 var uint5_t pwr_var := 5;
2336
2337 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2338 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2339
2340 /* establish with fixed power level */
2341 f_est_dchan(more_ies :={valueof(pwr)});
2342
2343 /* check our initial power level */
2344 f_wait_for_l1_power_level(pwr_var);
2345
2346 /* wait, then check that our power level did not change */
2347 timer T1 := 10.0;
2348 T1.start;
2349 alt {
2350 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2351 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2353 "BS power control should not be active unless we receive a power parameters IE!");
2354 }
2355 repeat;
2356 }
2357 [] L1CTL.receive { repeat; }
2358 [] T1.timeout { setverdict(pass); }
2359 }
2360
2361 f_rsl_chan_deact();
2362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2363
2364}
2365
Eric Wild095024b2019-06-17 15:08:57 +02002366/* see if we change the power level without receiving power parameters, which should not happen
2367ms power control WITHOUT power parameters */
2368function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2369 var L1ctlDlMessage l1_dl;
2370
2371 /* set a high value to ensure power decreases */
2372 f_trxc_fake_rssi(rxlev2dbm(50));
2373 f_l1_tune(L1CTL);
2374 RSL.clear;
2375
2376 var uint5_t pwr_var := 5;
2377
2378 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2379 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2380
2381 /* establish with fixed power level */
2382 f_est_dchan(more_ies :={valueof(pwr)});
2383
2384 /* check our initial power level */
2385 f_wait_for_l1_power_level(pwr_var);
2386
2387 /* pwr control without power params IE, should NOT activate MS power control*/
2388 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2389
2390 /* wait, then check that our power level did not change */
2391 timer T1 := 10.0;
2392 T1.start;
2393 alt {
2394 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2395 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2397 "BS power control should not be active unless we receive a power parameters IE!");
2398 }
2399 repeat;
2400 }
2401 [] L1CTL.receive { repeat; }
2402 [] T1.timeout { setverdict(pass); }
2403 }
2404
2405 f_rsl_chan_deact();
2406 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2407
2408}
2409
Eric Wild61edb7e2019-06-03 12:38:31 +02002410function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2411 var L1ctlDlMessage l1_dl;
2412 timer T0 := 10.0;
2413 T0.start;
2414 alt {
2415 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2416 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2418 "Power level in L1 header != signaled (RSL) power level.");
2419 }
2420 }
2421 [] L1CTL.receive { repeat; }
2422 [] T0.timeout {
2423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2424 "Timeout waiting for initial power level");
2425 }
2426 }
2427 T0.stop;
2428}
2429
2430private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2431 var IntegerRecord min_dbm_level;
2432 var IntegerRecord max_dbm_level;
2433 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2434
2435 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2436 if (min_dbm_level[i] == level) {
2437 return true;
2438 }
2439 }
2440 return false;
2441}
2442
2443private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2444 var IntegerRecord min_dbm_level;
2445 var IntegerRecord max_dbm_level;
2446 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2447
2448 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2449 if (max_dbm_level[i] == level) {
2450 return true;
2451 }
2452 }
2453 return false;
2454}
2455
2456private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2457 var IntegerRecord min_dbm_level;
2458 var IntegerRecord max_dbm_level;
2459 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2460 return max_dbm_level[0];
2461}
2462
2463type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2464template charstring BtsBand_allGSM:= pattern "GSM???";
2465private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2466 // 45.005 4.1.1
2467 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2468 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2469 2, 1, 0};
2470 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2471 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2472 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2473 var IntegerRecord rv;
2474
2475 select(band){
2476 case (BtsBand_allGSM){
2477 rv := gsm_power;
2478 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2479 max_dbm_level := {2, 1, 0};
2480 }
2481 case("DCS1800"){
2482 rv := dcs_power;
2483 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2484 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2485 }
2486 case("PCS1900"){
2487 rv := pcs_power;
2488 min_dbm_level := {15};
2489 max_dbm_level := {30};
2490 }
2491 }
2492
2493 return rv;
2494}
2495
2496private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2497 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2498}
2499
2500testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2501 var ConnHdlr vc_conn;
2502 var ConnHdlrPars pars;
2503 f_init();
2504 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2505 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2506 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2507 pars.bts0_band := f_vty_get_bts0_band();
2508 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2509 vc_conn.done;
2510 }
2511 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2513}
2514
2515testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2516 var ConnHdlr vc_conn;
2517 var ConnHdlrPars pars;
2518 f_init();
2519 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2520 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2521 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2522 pars.bts0_band := f_vty_get_bts0_band();
2523 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2524 vc_conn.done;
2525 }
2526 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2528}
2529
2530testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2531 var ConnHdlr vc_conn;
2532 var ConnHdlrPars pars;
2533 f_init();
2534 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2535 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2536 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2537 pars.bts0_band := f_vty_get_bts0_band();
2538 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2539 vc_conn.done;
2540 }
2541 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2543}
2544
2545testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2546 var ConnHdlr vc_conn;
2547 var ConnHdlrPars pars;
2548 f_init();
2549 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2550 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2551 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2552 pars.bts0_band := f_vty_get_bts0_band();
2553 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2554 vc_conn.done;
2555 }
2556 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2558}
2559
Eric Wild280ccb82019-06-17 11:11:52 +02002560testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2561 var ConnHdlr vc_conn;
2562 var ConnHdlrPars pars;
2563 f_init();
2564 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2565 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2566 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2567 pars.bts0_band := f_vty_get_bts0_band();
2568 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2569 vc_conn.done;
2570 }
2571 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2573}
2574
Eric Wild095024b2019-06-17 15:08:57 +02002575testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2576 var ConnHdlr vc_conn;
2577 var ConnHdlrPars pars;
2578 f_init();
2579 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2580 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2581 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2582 pars.bts0_band := f_vty_get_bts0_band();
2583 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2584 vc_conn.done;
2585 }
2586 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2588}
2589
Harald Welte70767382018-02-21 12:16:40 +01002590testcase TC_meas_res_sign_tchf() runs on test_CT {
2591 var ConnHdlr vc_conn;
2592 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002593 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002594 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2595 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002596 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2597 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002598 vc_conn.done;
2599 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002601}
2602testcase TC_meas_res_sign_tchh() runs on test_CT {
2603 var ConnHdlr vc_conn;
2604 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002605 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002606 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2607 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002608 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2609 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002610 vc_conn.done;
2611 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002612 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002613}
2614testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2615 var ConnHdlr vc_conn;
2616 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002617 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002618 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2619 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002620 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2621 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002622 vc_conn.done;
2623 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002625}
2626testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2627 var ConnHdlr vc_conn;
2628 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002629 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002630 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2631 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002632 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2633 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002634 vc_conn.done;
2635 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002637}
Harald Welte685d5982018-02-27 20:42:05 +01002638testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2639 var ConnHdlr vc_conn;
2640 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002641 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002642 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2643 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2644 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2645 pars.l1_pars.toa256_enabled := true;
2646 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2647 vc_conn.done;
2648 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002650}
2651
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002652/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2653 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2654function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2655 var L1ctlDlMessage l1_dl;
2656 var RSL_IE_MS_Power ms_power;
2657 var RSL_Message rsl;
2658 var uint5_t power_level := 0;
2659
2660 f_l1_tune(L1CTL);
2661 RSL.clear;
2662
2663 f_est_dchan();
2664
2665 ms_power.reserved := 0;
2666 ms_power.fpc_epc := false;
2667
2668 /* Send the first power control command. This will disable any BTS/TRX
2669 * internal power control and switch the MS (which is not in scope of
2670 * this test) to a constant power level. We start with a power level
2671 * of 0 */
2672 ms_power.power_level := power_level;
2673 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2674 RSL.send(rsl);
2675
2676 alt {
2677
2678 /* Pick all SACCH blocks for checking */
2679 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2680
2681 /* The first byte of the L1 header contains the power level.
2682 * The reserved bits and the fpc bit is set to 0, so we may
2683 * compare directly. */
2684 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2685 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2686 }
2687
2688 /* Signal a new power level via RSL for the next turn. */
2689 if (power_level < 31) {
2690 power_level := power_level + 1;
2691 ms_power.power_level := power_level;
2692 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2693 RSL.send(rsl);
2694 repeat;
2695 }
2696
2697 }
2698
2699 /* Ignore all other blocks */
2700 [] L1CTL.receive { repeat; }
2701
2702 }
2703
2704 f_rsl_chan_deact();
2705 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2706
2707 setverdict(pass);
2708}
2709
2710testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2711 var ConnHdlr vc_conn;
2712 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002713 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002714
2715 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2716 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2717 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2718 vc_conn.done;
2719 }
2720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2721}
Harald Welte70767382018-02-21 12:16:40 +01002722
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002723/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002724TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2725function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2726 var L1ctlDlMessage l1_dl;
2727 var uint5_t ta_to_test := 16;
2728
2729
2730 f_l1_tune(L1CTL);
2731 RSL.clear;
2732
2733 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002734 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002735
2736 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2737
2738
2739 alt {
2740
2741 /* Pick all SACCH blocks for checking */
2742 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2743
2744 /* The second byte of the L1 header contains the TA. */
2745 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2746 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2747 }
2748
2749 }
2750
2751 /* Ignore all other blocks */
2752 [] L1CTL.receive { repeat; }
2753
2754 }
2755
2756 f_rsl_chan_deact();
2757 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2758
2759 setverdict(pass);
2760}
2761
2762testcase TC_rsl_chan_initial_ta() runs on test_CT {
2763 var ConnHdlr vc_conn;
2764 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002765 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002766 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002767 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2768 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002769 vc_conn.done;
2770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2771}
2772
Eric Wilde57e1a62019-05-28 13:30:55 +02002773/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2774function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2775 var L1ctlDlMessage l1_dl;
2776 var uint5_t ms_power_level := 7;
2777
2778 var RSL_IE_MS_Power ms_power;
2779 ms_power.reserved := 0;
2780 ms_power.fpc_epc := false;
2781 ms_power.power_level := ms_power_level;
2782
2783 f_l1_tune(L1CTL);
2784 RSL.clear;
2785
2786 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2787
2788 timer T := 1.0;
2789 T.start;
2790 alt {
2791 /* Pick all SACCH blocks for checking */
2792 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2793 /* The first byte of the L1 header contains the power level.. */
2794 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2795 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2796 }
2797 }
2798 /* Ignore all other blocks */
2799 [] L1CTL.receive { repeat; }
2800 [] T.timeout {
2801 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2802 }
2803 }
2804
2805 f_rsl_chan_deact();
2806 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2807 setverdict(pass);
2808}
2809
2810testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2811 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2812 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2813}
2814
Harald Welte0472ab42018-03-12 15:02:26 +01002815/* 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 +01002816private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002817 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002818 RSL.clear;
2819
2820 f_est_dchan();
2821 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002822 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002823
2824 timer T := 40.0;
2825 T.start;
2826 alt {
2827 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2828 setverdict(pass)
2829 }
2830 [] RSL.receive { repeat };
2831 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002833 }
2834 }
2835 f_rsl_chan_deact();
2836}
2837testcase TC_conn_fail_crit() runs on test_CT {
2838 var ConnHdlr vc_conn;
2839 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002840 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002841 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2842 pars.t_guard := 60.0;
2843 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2844 vc_conn.done;
2845}
2846
Harald Welte93640c62018-02-25 16:59:33 +01002847/***********************************************************************
2848 * Paging
2849 ***********************************************************************/
2850
Harald Welte68e495b2018-02-25 00:05:57 +01002851function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2852 if (tmsi == 'FFFFFFFF'O) {
2853 return true;
2854 } else {
2855 return false;
2856 }
2857}
Harald Welte70767382018-02-21 12:16:40 +01002858
Philipp Maier82cb0b12018-08-31 14:41:39 +02002859type record allowedFn { integer frame_nr }
2860template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2861template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2862template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2863template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2864template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2865template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2866template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2867template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2868function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2869{
2870 var integer frame_nr_51;
2871 frame_nr_51 := frame_nr mod 51
2872
2873 var allowedFn fn_check;
2874 fn_check.frame_nr := frame_nr_51;
2875
2876 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002878 return;
2879 }
2880
2881 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2882 return;
2883 }
2884 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2885 return;
2886 }
2887 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2888 return;
2889 }
2890 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2891 return;
2892 }
2893 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2894 return;
2895 }
2896 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2897 return;
2898 }
2899 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2900 return;
2901 }
2902 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2903 return;
2904 }
2905
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002907 return;
2908}
2909
2910altstep 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 +01002911runs on test_CT {
2912 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002913 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002914 repeat;
2915 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002916 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002917 var octetstring without_plen :=
2918 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2919 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002920
2921 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2922
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07002923 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
2924 /* Ignore empty RR Paging Request (PCH filling) messages.
2925 * TODO: does it make sense to count them? */
2926 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002927 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2928 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002929 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002930 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2931 }
2932 } else if (match(rr, tr_PAGING_REQ2)) {
2933 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2934 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2935 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2936 }
2937 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2938 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2939 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002940 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002941 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2942 }
2943 } else if (match(rr, tr_PAGING_REQ3)) {
2944 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2945 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2946 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2947 }
2948 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2949 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2950 }
2951 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2952 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2953 }
2954 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2955 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2956 }
2957 }
2958 repeat;
2959 }
2960}
2961
2962type record PagingTestCfg {
2963 boolean combined_ccch,
2964 integer bs_ag_blks_res,
2965 float load_factor,
2966 boolean exp_load_ind,
2967 boolean exp_overload,
2968 boolean use_tmsi
2969}
2970
2971type record PagingTestState {
2972 integer num_paging_sent,
2973 integer num_paging_rcv_msgs,
2974 integer num_paging_rcv_ids,
2975 integer num_overload
2976}
2977
Harald Welte68e495b2018-02-25 00:05:57 +01002978/* Helper function for paging related testing */
2979private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002980 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002981 f_init_l1ctl();
2982 f_l1_tune(L1CTL);
2983
2984 var PagingTestState st := {
2985 num_paging_sent := 0,
2986 num_paging_rcv_msgs := 0,
2987 num_paging_rcv_ids := 0,
2988 num_overload := 0
2989 };
2990
2991 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2992 var float max_pch_imsi_per_sec;
2993 if (cfg.use_tmsi) {
2994 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2995 } else {
2996 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2997 }
2998 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2999 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003000 var float time_total := 20.0;
3001 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3002 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003003
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003004 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3005 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003006
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003007 timer T_itv := 0.0;
3008 T_itv.start;
3009 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003010 alt {
3011 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003012 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003013 st.num_overload := st.num_overload + 1;
3014 repeat;
3015 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003016 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003018 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003019 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003020 log("Rx LOAD_IND");
3021 /* FIXME: analyze/verify interval + contents */
3022 repeat;
3023 }
3024 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003025 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003026 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003027 [] T_itv.timeout {
3028 /* Send paging cmds based on elapsed time */
3029 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3030 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003031 var MobileIdentityV mi;
3032
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003033 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003034 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003035 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003036 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003037 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003038 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003039
3040 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003041 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 +02003042
3043 st.num_paging_sent := st.num_paging_sent + 1;
3044 }
3045 if (st.num_paging_sent < pkt_total) {
3046 /* Wait for interval to next PAGING COMMAND */
3047 var float time_now := T_total.read;
3048 var float next_sched := int2float(st.num_paging_sent)*interval;
3049 if (next_sched > time_now) {
3050 T_itv.start(next_sched - time_now);
3051 } else {
3052 T_itv.start(0.0);
3053 }
3054 } else {
3055 /* We are done, no need to keep counting */
3056 T_total.stop;
3057 }
3058 }
3059 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003060 }
3061 }
3062
3063 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3064 timer T_wait := 18.0;
3065 T_wait.start;
3066 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003067 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003068 [] L1CTL.receive { repeat; }
3069 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003070 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3071 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003072 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003074 }
Harald Welte68e495b2018-02-25 00:05:57 +01003075 }
3076
3077 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3078 " rcvd_ids=", st.num_paging_rcv_ids);
3079 return st;
3080}
3081
3082/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3083 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3084 * - that CCCH LOAD IND (PCH) are being generated
3085 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3086testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003087 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003088 var PagingTestCfg cfg := {
3089 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003090 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003091 load_factor := 0.8,
3092 exp_load_ind := true,
3093 exp_overload := false,
3094 use_tmsi := false
3095 };
3096 var PagingTestState st := f_TC_paging(cfg);
3097 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3099 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003100 } else {
3101 setverdict(pass);
3102 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003104}
3105
3106/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3107 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3108 * - that CCCH LOAD IND (PCH) are being generated
3109 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3110testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003111 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003112 var PagingTestCfg cfg := {
3113 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003114 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003115 load_factor := 0.8,
3116 exp_load_ind := true,
3117 exp_overload := false,
3118 use_tmsi := true
3119 };
3120 var PagingTestState st := f_TC_paging(cfg);
3121 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3123 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003124 } else {
3125 setverdict(pass);
3126 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003128}
3129
3130/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3131 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3132 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3133 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3134testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003135 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003136 var PagingTestCfg cfg := {
3137 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003138 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003139 load_factor := 2.0,
3140 exp_load_ind := true,
3141 exp_overload := true,
3142 use_tmsi := false
3143 };
3144 var PagingTestState st := f_TC_paging(cfg);
3145 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3146 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003147 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003148 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003149 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 +01003150 } else {
3151 setverdict(pass);
3152 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003154}
3155
3156/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3157 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3158 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3159 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3160testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003161 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003162 var PagingTestCfg cfg := {
3163 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003164 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003165 load_factor := 2.0,
3166 exp_load_ind := true,
3167 exp_overload := true,
3168 use_tmsi := true
3169 };
3170 var PagingTestState st := f_TC_paging(cfg);
3171 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3172 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003173 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003174 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003175 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 +01003176 } else {
3177 setverdict(pass);
3178 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003180}
3181
3182
Harald Welte93640c62018-02-25 16:59:33 +01003183/***********************************************************************
3184 * Immediate Assignment / AGCH
3185 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003186private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003187 len := 0,
3188 ma := ''B
3189}
Harald Welte93640c62018-02-25 16:59:33 +01003190
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003191template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
Vadim Yanitskiye9f68be2020-05-27 02:08:35 +07003192 uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003193 chan_nr := chan_nr,
3194 tsc := tsc,
3195 h := false,
3196 arfcn := arfcn,
3197 maio_hsn := omit
3198}
3199
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003200template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3201 template (value) MaioHsn maio_hsn) := {
3202 chan_nr := chan_nr,
3203 tsc := tsc,
3204 h := true,
3205 arfcn := omit,
3206 maio_hsn := maio_hsn
3207}
3208
Harald Weltee8d750e2018-06-10 21:41:35 +02003209private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3210 return int2str(num_tx) & " sent, "
3211 & int2str(num_rx) & " received, "
3212 & int2str(num_del) & " deleted";
3213}
3214
3215private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3216 var L1ctlDlMessage l1_dl;
3217 timer T := 10.0;
3218 var integer num_tx := 0;
3219 var integer num_rx := 0;
3220 var integer num_del := 0;
3221 var charstring res_str;
3222 var float rx_ratio;
3223
Harald Welte10474062019-05-30 16:48:17 +02003224 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003225 f_init_l1ctl();
3226 f_l1_tune(L1CTL);
3227
3228 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003229 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003230 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3231 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003232 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003233 num_tx := num_tx+1;
3234 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003235 }
3236 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003237 T.start;
3238 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003239 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003240 num_del := num_del+1;
3241 repeat;
3242 }
3243 [] RSL_CCHAN.receive {
3244 repeat;
3245 }
3246 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3247 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3248 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3249 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3250 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003251 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003252 } else {
3253 num_rx := num_rx+1;
3254 }
3255 repeat;
3256 }
3257 [] L1CTL.receive { repeat; }
3258 [] T.timeout { }
3259 }
3260 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3261 log("AGCH test: " & res_str);
3262 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003264 }
3265 rx_ratio := int2float(num_rx) / int2float(num_tx);
3266 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003267 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 +02003268 } else {
3269 setverdict(pass);
3270 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003272}
3273
Harald Weltee8d750e2018-06-10 21:41:35 +02003274/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3275testcase TC_imm_ass_1000_20ms() runs on test_CT {
3276 f_TC_imm_ass(1000, 0.02, 0.25);
3277}
3278
3279/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3280testcase TC_imm_ass_200_0ms() runs on test_CT {
3281 f_TC_imm_ass(200, 0.0, 0.05);
3282}
3283
3284/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3285testcase TC_imm_ass_200_76ms() runs on test_CT {
3286 f_TC_imm_ass(150, 0.076, 1.00);
3287}
3288
3289
3290
Harald Welte48494ca2018-02-25 16:59:50 +01003291/***********************************************************************
3292 * BCCH
3293 ***********************************************************************/
3294
3295/* tuple of Frame Number + decoded SI */
3296type record SystemInformationFn {
3297 GsmFrameNumber frame_number,
3298 SystemInformation si
3299}
3300
3301/* an arbitrary-length vector of decoded SI + gsmtap header */
3302type record of SystemInformationFn SystemInformationVector;
3303
3304/* an array of SI-vectors indexed by TC value */
3305type SystemInformationVector SystemInformationVectorPerTc[8];
3306
3307/* determine if a given SI vector contains given SI type at least once */
3308function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3309 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3310 var integer fn_mod51 := arr[i].frame_number mod 51;
3311 if (not bcch_ext and fn_mod51 == 2 or
3312 bcch_ext and fn_mod51 == 6) {
3313 if (arr[i].si.header.message_type == key) {
3314 return true;
3315 }
3316 }
3317 }
3318 return false;
3319}
3320
3321/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3322function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3323 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003325 }
3326}
3327
3328/* check if a given SI vector contains given SI type at least once on any TC */
3329function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3330 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3331 if (f_si_vecslot_contains(arr[tc], key) or
3332 f_si_vecslot_contains(arr[tc], key, true)) {
3333 return true;
3334 }
3335 }
3336 return false;
3337}
3338
3339/* determine if a given SI vector contains given SI type at least N of M times */
3340function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3341 var integer count := 0;
3342 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003344 }
3345 for (var integer i:= 0; i < m; i := i + 1) {
3346 var integer fn_mod51 := arr[i].frame_number mod 51;
3347 if (not bcch_ext and fn_mod51 == 2 or
3348 bcch_ext and fn_mod51 == 6) {
3349 if (arr[i].si.header.message_type == key) {
3350 count := count + 1;
3351 }
3352 }
3353 }
3354 if (count >= n) {
3355 return true;
3356 } else {
3357 return false;
3358 }
3359}
3360
3361/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3362function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3363 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003365 }
3366}
3367
3368/* determine if a given SI vector contains given SI type at least once */
3369function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3370 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3371 var integer fn_mod51 := arr[i].frame_number mod 51;
3372 if (not bcch_ext and fn_mod51 == 2 or
3373 bcch_ext and fn_mod51 == 6) {
3374 if (arr[i].si.header.message_type != key) {
3375 return false;
3376 }
3377 }
3378 }
3379 return true;
3380}
3381
3382/* ensure a given TC slot of the SI vector contains only given SI type */
3383function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3384 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003386 }
3387}
3388
3389/* SI configuration of cell, against which we validate actual SI messages */
3390type set SystemInformationConfig {
3391 boolean bcch_extended,
3392 boolean si1_present,
3393 boolean si2bis_present,
3394 boolean si2ter_present,
3395 boolean si2quater_present,
3396 boolean si7_present,
3397 boolean si8_present,
3398 boolean si9_present,
3399 boolean si13_present,
3400 boolean si13alt_present,
3401 boolean si15_present,
3402 boolean si16_present,
3403 boolean si17_present,
3404 boolean si2n_present,
3405 boolean si21_present,
3406 boolean si22_present
3407}
3408
3409/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3410function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3411 var integer i;
3412 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3413 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003415 }
3416 }
3417 if (cfg.si1_present) {
3418 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3419 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3420 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3421 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3422 /* make sure *ALL* contain SI1 */
3423 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3424 }
3425 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3426 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3427 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3428 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3429 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3430 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3431
3432 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3433 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3434 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3435 * consecutive occurrences of TC = 4. */
3436 if (cfg.si2bis_present and not cfg.si2ter_present) {
3437 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3438 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3439 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3440 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3441 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3442 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3443 }
3444
3445 if (cfg.si7_present or cfg.si8_present) {
3446 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3447 * if System Information type 4 does not contain all information needed for cell
3448 * selection and reselection. */
3449 if (not cfg.bcch_extended) {
3450 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3451 }
3452 if (cfg.si7_present) {
3453 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3454 }
3455 if (cfg.si8_present) {
3456 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3457 }
3458 }
3459
3460 if (cfg.si2quater_present) {
3461 /* iii) System information type 2 quater is sent if needed, as determined by the system
3462 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3463 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3464 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3465 * within any of 4 consecutive occurrences of TC = 5. */
3466 if (not (cfg.bcch_extended)) {
3467 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3468 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3469 } else {
3470 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3471 }
3472 } else {
3473 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3474 }
3475 }
3476 if (cfg.si9_present) {
3477 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3478 * in system information type 3 as defined in 3GPP TS 44.018. */
3479 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3480 }
3481 if (cfg.si13_present) {
3482 /* vii) System Information type 13 is only related to the GPRS service. System Information
3483 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3484 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3485 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3486 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3487 * within any of 4 consecutive occurrences of TC=4. */
3488 if (not cfg.bcch_extended) {
3489 log("not-bccch-extended");
3490 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3491 } else {
3492 log("bccch-extended");
3493 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3494 }
3495 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003497 }
3498 }
3499 if (cfg.si16_present or cfg.si17_present) {
3500 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3501 * should not be sent in a cell where network sharing is used (see rule xv). */
3502 if (cfg.si22_present) {
3503 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3504 }
3505 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003507 }
3508 if (not cfg.bcch_extended) {
3509 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3510 }
3511 if (cfg.si16_present) {
3512 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3513 }
3514 if (cfg.si17_present) {
3515 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3516 }
3517 }
3518
3519 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3520 * broadcast information. The frequency with which they are sent is determined by the
3521 * system operator. System Information type 9 identifies the scheduling of System
3522 * Information type 18 and 20 messages. */
3523
3524 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3525 * Information Type 19 is present, then its scheduling shall be indicated in System
3526 * Information Type 9. */
3527
3528 if (cfg.si15_present) {
3529 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3530 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3531 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3532 * 4 consecutive occurrences of TC = 1. */
3533 if (not cfg.bcch_extended) {
3534 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3535 } else {
3536 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3537 }
3538 }
3539 if (cfg.si13alt_present) {
3540 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3541 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3542 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3543 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3544 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3545 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3546 * of TC = 4. */
3547 if (cfg.si13_present) {
3548 testcase.stop("Error: Cannot have SI13alt and SI13");
3549 }
3550 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003552 }
3553 if (not cfg.bcch_extended) {
3554 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3555 } else {
3556 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3557 }
3558 }
3559 if (cfg.si2n_present) {
3560 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3561 * as determined by the system operator. In the case that the message is sent on the
3562 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3563 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3564 * consecutive occurrences of TC = 4. */
3565 if (not cfg.bcch_extended) {
3566 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3567 } else {
3568 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3569 }
3570 }
3571 if (cfg.si21_present) {
3572 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3573 * determined by the system operator. If Extended Access Barring is in use in the cell
3574 * then this message is sent at least once within any of 4 consecutive occurrences of
3575 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3576 * cell then this message shall only be sent on BCCH Ext. */
3577 if (not cfg.bcch_extended) {
3578 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3579 } else {
3580 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3581 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003583 }
3584 }
3585 }
3586 if (cfg.si22_present) {
3587 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3588 * should not be sent in a cell where SoLSA is used (see rule viii). System
3589 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3590 * =2 and TC=6. */
3591 if (cfg.si16_present or cfg.si17_present) {
3592 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3593 }
3594 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3595 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003597 }
3598 if (not cfg.bcch_extended) {
3599 testcase.stop("Error: SI22 requires BCCH Extd!");
3600 } else {
3601 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3602 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3603 }
3604 }
3605}
3606
3607/* sample Systme Information for specified duration via L1CTL */
3608function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3609 timer T := duration;
3610 var SystemInformationVectorPerTc si_per_tc;
3611 var L1ctlDlMessage l1_dl;
3612
3613 /* initialize all per-TC vectors empty */
3614 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3615 si_per_tc[i] := {};
3616 }
3617
3618 /* flush all previous L1 queued msgs */
3619 pt.clear;
3620
3621 T.start;
3622 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003623 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003624 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3625 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3626 log("Ignoring non-RR SI ", l1_dl);
3627 repeat;
3628 }
3629 var SystemInformationFn sig := {
3630 frame_number := l1_dl.dl_info.frame_nr,
3631 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3632 }
3633 var integer tc := f_gsm_compute_tc(sig.frame_number);
3634 log("SI received at TC=", tc, ": ", sig.si);
3635 /* append to the per-TC bucket */
3636 si_per_tc[tc] := si_per_tc[tc] & { sig };
3637 repeat;
3638 }
3639 [] pt.receive { repeat; }
3640 [] T.timeout { }
3641 }
3642
3643 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3644 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3645 }
3646 log("si_per_tc=", si_per_tc);
3647 return si_per_tc;
3648}
3649
3650/* helper function: Set given SI via RSL + validate scheduling.
3651 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3652function f_TC_si_sched() runs on test_CT {
3653 var SystemInformationVectorPerTc si_per_tc;
3654 f_init_l1ctl();
3655 f_l1_tune(L1CTL);
3656
3657 /* Sample + Validate Scheduling */
3658 si_per_tc := f_l1_sample_si(L1CTL);
3659 f_validate_si_scheduling(si_cfg, si_per_tc);
3660
3661 setverdict(pass);
3662}
3663
3664testcase TC_si_sched_default() runs on test_CT {
3665 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003666 /* 2+3+4 are mandatory and set in f_init() */
3667 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003669}
3670
3671testcase TC_si_sched_1() runs on test_CT {
3672 f_init();
3673 si_cfg.si1_present := true;
3674 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003675 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003677}
3678
3679testcase TC_si_sched_2bis() runs on test_CT {
3680 f_init();
3681 si_cfg.si2bis_present := true;
3682 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3683 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003685}
3686
3687testcase TC_si_sched_2ter() runs on test_CT {
3688 f_init();
3689 si_cfg.si2ter_present := true;
3690 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3691 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003693}
3694
3695testcase TC_si_sched_2ter_2bis() runs on test_CT {
3696 f_init();
3697 si_cfg.si2bis_present := true;
3698 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3699 si_cfg.si2ter_present := true;
3700 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3701 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003703}
3704
3705testcase TC_si_sched_2quater() runs on test_CT {
3706 f_init();
3707 si_cfg.si2quater_present := true;
3708 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3709 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003711}
3712
3713testcase TC_si_sched_13() runs on test_CT {
3714 f_init();
3715 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003716 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003717 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003719}
3720
3721testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3722 f_init();
3723 si_cfg.si2bis_present := true;
3724 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3725 si_cfg.si2ter_present := true;
3726 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3727 si_cfg.si2quater_present := true;
3728 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3729 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003730 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003731 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003733}
3734
3735
Harald Welte68e495b2018-02-25 00:05:57 +01003736testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003737 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003738 /* FIXME: enable / disable individual BCCH info */
3739 //ts_RSL_BCCH_INFO(si_type, info);
3740 /* expect no ERROR REPORT after either of them *
3741 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003743}
3744
Harald Welte93640c62018-02-25 16:59:33 +01003745/***********************************************************************
3746 * Low-Level Protocol Errors / ERROR REPORT
3747 ***********************************************************************/
3748
Harald Welte01d982c2018-02-25 01:31:40 +01003749private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3750 timer T := 5.0;
3751 T.start;
3752 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003753 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01003754 setverdict(pass);
3755 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003756 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003758 }
3759 [] RSL_CCHAN.receive {
3760 repeat;
3761 }
3762 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003764 }
3765 }
3766}
3767
3768/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3769testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003770 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003771 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3772 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003773 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003774
3775 f_exp_err_rep(RSL_ERR_PROTO);
3776}
3777
3778/* Provoke a mandatory IE error and match on ERROR REPORT */
3779testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003780 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003781
3782 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3783 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003784 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003785
3786 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3787}
3788
3789/* Provoke an IE content error and match on ERROR REPORT */
3790testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003791 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003792 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3793 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003794 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003795
3796 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3797}
3798
Harald Welteee25aae2019-05-19 14:32:37 +02003799/* attempt to activate channel with wrong RSL Message Discriminator IE */
3800function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3801 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3802 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3803 RSL.send(rsl);
3804 f_rslem_unregister(0, g_chan_nr);
3805}
3806testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3807 var ConnHdlr vc_conn;
3808 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3809
Harald Welte10474062019-05-30 16:48:17 +02003810 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003811
3812 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3813 vc_conn.done;
3814 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3815
3816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3817}
3818
3819/* Send messages with wrong message type */
3820function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3821 var template (value) RSL_Message rsl_tx;
3822 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3823 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3824 RSL.send(rsl_tx);
3825 f_rslem_unregister(0, g_chan_nr);
3826}
3827function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3828 var template (value) RSL_Message rsl_tx;
3829 /* we first have to activate the dedicated channel */
3830 f_rsl_chan_act(g_pars.chan_mode);
3831 /* ... to then send an invalid RLL message */
3832 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3833 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3834 RSL.send(rsl_tx);
3835 f_rslem_unregister(0, g_chan_nr);
3836}
3837testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3838 var ConnHdlr vc_conn;
3839 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3840 var template (value) RSL_Message rsl_tx;
3841
Harald Welte10474062019-05-30 16:48:17 +02003842 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003843
3844 /* Common Channel with wrong message type */
3845 RSL_CCHAN.clear;
3846 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3847 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003848 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003849 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3850
3851 /* TRX Management */
3852 RSL_CCHAN.clear;
3853 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3854 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003855 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003856 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3857
3858 /* Dedicated Channel */
3859 RSL_CCHAN.clear;
3860 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3861 vc_conn.done;
3862 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3863
3864 /* RLL */
3865 RSL_CCHAN.clear;
3866 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3867 vc_conn.done;
3868 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3869}
3870
3871/* Send messages in wrong sequence (RLL to an inactive lchan) */
3872function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3873 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3874 f_rslem_unregister(0, g_chan_nr);
3875}
3876testcase TC_err_rep_wrong_sequence() runs on test_CT {
3877 var ConnHdlr vc_conn;
3878 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3879
Harald Welte10474062019-05-30 16:48:17 +02003880 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003881
3882 RSL_CCHAN.clear;
3883 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3884 vc_conn.done;
3885 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3886}
3887
Harald Welte93640c62018-02-25 16:59:33 +01003888/***********************************************************************
3889 * IPA CRCX/MDCX/DLCS media stream handling
3890 ***********************************************************************/
3891
Harald Weltea871a382018-02-25 02:03:14 +01003892/* Send IPA DLCX to inactive lchan */
3893function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003894 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3895 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003896}
3897testcase TC_ipa_dlcx_not_active() runs on test_CT {
3898 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003899 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003900 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3901 vc_conn.done;
3902}
Harald Welte68e495b2018-02-25 00:05:57 +01003903
Harald Weltea3f1df92018-02-25 12:49:55 +01003904/* Send IPA CRCX twice to inactive lchan */
3905function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3906 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3907 "IPA CRCX ACK");
3908 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3909 "IPA CRCX NACK");
3910}
3911testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3912 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003913 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003914 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3915 vc_conn.done;
3916}
3917
3918/* Regular sequence of CRCX/MDCX/DLCX */
3919function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3920 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3921 "IPA CRCX ACK");
3922 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3923 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3924 var uint7_t rtp_pt2 := f_rnd_int(127);
3925 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3926 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3927 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3928 "IPA MDCX ACK");
3929 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3930 "IPA DLCX ACK");
3931}
3932testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3933 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003934 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003935 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3936 vc_conn.done;
3937}
3938
Harald Welte3ae11da2018-02-25 13:36:06 +01003939/* Sequence of CRCX, 2x MDCX, DLCX */
3940function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3941 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3942 "IPA CRCX ACK");
3943 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3944 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3945 var uint7_t rtp_pt2 := f_rnd_int(127);
3946 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3947 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3948 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3949 "IPA MDCX ACK");
3950 /* Second MDCX */
3951 remote_ip := f_rnd_int(c_UINT32_MAX);
3952 remote_port := f_rnd_int(c_UINT16_MAX);
3953 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3954 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3955 "IPA MDCX ACK");
3956 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3957 "IPA DLCX ACK");
3958}
3959testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3960 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003961 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003962 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3963 vc_conn.done;
3964}
3965
Harald Welte9912eb52018-02-25 13:30:15 +01003966/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3967function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3968 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3969 "IPA CRCX NACK");
3970}
3971testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3972 var ConnHdlrPars pars;
3973 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003974 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003975
3976 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3977 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3978 vc_conn.done;
3979
3980 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3981 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3982 vc_conn.done;
3983}
3984
Harald Weltea3f1df92018-02-25 12:49:55 +01003985
Harald Welte883340c2018-02-28 18:59:29 +01003986/***********************************************************************
3987 * PCU Socket related tests
3988 ***********************************************************************/
3989
Harald Welte07bd2d22019-05-25 11:03:30 +02003990/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003991friend 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 +01003992runs on test_CT {
3993 timer T := 3.0;
3994
3995 /* we don't expect any RTS.req before PDCH are active */
3996 T.start;
3997 alt {
3998 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004000 }
4001 [] PCU.receive { repeat; }
4002 [] T.timeout { }
4003 }
4004
4005 /* Send PDCH activate request for known PDCH timeslot */
4006 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4007
4008 /* we now expect RTS.req for this timeslot (only) */
4009 T.start;
4010 alt {
4011 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4012 setverdict(pass);
4013 }
4014 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4015 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004017 }
4018 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004020 }
4021 [] PCU.receive { repeat; }
4022 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004024 }
4025 [not exp_success] T.timeout {
4026 setverdict(pass);
4027 }
4028 }
4029}
4030
Harald Welte07bd2d22019-05-25 11:03:30 +02004031/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004032friend 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 +01004033runs on test_CT {
4034 timer T := 3.0;
4035
4036 /* Send PDCH activate request for known PDCH timeslot */
4037 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4038
4039 PCU.clear;
4040 /* we now expect no RTS.req for this timeslot */
4041 T.start;
4042 alt {
4043 [] 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 +02004044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004045 }
4046 [] PCU.receive { repeat; }
4047 [] T.timeout {
4048 setverdict(pass);
4049 }
4050 }
4051}
4052
Harald Weltead033dc2019-05-25 17:28:16 +02004053friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004054 f_init();
4055 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4056}
4057
Harald Welte883340c2018-02-28 18:59:29 +01004058/* PDCH activation via PCU socket; check for presence of RTS.req */
4059testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004060 f_init_pcu_test();
4061
Harald Welte883340c2018-02-28 18:59:29 +01004062 f_TC_pcu_act_req(0, 0, 7, true);
4063}
4064
4065/* PDCH activation via PCU socket on non-PDCU timeslot */
4066testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004067 f_init_pcu_test();
4068
Harald Welte883340c2018-02-28 18:59:29 +01004069 f_TC_pcu_act_req(0, 0, 1, false);
4070}
4071
4072/* PDCH activation via PCU socket on wrong BTS */
4073testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004074 f_init_pcu_test();
4075
Harald Welte883340c2018-02-28 18:59:29 +01004076 f_TC_pcu_act_req(23, 0, 7, false);
4077}
4078
4079/* PDCH activation via PCU socket on wrong TRX */
4080testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004081 f_init_pcu_test();
4082
Harald Welte883340c2018-02-28 18:59:29 +01004083 f_TC_pcu_act_req(0, 23, 7, false);
4084}
4085
4086/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4087testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004088 f_init_pcu_test();
4089
Harald Welte883340c2018-02-28 18:59:29 +01004090 /* Activate PDCH */
4091 f_TC_pcu_act_req(0, 0, 7, true);
4092 f_sleep(1.0);
4093 /* and De-Activate again */
4094 f_TC_pcu_deact_req(0, 0, 7);
4095}
4096
4097/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4098testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004099 f_init_pcu_test();
4100
Harald Welte883340c2018-02-28 18:59:29 +01004101 f_TC_pcu_deact_req(0, 0, 1);
4102}
4103
4104/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4105testcase TC_pcu_ver_si13() runs on test_CT {
4106 const octetstring si13 := '00010203040506070909'O;
4107 var PCUIF_send_data sd;
4108 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004109 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004110
4111 /* Set SI13 via RSL */
4112 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004113
Harald Welte883340c2018-02-28 18:59:29 +01004114 T.start;
4115 alt {
4116 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4117 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4118 setverdict(pass);
4119 } else {
4120 repeat;
4121 }
4122 }
4123 [] PCU.receive { repeat; }
4124 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004126 }
4127 }
4128}
4129
4130private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4131
4132/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004133friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004134 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4135runs on test_CT
4136{
4137 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4138 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4139}
4140
4141/* 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 +02004142friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4143 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004144runs on test_CT
4145{
4146 var PCUIF_send_data sd;
4147
4148 timer T := 3.0;
4149 T.start;
4150 alt {
4151 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4152 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4153 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4154 sd.data.u.rts_req.fn, sapi, data);
4155 }
4156 [] PCU.receive { repeat; }
4157 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004159 }
4160 }
4161}
4162
4163/* Send DATA.req on invalid BTS */
4164testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004165 var TfiUsfArr tua := f_TfiUsfArrInit();
4166 var octetstring data := '0000'O & f_rnd_octstring(21);
4167
4168 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004169
Harald Welte883340c2018-02-28 18:59:29 +01004170 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004171 f_TfiUsfArrSet(tua, 7, 0);
4172 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4173 f_sleep(1.0);
4174
4175 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004176}
4177
4178/* Send DATA.req on invalid TRX */
4179testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004180 var TfiUsfArr tua := f_TfiUsfArrInit();
4181 var octetstring data := '0000'O & f_rnd_octstring(21);
4182
4183 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004184
Harald Welte883340c2018-02-28 18:59:29 +01004185 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004186 f_TfiUsfArrSet(tua, 7, 0);
4187 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4188 f_sleep(1.0);
4189
4190 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004191}
4192
4193/* Send DATA.req on invalid timeslot */
4194testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004195 var TfiUsfArr tua := f_TfiUsfArrInit();
4196 var octetstring data := '0000'O & f_rnd_octstring(21);
4197
4198 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004199
Harald Welte883340c2018-02-28 18:59:29 +01004200 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004201 f_TfiUsfArrSet(tua, 7, 0);
4202 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4203 f_sleep(1.0);
4204
4205 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004206}
4207
4208/* Send DATA.req on timeslot that hasn't been activated */
4209testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004210 var TfiUsfArr tua := f_TfiUsfArrInit();
4211 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004212
Harald Welte7162a612019-05-26 12:56:09 +02004213 f_virtphy_common();
4214
4215 f_TfiUsfArrSet(tua, 7, 0);
4216 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4217 f_sleep(1.0);
4218
4219 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004220}
4221
Harald Weltead033dc2019-05-25 17:28:16 +02004222private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004223 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4224 boolean wait_rts := true)
4225runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004226 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004227 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004228
4229 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004230 if (wait_rts) {
4231 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4232 } else {
4233 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4234 }
Harald Weltead033dc2019-05-25 17:28:16 +02004235
4236 T.start;
4237 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004238 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004239 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4240 setverdict(pass);
4241 }
Harald Welte7162a612019-05-26 12:56:09 +02004242 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4243 setverdict(fail, "Received unexpected ", rx_dl);
4244 }
Harald Weltead033dc2019-05-25 17:28:16 +02004245 [] L1CTL.receive {
4246 repeat;
4247 }
Harald Welte7162a612019-05-26 12:56:09 +02004248 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004249 setverdict(fail, "Timeout waiting for ", data);
4250 }
Harald Welte7162a612019-05-26 12:56:09 +02004251 [not expect_data] T.timeout {
4252 setverdict(pass);
4253 }
Harald Weltead033dc2019-05-25 17:28:16 +02004254 }
4255}
4256
4257private function f_disable_dynamic_ts() runs on test_CT
4258{
4259 f_init_vty_bsc();
4260 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4261 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4262 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4263 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004264 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004265}
4266
4267private function f_virtphy_common() runs on test_CT {
4268 f_disable_dynamic_ts();
4269 f_init_l1ctl();
4270 f_l1_tune(L1CTL);
4271}
4272
4273testcase TC_pcu_data_req_pdtch() runs on test_CT {
4274 var TfiUsfArr tua := f_TfiUsfArrInit();
4275 var octetstring data := '0000'O & f_rnd_octstring(21);
4276
4277 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004278
Harald Welte883340c2018-02-28 18:59:29 +01004279 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004280 f_TfiUsfArrSet(tua, 7, 0);
4281 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4282 f_sleep(1.0);
4283
4284 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004285}
4286
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004287/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004288testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004289 var TfiUsfArr tua := f_TfiUsfArrInit();
4290 var octetstring data := '0000'O & f_rnd_octstring(21);
4291
4292 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004293
Harald Welte883340c2018-02-28 18:59:29 +01004294 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004295 f_TfiUsfArrSet(tua, 7, 0);
4296 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4297 f_sleep(1.0);
4298
4299 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004300}
4301
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004302private function f_TC_pcu_ptcch_ul(uint16_t ra)
4303runs on test_CT {
4304 var template PCUIF_Message pcu_rach_ind;
4305 var PCUIF_send_data sd;
4306 var GsmFrameNumber fn;
4307 timer T;
4308
4309 /* Send an Access Burst on PTCCH/U over the Um-interface */
4310 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4311 chan_nr := ts_RslChanNr_PDCH(7),
4312 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4313
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004314 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4315 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004316
4317 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4318 T.start(52.0 * 4.615 / 1000.0);
4319 alt {
4320 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4321 log("Rx an Access Burst on the PCU interface: ", sd.data);
4322 setverdict(pass);
4323 T.stop;
4324 }
4325 [] PCU.receive { repeat; }
4326 [] T.timeout {
4327 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4328 /* Keep going, that's not the end of the world */
4329 }
4330 }
4331}
4332
4333testcase TC_pcu_ptcch() runs on test_CT {
4334 var L1ctlDlMessage dl;
4335 var octetstring data;
4336 timer T;
4337
4338 f_init_pcu_test();
4339 f_init_l1ctl();
4340 f_l1_tune(L1CTL);
4341
4342 /* Activate PDCH channel on TS7 */
4343 f_TC_pcu_act_req(0, 0, 7, true);
4344
4345 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004346 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004347
4348 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4349 for (var integer i := 0; i < 16; i := i + 1) {
4350 log("Sending an Access Burst towards the L1CTL interface");
4351 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4352 }
4353
4354 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4355 data := f_rnd_octstring(23);
4356
4357 /* Verify PTCCH/D: send a random data block, make sure it's received */
4358 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4359 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4360
4361 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4362 * let's give it more time in case if we miss the beginning. */
4363 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4364 alt {
4365 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4366 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4367 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4368 frame := data)) -> value dl {
4369 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4370 setverdict(pass);
4371 T.stop;
4372 }
4373 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4374 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4375 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4376 l2_data := data)) -> value dl {
4377 log("Rx PTCCH/D data block on L1CTL: ", dl);
4378 setverdict(pass);
4379 T.stop;
4380 }
4381 [] L1CTL.receive { repeat; }
4382 [] T.timeout {
4383 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4384 }
4385 }
4386}
4387
Harald Welte883340c2018-02-28 18:59:29 +01004388/* Send AGCH from PCU; check it appears on Um side */
4389testcase TC_pcu_data_req_agch() runs on test_CT {
4390 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004391 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004392 f_init_l1ctl();
4393 f_l1_tune(L1CTL);
4394
4395 f_TC_pcu_act_req(0, 0, 7, true);
4396 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4397
4398 T.start;
4399 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004400 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004401 setverdict(pass);
4402 }
4403 [] L1CTL.receive { repeat; }
4404 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004406 }
4407 }
4408}
4409
Harald Welte928622b2019-05-26 13:22:59 +02004410/* Send AGCH from PCU; check it appears on Um side */
4411testcase TC_pcu_data_req_pch() runs on test_CT {
4412 timer T := 3.0;
4413 f_init_pcu_test();
4414 f_init_l1ctl();
4415 f_l1_tune(L1CTL);
4416
4417 f_TC_pcu_act_req(0, 0, 7, true);
4418 /* three characters prefix: last 3 digits of IMSI as ASCII */
4419 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4420
4421 T.start;
4422 alt {
4423 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4424 setverdict(pass);
4425 }
4426 [] L1CTL.receive { repeat; }
4427 [] T.timeout {
4428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4429 }
4430 }
4431}
4432
Harald Welte883340c2018-02-28 18:59:29 +01004433/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4434testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4435 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004436 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004437 f_init_l1ctl();
4438 f_l1_tune(L1CTL);
4439
4440 /* append 3 last imsi digits so BTS can compute pagng group */
4441 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4442
4443 timer T := 0.5;
4444 T.start;
4445 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004446 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004447 /* TODO: verify paging group */
4448 setverdict(pass);
4449 }
4450 [] L1CTL.receive { repeat; }
4451 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004453 }
4454 }
4455}
4456
4457/* Send RACH from Um side, expect it to show up on PCU socket */
4458testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004459 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004460 f_init_l1ctl();
4461 f_l1_tune(L1CTL);
4462
4463 var GsmFrameNumber fn_last := 0;
4464 for (var integer i := 0; i < 1000; i := i+1) {
4465 var OCT1 ra := f_rnd_ra_ps();
4466 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4467 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004469 }
4470 fn_last := fn;
4471
4472 timer T := 2.0;
4473 T.start;
4474 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004475 [] 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 +01004476 T.stop;
4477 }
4478 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004480 }
4481 [] PCU.receive { repeat; }
4482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004484 }
4485 }
4486 }
4487 setverdict(pass);
4488}
4489
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004490/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4491 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4492testcase TC_pcu_ext_rach_content() runs on test_CT {
4493 var template PCUIF_Message pcu_rach_ind;
4494 var GsmFrameNumber fn_last := 0;
4495 var L1ctlRachSynchSeq synch_seq;
4496 var PCUIF_BurstType pcu_bt;
4497 var GsmFrameNumber fn;
4498 var BIT11 ra11;
4499
4500 f_init_pcu_test();
4501 f_init_l1ctl();
4502 f_l1_tune(L1CTL);
4503
4504 for (var integer i := 0; i < 1000; i := i+1) {
4505 /* We need to test both TS1 & TS2 */
4506 if (i rem 2 == 0) {
4507 synch_seq := RACH_SYNCH_SEQ_TS1;
4508 pcu_bt := BURST_TYPE_1;
4509 } else {
4510 synch_seq := RACH_SYNCH_SEQ_TS2;
4511 pcu_bt := BURST_TYPE_2;
4512 }
4513
4514 ra11 := f_rnd_ra11_ps();
4515 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4516 if (fn == fn_last) {
4517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4518 "Two RACH in same FN?!?");
4519 }
4520 fn_last := fn;
4521
4522 /* Compose the expected message */
4523 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004524 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004525 ra := bit2int(ra11),
4526 is_11bit := 1,
4527 burst_type := pcu_bt,
4528 fn := fn);
4529
4530 timer T := 2.0;
4531 T.start;
4532 alt {
4533 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4534 T.stop;
4535 }
4536 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4538 }
4539 [] PCU.receive { repeat; }
4540 [] T.timeout {
4541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4542 }
4543 }
4544 }
4545 setverdict(pass);
4546}
4547
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004548private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4549runs on test_CT {
4550 var template PCUIF_send_data sdt;
4551 var PCUIF_send_data sd;
4552 var int16_t lqual_cb;
4553 timer T := 1.0;
4554
4555 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4556 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4557
4558 /* Send a random PDTCH frame over Um */
4559 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4560 '0000'O & f_rnd_octstring(21)));
4561
4562 T.start;
4563 alt {
4564 /* If expected link quality is above the threshold */
4565 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4566 lqual_cb := sd.data.u.data_ind.lqual_cb;
4567 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4568
4569 /* Make sure the actual link quality matches the expected value */
4570 if (not match(lqual_cb, lqual_cb_exp)) {
4571 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4572 "expected value ", lqual_cb_exp));
4573 } else {
4574 setverdict(pass);
4575 }
4576 }
4577 /* If expected link quality is below the threshold */
4578 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4580 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4581 }
4582 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4583 [] PCU.receive { repeat; }
4584 [lqual_cb_exp < thresh] T.timeout {
4585 log("Rx nothing, as expected");
4586 setverdict(pass);
4587 }
4588 [lqual_cb_exp >= thresh] T.timeout {
4589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4590 "Timeout waiting for PCUIF_DATA.ind");
4591 }
4592 }
4593}
4594
4595/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4596testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4597 f_init_pcu_test();
4598 PCU.clear;
4599
4600 f_init_l1ctl();
4601 f_l1_tune(L1CTL);
4602
4603 /* Activate a PDCH channel on TS7 */
4604 f_TC_pcu_act_req(0, 0, 7, true);
4605
4606 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004607 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004608
4609 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4610 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4611 var TrxcMessage ret;
4612
4613 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4614 valueof(ts_TRXC_FAKE_CI(i)));
4615
4616 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4617 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4618 }
4619}
4620
Harald Welte883340c2018-02-28 18:59:29 +01004621/* Send PAGING via RSL, expect it to shw up on PCU socket */
4622testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004623 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004624
4625 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004626 var MobileIdentityLV mi_lv;
4627 var octetstring mi_lv_enc;
4628 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004629 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004630
Harald Welte883340c2018-02-28 18:59:29 +01004631 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004632 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004633 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004634 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004635 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004636
4637 /* Fancy encoding for PCUIF */
4638 mi_lv := valueof(ts_MI_LV(mi));
4639 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4640 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004641
4642 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004643 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004644 T.start;
4645 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004646 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004647 }
4648 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004650 }
4651 [] PCU.receive { repeat; }
4652 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004654 }
4655 }
4656 }
4657 setverdict(pass);
4658}
4659
Harald Welted66c9b82019-05-25 09:03:15 +02004660/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4661testcase TC_pcu_time_ind() runs on test_CT {
4662 var PCUIF_send_data pcu_sd;
4663 var integer num_time_ind := 0;
4664 var integer first_fn, last_fn;
4665 var float test_duration := 5.0;
4666 timer T;
4667
4668 f_init_pcu_test();
4669 f_TC_pcu_act_req(0, 0, 7, true);
4670
4671 PCU.clear;
4672 T.start(test_duration);
4673 alt {
4674 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4675 num_time_ind := num_time_ind + 1;
4676 if (not isbound(first_fn)) {
4677 first_fn := pcu_sd.data.u.time_ind.fn;
4678 }
4679 last_fn := pcu_sd.data.u.time_ind.fn;
4680 repeat;
4681 }
4682 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4683 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4684 repeat;
4685 }
4686 [] PCU.receive {
4687 repeat;
4688 }
4689 [] T.timeout {}
4690 }
4691 var integer fn_expired := last_fn - first_fn;
4692 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4693
4694 /* verify the number of frames expired matches our expectation */
4695 const float c_GSM_FN_DURATION_MS := 4.61538;
4696 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004697 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004698 if (not match(fn_expired, t_fn_expected)) {
4699 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4700 }
4701
4702 /* There are three TIME.ind in every fn MOD 13 */
4703 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4704 /* Add some tolerance */
4705 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4706 if (not match(num_time_ind, t_time_ind_exp)) {
4707 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4708 }
4709
4710 setverdict(pass);
4711}
4712
Harald Welte4832c862019-05-25 14:57:18 +02004713/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4714testcase TC_pcu_rts_req() runs on test_CT {
4715 var PCUIF_send_data pcu_sd;
4716 var integer first_fn, last_fn;
4717 var integer num_rts_pdtch := 0;
4718 var integer num_rts_ptcch := 0;
4719 var float test_duration := 5.0;
4720 timer T;
4721
4722 f_init_pcu_test();
4723 f_TC_pcu_act_req(0, 0, 7, true);
4724
4725 PCU.clear;
4726 T.start(test_duration);
4727 alt {
4728 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4729 -> value pcu_sd {
4730 num_rts_pdtch := num_rts_pdtch + 1;
4731 if (not isbound(first_fn)) {
4732 first_fn := pcu_sd.data.u.rts_req.fn;
4733 }
4734 last_fn := pcu_sd.data.u.rts_req.fn;
4735 repeat;
4736 }
4737 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4738 -> value pcu_sd {
4739 num_rts_ptcch := num_rts_ptcch + 1;
4740 if (not isbound(first_fn)) {
4741 first_fn := pcu_sd.data.u.rts_req.fn;
4742 }
4743 last_fn := pcu_sd.data.u.rts_req.fn;
4744 repeat;
4745 }
4746 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4747 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4748 repeat;
4749 }
4750 [] PCU.receive {
4751 repeat;
4752 }
4753 [] T.timeout {}
4754 }
4755 var integer fn_expired := last_fn - first_fn;
4756 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4757 ", num_rts_ptcch=", num_rts_ptcch);
4758
4759 /* verify the number of frames expired matches our expectation */
4760 const float c_GSM_FN_DURATION_MS := 4.61538;
4761 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004762 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004763 if (not match(fn_expired, t_fn_expected)) {
4764 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4765 }
4766
4767 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4768 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4769 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4770 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4771 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4772 t_ptcch_exp);
4773 }
4774
4775 /* We have 12 PDTCH blocks every 52-multiframe */
4776 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4777 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4778 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4779 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4780 t_pdtch_exp);
4781 }
4782
4783 setverdict(pass);
4784}
4785
Harald Welte07bd2d22019-05-25 11:03:30 +02004786/* test for generating Abis side OML ALERT from the PCU */
4787testcase TC_pcu_oml_alert() runs on test_CT {
4788 var PCUIF_send_data pcu_sd;
4789 var integer num_time_ind := 0;
4790 var integer first_fn, last_fn;
4791 var float test_duration := 5.0;
4792 timer T;
4793
4794 f_init_pcu_test();
4795 f_TC_pcu_act_req(0, 0, 7, true);
4796
4797 /* re-connect CTRL port from BTS to BSC */
4798 f_ipa_ctrl_stop();
4799 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4800
4801 /* Send that OML Alert */
4802 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4803
4804 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4805 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4806 setverdict(pass);
4807}
4808
Harald Welteeaa9a862019-05-26 23:01:08 +02004809template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4810 template (value) RoutingAreaIdentificationV rai,
4811 template (value) OCT1 cause) := {
4812 discriminator := '0000'B, /* overwritten */
4813 tiOrSkip := {
4814 skipIndicator := '0000'B
4815 },
4816 msgs := {
4817 rrm := {
4818 gPRS_suspensionRequest := {
4819 messageType := '00110100'B,
4820 tLLI := tlli,
4821 routingAreaIdentification := rai,
4822 suspensionCause := cause,
4823 service_Support := omit
4824 }
4825 }
4826 }
4827}
4828
4829/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4830private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4831 var PCUIF_Message first_info;
4832 var integer pcu_conn_id := -1;
4833 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4834 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4835 var OCT4 tlli := '01020304'O;
4836 var OCT1 cause := '23'O;
4837 timer T := 5.0;
4838
4839 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4840
4841 f_l1_tune(L1CTL);
4842 RSL.clear;
4843
4844 f_est_dchan();
4845 L1CTL.clear;
4846
4847 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4848
4849 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4850 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4851 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4852
4853 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4854 T.start;
4855 alt {
4856 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4857 setverdict(pass);
4858 }
4859 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4860 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4861 }
4862 [] PCU.receive {
4863 repeat;
4864 }
4865 [] T.timeout {
4866 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4867 }
4868 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004869
4870 /* release the channel */
4871 f_rsl_chan_deact();
4872 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4873 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004874}
4875testcase TC_pcu_rr_suspend() runs on test_CT {
4876 var ConnHdlrPars pars;
4877 var ConnHdlr vc_conn;
4878
4879 f_init();
4880
4881 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4882 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4883 vc_conn.done;
4884}
Harald Welte07bd2d22019-05-25 11:03:30 +02004885
Harald Weltea2e0e942019-05-27 18:12:53 +02004886/* Ensure that PCUIF socket can accept only a single connection */
4887testcase TC_pcu_socket_connect_multi() runs on test_CT {
4888 timer T := 5.0;
4889
4890 /* this (among other things) establishes the first connection to the PCUIF socket */
4891 f_init();
4892
4893 /* try to establish a second connection, expect it to fail */
4894 PCU.send(UD_connect:{mp_pcu_socket, -1});
4895 T.start;
4896 alt {
4897 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4898 setverdict(pass);
4899 }
4900 [] PCU.receive(UD_connect_result:?) {
4901 setverdict(fail, "Unexpected unix domain connect result");
4902 }
4903 [] T.timeout {
4904 setverdict(pass);
4905 }
4906 }
4907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4908}
4909
Harald Weltec8effb72019-05-27 18:23:04 +02004910/* Ensure that PCUIF socket can disconnect + reconnect */
4911testcase TC_pcu_socket_reconnect() runs on test_CT {
4912 /* this (among other things) establishes the first connection to the PCUIF socket */
4913 f_init();
4914
4915 f_sleep(1.0);
4916
4917 f_pcuif_close(PCU, g_pcu_conn_id);
4918 g_pcu_conn_id := -1;
4919
4920 f_sleep(1.0);
4921
4922 /* re-connect */
4923 PCU.clear;
4924 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4925 setverdict(pass);
4926
4927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4928}
4929
Harald Weltebe030482019-05-27 22:29:35 +02004930/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07004931private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
4932runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02004933 var L1ctlDlMessage l1_dl;
4934 var SystemInformation si;
4935 timer T := 5.0;
4936 T.start;
4937 alt {
4938 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4939 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4940 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4941 log("Ignoring non-RR SI ", l1_dl);
4942 repeat;
4943 }
4944 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07004945 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02004946 repeat;
4947 }
4948 }
4949 [] pt.receive {
4950 repeat;
4951 }
4952 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07004953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4954 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02004955 }
4956 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07004957 return si;
Harald Weltebe030482019-05-27 22:29:35 +02004958}
4959
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004960/* Check if GPRS Indicator is present in RR System Information of a given type */
4961private function f_si_has_gprs_indicator(RrMessageType si_type)
4962runs on test_CT return boolean {
4963 var SystemInformation si := f_get_si(L1CTL, si_type);
4964
4965 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
4966 var RestOctets ro := si.payload.si3.rest_octets;
4967 var SI3RestOctets rest := dec_SI3RestOctets(ro);
4968 return rest.gprs_ind.presence == '1'B;
4969 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
4970 var RestOctets ro := si.payload.si4.rest_octets;
4971 var SI4RestOctets rest := dec_SI4RestOctets(ro);
4972 return rest.gprs_ind.presence == '1'B;
4973 }
4974
4975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
4976 return false;
Harald Weltebe030482019-05-27 22:29:35 +02004977}
4978
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004979/* Make sure that GPRS Indicator is absent when the PCU is not connected */
4980private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
4981runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02004982 /* don't call f_init() as this would connect PCU socket */
4983 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004984
4985 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02004986 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004987 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02004988
4989 f_init_l1ctl();
4990 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02004991 f_sleep(2.0);
4992 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004993
4994 if (f_si_has_gprs_indicator(si_type)) {
4995 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02004996 } else {
4997 setverdict(pass);
4998 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07004999
Harald Weltebe030482019-05-27 22:29:35 +02005000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5001}
5002
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005003testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5004 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5005}
Harald Weltebe030482019-05-27 22:29:35 +02005006
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005007testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5008 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5009}
5010
5011/* Ensure that GPRS capability is advertised after PCU socket connect */
5012private function f_TC_pcu_socket_connect(RrMessageType si_type)
5013runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005014 /* this (among other things) establishes the first connection to the PCUIF socket */
5015 f_init();
5016 f_init_l1ctl();
5017 f_l1_tune(L1CTL);
5018
5019 f_sleep(2.0);
5020 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005021
5022 if (not f_si_has_gprs_indicator(si_type)) {
5023 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005024 } else {
5025 setverdict(pass);
5026 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005027
Harald Weltebe030482019-05-27 22:29:35 +02005028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5029}
5030
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005031testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5032 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5033}
Harald Weltebe030482019-05-27 22:29:35 +02005034
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005035testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5036 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5037}
5038
5039/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5040private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5041runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005042 /* this (among other things) establishes the first connection to the PCUIF socket */
5043 f_init();
5044 f_init_l1ctl();
5045 f_l1_tune(L1CTL);
5046
5047 f_pcuif_close(PCU, g_pcu_conn_id);
5048 g_pcu_conn_id := -1;
5049
5050 f_sleep(1.0);
5051
5052 /* re-connect */
5053 PCU.clear;
5054 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5055
5056 f_sleep(2.0);
5057 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005058
5059 if (f_si_has_gprs_indicator(si_type)) {
5060 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005061 } else {
5062 setverdict(pass);
5063 }
5064
5065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5066}
5067
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005068testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5069 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5070}
5071
5072testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5073 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5074}
5075
Oliver Smithf5239c72019-08-28 10:01:25 +02005076/* 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) */
5077testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5078 var SystemInformation si3 := valueof(ts_SI3_default);
5079
5080 f_init();
5081
5082 /* Verify cell_id */
5083 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5084 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5085 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005086 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5087 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5088 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005089 }
5090
5091 /* Verify LAC */
5092 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5093 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5094 if (lac_si3 != lac_pcu) {
5095 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5096 }
5097
5098 setverdict(pass);
5099}
Harald Welted66c9b82019-05-25 09:03:15 +02005100
Harald Welte3d04ae62018-04-04 20:29:05 +02005101/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005102 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005103 ***********************************************************************/
5104
5105private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5106runs on ConnHdlr {
5107 var PCUIF_send_data sd;
5108 /* Expect BTS to immediately acknowledge activation as PDCH */
5109 PCU.clear;
5110 f_rsl_chan_act(g_pars.chan_mode);
5111 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005112 timer T_wait := 2.0;
5113 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005114 alt {
5115 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5116 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 +02005117 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5118 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5119 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005120 }
5121 }
5122 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005123 [] T_wait.timeout {
5124 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5125 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5126 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005127 }
5128 /* try to activate this PDCH from the PCU point of view */
5129 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5130 /* FIXME: is there a response? */
5131}
5132
5133private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5134runs on ConnHdlr {
5135 var PCUIF_send_data sd;
5136 /* Send RSL CHAN REL (deactivate) */
5137 PCU.clear;
5138 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5139 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005140 timer T_wait := 2.0;
5141 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005142 alt {
5143 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5144 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 +02005145 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5146 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5147 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005148 }
5149 }
5150 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005151 [] T_wait.timeout {
5152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5153 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5154 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005155 }
5156 /* Emulate PCU asking BTS to deactivate PDCH */
5157 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5158 alt {
5159 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5160 setverdict(pass);
5161 }
5162 [] RSL.receive { repeat; }
5163 }
5164}
5165
5166/* Activate Osmocom-style dynamic PDCH from BSC side */
5167function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5168 var PCUIF_Message first_info;
5169 var integer ts_nr := g_chan_nr.tn;
5170 var integer trx_nr := 0;
5171 var integer bts_nr := 0;
5172 var integer pcu_conn_id := -1;
5173
5174 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5175
5176 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5177 f_sleep(3.0);
5178 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5179 setverdict(pass);
5180}
5181testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5182 var ConnHdlrPars pars;
5183 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005184 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005185
5186 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5187 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5188 vc_conn.done;
5189}
5190
5191/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5192function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5193 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005194 var integer pcu_conn_id := -1;
5195
5196 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5197
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005198 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5199 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5200 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005201 setverdict(pass);
5202}
5203testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5204 var ConnHdlrPars pars;
5205 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005206 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005207
5208 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5209 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5210 vc_conn.done;
5211}
5212
5213/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5214function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5215 var PCUIF_Message first_info;
5216 var integer ts_nr := g_chan_nr.tn;
5217 var integer trx_nr := 0;
5218 var integer bts_nr := 0;
5219 var integer pcu_conn_id := -1;
5220
5221 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5222
5223 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005224 /* Send a second Chan Activ and expect it to be NACKed */
5225 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5226 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005227 setverdict(pass);
5228}
5229testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5230 var ConnHdlrPars pars;
5231 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005232 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005233
5234 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5235 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5236 vc_conn.done;
5237}
5238
5239/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5240function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5241 var PCUIF_Message first_info;
5242 var integer ts_nr := g_chan_nr.tn;
5243 var integer trx_nr := 0;
5244 var integer bts_nr := 0;
5245 var integer pcu_conn_id := -1;
5246 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5247
5248 /* register for the TCH/F channel number */
5249 f_rslem_register(0, chan_nr);
5250
5251 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5252
5253 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5254 "RSL CHAN ACT");
5255 setverdict(pass);
5256}
5257testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5258 var ConnHdlrPars pars;
5259 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005260 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005261
5262 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5263 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5264 vc_conn.done;
5265}
5266
5267/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5268function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5269 var PCUIF_Message first_info;
5270 var integer ts_nr := g_chan_nr.tn;
5271 var integer trx_nr := 0;
5272 var integer bts_nr := 0;
5273 var integer pcu_conn_id := -1;
5274 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5275 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5276
5277 /* register for the TCH/H channel numbers */
5278 f_rslem_register(0, chan_nr[0]);
5279 f_rslem_register(0, chan_nr[1]);
5280
5281 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5282
5283 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5284 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5285 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5286 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5287 setverdict(pass);
5288}
5289testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5290 var ConnHdlrPars pars;
5291 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005292 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005293
5294 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5295 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5296 vc_conn.done;
5297}
5298
Harald Welte9bbbfb52018-04-05 09:33:19 +02005299/***********************************************************************
5300 * IPA Style Dynamic Timeslot Support
5301 ***********************************************************************/
5302
5303private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5304runs on ConnHdlr {
5305 var PCUIF_send_data sd;
5306 /* Expect BTS to immediately acknowledge activation as PDCH */
5307 PCU.clear;
5308 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5309 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005310 timer T_wait := 2.0;
5311 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005312 alt {
5313 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5314 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 +01005315 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5316 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5317 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005318 }
5319 }
5320 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005321 [] T_wait.timeout {
5322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5323 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5324 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005325 }
5326 /* try to activate this PDCH from the PCU point of view */
5327 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5328 /* FIXME: is there a response? */
5329
5330 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5331}
5332
5333private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5334runs on ConnHdlr {
5335 var PCUIF_send_data sd;
5336 /* Send RSL CHAN REL (deactivate) */
5337 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5338 PCU.clear;
5339 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005340 timer T_wait := 2.0;
5341 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005342 alt {
5343 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5344 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 +01005345 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5346 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5347 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005348 }
5349 }
5350 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005351 [] T_wait.timeout {
5352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5353 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5354 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005355 }
5356 /* Emulate PCU asking BTS to deactivate PDCH */
5357 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5358 alt {
5359 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5360 setverdict(pass);
5361 }
5362 [] RSL.receive { repeat; }
5363 }
5364}
5365
5366/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5367function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5368 var PCUIF_Message first_info;
5369 var integer ts_nr := g_chan_nr.tn;
5370 var integer trx_nr := 0;
5371 var integer bts_nr := 0;
5372 var integer pcu_conn_id := -1;
5373
5374 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5375
5376 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5377 f_sleep(3.0);
5378 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5379
5380 setverdict(pass);
5381
5382}
5383testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5384 var ConnHdlrPars pars;
5385 var ConnHdlr vc_conn;
5386 f_init();
5387
5388 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5389 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5390 vc_conn.done;
5391}
5392
5393/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5394function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5395 var PCUIF_Message first_info;
5396 var integer ts_nr := g_chan_nr.tn;
5397 var integer trx_nr := 0;
5398 var integer bts_nr := 0;
5399 var integer pcu_conn_id := -1;
5400
5401 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5402
5403 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5404 "RSL CHAN ACT");
5405 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5406 "RF CHAN REL", true);
5407 setverdict(pass);
5408}
5409testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5410 var ConnHdlrPars pars;
5411 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005412 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005413
5414 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5415 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5416 vc_conn.done;
5417}
5418
5419/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5420function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5421 var PCUIF_Message first_info;
5422 var integer ts_nr := g_chan_nr.tn;
5423 var integer trx_nr := 0;
5424 var integer bts_nr := 0;
5425 var integer pcu_conn_id := -1;
5426
5427 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5428
5429 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5430 "RSL CHAN ACT");
5431
5432 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5433 alt {
5434 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5435 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005437 }
5438 [] RSL.receive { repeat; }
5439 }
5440
5441 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5442 "RF CHAN REL", true);
5443 setverdict(pass);
5444}
5445testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5446 var ConnHdlrPars pars;
5447 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005448 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005449
5450 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5451 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5452 vc_conn.done;
5453}
5454
5455/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5456function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5457 var PCUIF_Message first_info;
5458 var integer ts_nr := g_chan_nr.tn;
5459 var integer trx_nr := 0;
5460 var integer bts_nr := 0;
5461 var integer pcu_conn_id := -1;
5462
5463 /* register for the TCH/F channel number */
5464 f_rslem_register(0, g_chan_nr);
5465
5466 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5467
5468 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5469
5470 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5471 "RSL CHAN ACT");
5472
5473 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5474
5475 setverdict(pass);
5476}
5477testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5478 var ConnHdlrPars pars;
5479 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005480 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005481
5482 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5483 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5484 vc_conn.done;
5485}
5486
5487
Harald Welte0472ab42018-03-12 15:02:26 +01005488/***********************************************************************
5489 * LAPDm / RLL related
5490 ***********************************************************************/
5491
5492private function f_tx_lapdm(template (value) LapdmFrame l,
5493 template (value) RslLinkId link_id) runs on ConnHdlr {
5494 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005495 var template (value) SacchL1Header l1h;
5496
5497 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005498 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005499 /* Compose dummy L1 header */
5500 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5501 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 +02005502 } else {
5503 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005504 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 +01005505 }
Harald Welte0472ab42018-03-12 15:02:26 +01005506}
5507
5508type record RllTestCase {
5509 uint3_t sapi,
5510 RslLinkId link_id,
5511 octetstring l3,
5512 boolean exp
5513}
5514type record of RllTestCase RllTestCases;
5515template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5516 sapi := sapi,
5517 link_id := id,
5518 l3 := l3,
5519 exp := exp
5520}
5521
5522/* execute the same callback function with a set of different parameters (tcs) on a
5523 * variety of logical channels */
5524private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5525 var ConnHdlrPars pars;
5526 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005527 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005528
5529 /* test on each of the channels we have */
5530 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5531 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5532
5533 /* test each of the test cases on the current channel */
5534 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5535 pars.spec.rll := tcs[j];
5536 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5537 vc_conn := f_start_handler(fn, pars);
5538 vc_conn.done;
5539 }
5540 }
5541
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005543}
5544
5545/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5546private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5547 var RllTestCase tc := g_pars.spec.rll;
5548 timer T := 3.0;
5549
5550 f_l1_tune(L1CTL);
5551 RSL.clear;
5552
5553 /* activate the logical channel */
5554 f_est_dchan();
5555 L1CTL.clear;
5556
5557 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5558 T.start;
5559 alt {
5560 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5561 if (tc.exp) {
5562 setverdict(pass);
5563 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005565 }
5566 }
5567 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5568 if (tc.exp) {
5569 setverdict(pass);
5570 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005572 }
5573 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005574 /* We also expect to receive the measurements */
5575 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005576 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005578 }
5579 [not tc.exp] T.timeout {
5580 setverdict(pass);
5581 }
5582 }
5583
5584 f_rsl_chan_deact();
5585 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5586 f_rslem_unregister(0, g_chan_nr);
5587}
5588testcase TC_rll_est_ind() runs on test_CT {
5589 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005590 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005591 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005592 /* normal SAPI0 establishment */
5593 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005594 /* SAPI 3 doesn't support contention resolution */
5595 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5596 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5597 /* normal SAPI3 establishment on main DCCH */
5598 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5599 /* normal SAPI3 establishment on SACCH */
5600 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5601 };
5602 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5603}
5604
5605/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5606private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5607 var RllTestCase tc := g_pars.spec.rll;
5608 var L1ctlDlMessage dl;
5609 timer T := 3.0;
5610
5611 f_l1_tune(L1CTL);
5612 RSL.clear;
5613
5614 /* activate the logical channel */
5615 f_est_dchan();
5616 L1CTL.clear;
5617
5618 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5619 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5620 T.start;
5621 alt {
5622 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5623 var LapdmFrame lapdm;
5624 var octetstring l2 := dl.payload.data_ind.payload;
5625 if (dl.dl_info.link_id.c == SACCH) {
5626 /* remove L1 header */
5627 l2 := substr(l2, 2, lengthof(l2)-2);
5628 }
5629 lapdm.ab := dec_LapdmFrameAB(l2);
5630 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5631 setverdict(pass);
5632 } else {
5633 repeat;
5634 }
5635 }
5636 [] L1CTL.receive { repeat; }
5637 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005639 }
5640 }
5641
5642 f_rsl_chan_deact();
5643 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5644 f_rslem_unregister(0, g_chan_nr);
5645}
5646testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5647 var RllTestCases tcs := {
5648 /* normal SAPI3 establishment on main DCCH */
5649 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5650 };
5651 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5652}
5653testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5654 var RllTestCases tcs := {
5655 /* normal SAPI3 establishment on SACCH */
5656 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5657 }
5658 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5659}
5660
5661/* altstep to receive a LAPDm frame matching the given template */
5662private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5663 var L1ctlDlMessage dl;
5664 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5665 var LapdmFrame lapdm;
5666 var octetstring l2 := dl.payload.data_ind.payload;
5667 if (dl.dl_info.link_id.c == SACCH) {
5668 /* remove L1 header */
5669 l2 := substr(l2, 2, lengthof(l2)-2);
5670 }
5671 if (ischosen(exp.ab)) {
5672 lapdm.ab := dec_LapdmFrameAB(l2);
5673 } else if (ischosen(exp.b4)) {
5674 lapdm.b4 := dec_LapdmFrameB4(l2);
5675 } else if (ischosen(exp.bbis)) {
5676 lapdm.bbis := dec_LapdmFrameBbis(l2);
5677 }
5678 log("Rx LAPDm ", lapdm);
5679 if (match(lapdm, exp)) {
5680 setverdict(pass);
5681 } else {
5682 repeat;
5683 }
5684 }
5685 [] L1CTL.receive { repeat; }
5686}
5687private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5688 timer T := t;
5689 T.start;
5690 alt {
5691 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005693 }
5694 [] as_l1_exp_lapdm(exp);
5695 }
5696}
5697
5698/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5699private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5700 /* send SABM from MS -> BTS */
5701 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5702 /* expect RLL EST IND on Abis */
5703 alt {
5704 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5705 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5706 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005708 }
5709 [] RSL.receive { repeat; }
5710 }
5711 /* expect UA from BTS -> MS */
5712 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5713}
5714
5715/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5716private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5717 var RllTestCase tc := g_pars.spec.rll;
5718
5719 f_l1_tune(L1CTL);
5720 RSL.clear;
5721
5722 /* activate the logical channel */
5723 f_est_dchan();
5724 L1CTL.clear;
5725
5726 /* first establish the link-layer */
5727 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5728
5729 /* then send the DISC */
5730 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5731 /* ... and expect the REL IND on the RSL side */
5732 alt {
5733 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5734 setverdict(pass);
5735 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005736 /* We also expect to receive the measurements */
5737 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005738 }
5739
5740 /* release the channel */
5741 f_rsl_chan_deact();
5742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5743 f_rslem_unregister(0, g_chan_nr);
5744}
5745testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5746 var RllTestCases tcs := {
5747 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5748 };
5749 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5750}
5751
5752testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5753 var RllTestCases tcs := {
5754 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5755 };
5756 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5757}
5758testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5759 var RllTestCases tcs := {
5760 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5761 };
5762 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5763}
5764testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5765 var RllTestCases tcs := {
5766 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5767 };
5768 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5769}
5770
5771/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5772private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5773 var RllTestCase tc := g_pars.spec.rll;
5774 f_l1_tune(L1CTL);
5775 RSL.clear;
5776
5777 /* activate the logical channel */
5778 f_est_dchan();
5779 L1CTL.clear;
5780
5781 /* first establish the link-layer */
5782 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5783
5784 /* then send the REL REQ via RSL */
5785 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5786 /* ... and expect the DISC on the Um side */
5787 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005788 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005789 /* FIXME: send a UA in resposne to the DISC */
5790 }
5791 }
5792
5793 /* release the channel */
5794 f_rsl_chan_deact();
5795 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5796 f_rslem_unregister(0, g_chan_nr);
5797}
5798testcase TC_rll_rel_req() runs on test_CT {
5799 var RllTestCases tcs := {
5800 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5801 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5802 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5803 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5804 };
5805 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5806}
5807
5808/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5809testcase TC_rll_data_req() runs on test_CT {
5810}
5811
5812/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5813testcase TC_rll_data_ind() runs on test_CT {
5814}
5815
5816/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5817private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5818 var RllTestCase tc := g_pars.spec.rll;
5819
5820 f_l1_tune(L1CTL);
5821 RSL.clear;
5822
5823 f_est_dchan();
5824 L1CTL.clear;
5825
5826 /* Send UNITDATA REQ on RSL side */
5827 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5828 /* Expect it to arrive on the other side */
5829 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005830 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005831 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005832 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005833 }
5834
5835 /* release the channel */
5836 f_rsl_chan_deact();
5837 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5838 f_rslem_unregister(0, g_chan_nr);
5839}
5840testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5841 var octetstring l3 := f_rnd_octstring(15);
5842 var RllTestCases tcs := {
5843 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5844 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5845 };
5846 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5847}
5848testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5849 var octetstring l3 := f_rnd_octstring(19);
5850 var RllTestCases tcs := {
5851 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5852 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5853 };
5854 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5855}
5856
5857/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5858private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5859 var RllTestCase tc := g_pars.spec.rll;
5860
5861 f_l1_tune(L1CTL);
5862 RSL.clear;
5863
5864 f_est_dchan();
5865 L1CTL.clear;
5866
5867 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005868 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005869 /* Expdct RLL UNITDATA IND on RSL side */
5870 alt {
5871 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5872 setverdict(pass);
5873 }
5874 [] RSL.receive { repeat; }
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_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005883 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005884 var RllTestCases tcs := {
5885 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5886 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5887 };
5888 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5889}
5890testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5891 var octetstring l3 := f_rnd_octstring(18);
5892 var RllTestCases tcs := {
5893 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5894 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5895 };
5896 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5897}
5898
Harald Weltee613f962018-04-18 22:38:16 +02005899/***********************************************************************
5900 * Encryption Related
5901 ***********************************************************************/
5902
5903/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5904function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5905 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5906 if (link_id.c == SACCH) {
5907 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5908 } else {
5909 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5910 }
5911}
5912
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005913/* Expect (or not expect) other kinds of messages */
5914private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5915 [exp_any] RSL.receive { repeat; }
5916 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005918 }
5919}
5920
Harald Weltee613f962018-04-18 22:38:16 +02005921/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005922private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005923 RslLinkId link_id,
5924 octetstring l3,
5925 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005926 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005927) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005928 timer T := 3.0;
5929 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5930 T.start;
5931 /* Expect RLL UNITDATA IND on RSL side */
5932 alt {
5933 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5934 setverdict(pass);
5935 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005936 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005937 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005938 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005940 }
Harald Weltee613f962018-04-18 22:38:16 +02005941 }
5942}
5943
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005944/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5945private function f_data_mo(
5946 RslLinkId link_id,
5947 boolean p, uint3_t nr, uint3_t ns,
5948 octetstring l3,
5949 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005950 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005951) runs on ConnHdlr {
5952 timer T := 3.0;
5953 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5954 T.start;
5955 /* Expect RLL DATA IND on RSL side */
5956 alt {
5957 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5958 setverdict(pass);
5959 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005960 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005961 [] as_rsl_any_ind(exp_any);
5962 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005964 }
5965 }
5966}
5967
Harald Weltee613f962018-04-18 22:38:16 +02005968/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5969function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5970 f_l1_tune(L1CTL);
5971 f_est_dchan(true);
5972
5973 /* now we actually need to transmit some data both ways to check if the encryption works */
5974 var L1ctlDlMessage dl;
5975
Stefan Sperling603d98e2018-07-25 16:47:28 +02005976 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005977 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5978
5979 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5980 f_unitdata_mt(link_id, l3);
5981
5982 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5983 f_unitdata_mo(link_id, l3);
5984
5985 /* release the channel */
5986 f_rsl_chan_deact();
5987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5988 f_rslem_unregister(0, g_chan_nr);
5989}
5990testcase TC_chan_act_a51() runs on test_CT {
5991 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5992 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5993 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5994}
5995testcase TC_chan_act_a52() runs on test_CT {
5996 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5997 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5998 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5999}
6000testcase TC_chan_act_a53() runs on test_CT {
6001 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6002 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6003 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6004}
6005
Eric Wildf1827a72019-05-28 17:37:35 +02006006/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6007 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
6008function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
6009 f_l1_tune(L1CTL);
6010 f_est_dchan(true);
6011
6012 /* now we actually need to transmit some data both ways to check if the encryption works */
6013 var L1ctlDlMessage dl;
6014
6015 var octetstring l3 := f_rnd_octstring(20);
6016 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6017
6018 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6019 f_unitdata_mt(link_id, l3);
6020
6021 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6022 f_unitdata_mo(link_id, l3);
6023
6024 var RSL_Message rsl;
6025 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6026
6027 /* modify key to break proper encryption */
6028 g_pars.encr.key := f_rnd_octstring(8);
6029 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6030 rsl.ies := rsl.ies & { ei };
6031 RSL.send(rsl);
6032
6033 timer T0 := 1.0;
6034 T0.start;
6035 /* Expect RSL MODIFY ACK */
6036 alt {
6037 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6038 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6040 }
6041 [] T0.timeout {
6042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6043 }
6044 }
6045
6046 var octetstring l3msg := f_rnd_octstring(15);
6047 timer T1 := 3.0;
6048 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6049 due to broken encryption */
6050 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6051 T1.start;
6052 alt {
6053 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6055 }
6056 [] T1.timeout {
6057 setverdict(pass);
6058 }
6059 }
6060
6061 /* release the channel */
6062 f_rsl_chan_deact();
6063 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6064 f_rslem_unregister(0, g_chan_nr);
6065}
6066testcase TC_rsl_modify_encr() runs on test_CT {
6067 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6068 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6069 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6070}
Harald Weltee613f962018-04-18 22:38:16 +02006071
6072/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6073function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6074 /* L3 payload doesn't matter, as it is passed transparently */
6075 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6076 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6077 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6078
6079 f_l1_tune(L1CTL);
6080
6081 /* first establish a dedicated channel in the clear */
6082 f_est_dchan(false);
6083
6084 /* Establish ABM */
6085 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6086
6087 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6088 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6089 /* expect the L3 to arrive still unencrypted on the MS side */
6090 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6091
6092 /* configure L1 to apply ciphering */
6093 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6094 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6095
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006096 /* send first ciphered I-frame in response and expect it on RSL */
6097 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006098
6099 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6100 * and hence enable encryption also on the downlink */
6101
6102 /* expect bi-directional communication work in encrypted mode */
6103 f_unitdata_mo(link_id, f_rnd_octstring(15));
6104 f_unitdata_mt(link_id, f_rnd_octstring(15));
6105
6106 /* release the channel */
6107 f_rsl_chan_deact();
6108 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6109 f_rslem_unregister(0, g_chan_nr);
6110}
6111testcase TC_encr_cmd_a51() runs on test_CT {
6112 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6113 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6114 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6115}
6116testcase TC_encr_cmd_a52() runs on test_CT {
6117 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6118 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6119 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6120}
6121testcase TC_encr_cmd_a53() runs on test_CT {
6122 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6123 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6124 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6125}
6126
6127private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6128 var LapdmFrame lf;
6129 var octetstring reenc;
6130
6131 /* decode the LAPDm frame */
6132 if (ischosen(exp_match.ab)) {
6133 lf.ab := dec_LapdmFrameAB(enc);
6134 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006136 }
6137
6138 /* check if decoder result matches expectation */
6139 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006141 } else {
6142 log(name, ": matched");
6143 setverdict(pass);
6144 }
6145
6146 /* test if re-encoded frame equals original input */
6147 reenc := enc_LapdmFrame(lf);
6148 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006150 } else {
6151 setverdict(pass);
6152 }
6153}
6154
6155testcase TC_lapdm_selftest() runs on test_CT {
6156 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6157 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6158 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6159 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6160 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6161 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6162 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6163}
6164
Stefan Sperling4880be42018-08-07 18:12:59 +02006165/***********************************************************************
6166 * DTX Related (see GSM 05.08, section 8.3)
6167 ***********************************************************************/
6168
6169/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6170function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6171 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6172 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6173 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6174 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6175}
6176function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6177 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6178 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6179}
6180function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6181 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6182 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6183 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6184 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6185}
6186function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6187 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6188 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6189 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6190 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6191 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6192 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6193 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6194 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6195}
6196
6197function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6198 var L1ctlDlMessage dl;
6199 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6200 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6201 var GsmFrameNumber first_fn;
6202 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006203 var integer nfill_frames_sacch := 0;
6204 var integer nfill_frames_nonsacch := 0;
6205 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006206 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6207 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006208 const integer frame_dtx_tchf_mod := 104;
6209 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6210 * which operates in terms of blocks rather than frames. */
6211 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6212 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006213 timer T := 5.0;
6214
6215 f_l1_tune(L1CTL);
6216 RSL.clear;
6217 L1CTL.clear;
6218
6219 /* activate TCHF signalling channel */
6220 f_est_dchan(false);
6221
6222 T.start;
6223 alt {
6224 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6225 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6226 var octetstring l2 := dl.payload.data_ind.payload;
6227
6228 if (is_first_frame) {
6229 is_first_frame := false;
6230 first_fn := dl.dl_info.frame_nr;
6231 }
6232
6233 if (dl.dl_info.link_id.c == SACCH) {
6234 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6235 if (not match(l2_fill_frame_sacch, l2)) {
6236 repeat;
6237 }
6238 } else if (not match(l2_fill_frame, l2)) {
6239 repeat;
6240 }
6241
6242 if (dtxd) {
6243 if (not f_g_chan_is_tchf()) {
6244 T.stop;
6245 f_rsl_chan_deact();
6246 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006247 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 +02006248 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006249 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006250 T.stop;
6251 f_rsl_chan_deact();
6252 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006253
6254 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6255 * 2 SACCH, 1 TCH/F */
6256 expected_fill_frames := 3;
6257
6258 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6259 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6260 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006262 } else {
6263 setverdict(pass);
6264 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006265 } else {
6266 if (dl.dl_info.link_id.c == SACCH) {
6267 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006268 repeat;
6269 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006270 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6271 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6272 * we should only see the subset of frames numbers which correspond to a block boundary.
6273 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6274 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6275 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6276 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6277 repeat;
6278 }
6279 }
6280 log("Received DTX TCH fill frame with bad frame number: ", fn,
6281 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6282 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6283 f_rsl_chan_deact();
6284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006286 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006287 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006288 if (dl.dl_info.link_id.c == SACCH) {
6289 nfill_frames_sacch := nfill_frames_sacch + 1;
6290 } else {
6291 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6292 }
6293 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006294 T.stop;
6295 if (f_g_chan_is_tchf()) {
6296 /* Without DTX we can expect 25 fill frames for every 104 frames.
6297 * (24 FACCH + 1 SACCH filling) */
6298 expected_fill_frames := 25;
6299 } else if (f_g_chan_is_tchh()) {
6300 /* We can expect 2 fill frames for every 104 frames. */
6301 expected_fill_frames := 2;
6302 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6303 /* We can expect 5 fill frames for every 104 frames. */
6304 expected_fill_frames := 5;
6305 } else {
6306 f_rsl_chan_deact();
6307 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006309 }
6310
6311 f_rsl_chan_deact();
6312 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006313
6314 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006315 setverdict(pass);
6316 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006317 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6318 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006320 }
6321 } else {
6322 repeat;
6323 }
6324 }
6325 }
6326 [] L1CTL.receive { repeat; }
6327 [] T.timeout {
6328 f_rsl_chan_deact();
6329 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006331 }
6332 }
6333}
6334
6335function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6336 f_test_l2_fill_frames(false);
6337}
6338
6339function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6340 f_test_l2_fill_frames(true);
6341}
6342
6343function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6344 var ConnHdlr vc_conn;
6345 var ConnHdlrPars pars;
6346 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006347 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006348 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6349 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6350 if (dtxd) {
6351 if (i >= 4) { /* DTX is only allowed on TCH/F */
6352 break;
6353 }
6354 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6355 } else {
6356 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6357 }
6358 vc_conn.done;
6359 }
6360}
6361
6362/* Verify that L2 fill frames are sent on TCH in signaling mode if
6363 * there is nothing to transmit while DTX is disabled on downlink. */
6364testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6365 f_tch_sign_l2_fill_frame(false);
6366}
6367
6368/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6369 * there is nothing to transmit while DTX is enabled on downlink. */
6370testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6371 f_tch_sign_l2_fill_frame(true);
6372}
Harald Welte0472ab42018-03-12 15:02:26 +01006373
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006374testcase TC_chopped_ipa_ping() runs on test_CT {
6375 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6376}
6377
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006378testcase TC_chopped_ipa_payload() runs on test_CT {
6379 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6380}
6381
Harald Welte0472ab42018-03-12 15:02:26 +01006382/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6383/* protocol error as per 44.006 */
6384/* link layer failure (repetition of I-frame N200 times without ACK */
6385/* repetition of SABM or DISC N200 times without ACK */
6386/* receptiom of SABM in multi-frame established state */
6387
6388
Harald Welte68e495b2018-02-25 00:05:57 +01006389/* TODO Areas:
6390
6391* channel activation
6392** with BS_Power / MS_Power, bypassing power control loop
6393** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006394** with timing advance from initial activation on
6395* mode modify
6396** encryption
6397** multirate
6398* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006399** unsupported algorithm
6400* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006401* BS Power Control
6402* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006403* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006404* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006405** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006406* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006407** DATA_IND from BTS->PCU
6408** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006409
6410*/
Harald Welte70767382018-02-21 12:16:40 +01006411
6412control {
6413 execute( TC_chan_act_stress() );
6414 execute( TC_chan_act_react() );
6415 execute( TC_chan_deact_not_active() );
6416 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006417 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006418 execute( TC_sacch_filling() );
6419 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006420 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006421 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006422 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006423 execute( TC_sacch_chan_act_ho_async() );
6424 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006425 execute( TC_rach_content() );
6426 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006427 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006428 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006429 execute( TC_rach_load_idle_thresh0() );
6430 execute( TC_rach_load_idle_below_thresh() );
6431 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006432 execute( TC_meas_res_sign_tchf() );
6433 execute( TC_meas_res_sign_tchh() );
6434 execute( TC_meas_res_sign_sdcch4() );
6435 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006436 execute( TC_meas_res_sign_tchh_toa256() );
Eric Wildae8f2622019-06-18 17:05:11 +02006437 execute( TC_rsl_bs_pwr_static_ass() );
6438 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006439 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006440 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006441 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006442 execute( TC_rsl_ms_pwr_dyn_up() );
6443 execute( TC_rsl_ms_pwr_dyn_down() );
6444 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6445 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006446 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006447 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006448 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006449 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006450 execute( TC_paging_imsi_80percent() );
6451 execute( TC_paging_tmsi_80percent() );
6452 execute( TC_paging_imsi_200percent() );
6453 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006454 execute( TC_rsl_protocol_error() );
6455 execute( TC_rsl_mand_ie_error() );
6456 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006457 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006458 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006459 execute( TC_si_sched_2bis() );
6460 execute( TC_si_sched_2ter() );
6461 execute( TC_si_sched_2ter_2bis() );
6462 execute( TC_si_sched_2quater() );
6463 execute( TC_si_sched_13() );
6464 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006465 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006466 execute( TC_ipa_crcx_twice_not_active() );
6467 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006468 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006469 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006470
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006471 if (mp_pcu_socket != "") {
6472 execute( TC_pcu_act_req() );
6473 execute( TC_pcu_act_req_wrong_ts() );
6474 execute( TC_pcu_act_req_wrong_bts() );
6475 execute( TC_pcu_act_req_wrong_trx() );
6476 execute( TC_pcu_deact_req() );
6477 execute( TC_pcu_deact_req_wrong_ts() );
6478 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006479 if (mp_l1_supports_gprs) {
6480 execute( TC_pcu_data_req_pdtch() );
6481 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006482 execute( TC_pcu_data_req_wrong_bts() );
6483 execute( TC_pcu_data_req_wrong_trx() );
6484 execute( TC_pcu_data_req_wrong_ts() );
6485 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006486 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006487 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006488 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006489 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006490 execute( TC_pcu_data_req_imm_ass_pch() );
6491 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006492 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006493 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006494 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006495 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006496 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006497 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006498 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006499 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006500 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006501 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006502 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006503 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006504 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006505 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006506 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006507 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006508 execute( TC_dyn_osmo_pdch_act_deact() );
6509 execute( TC_dyn_osmo_pdch_double_act() );
6510 execute( TC_dyn_ipa_pdch_act_deact() );
6511 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6512
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006513 } else {
6514 log("PCU socket path not available, skipping PCU tests");
6515 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006516
Harald Welte3d04ae62018-04-04 20:29:05 +02006517 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006518 execute( TC_dyn_osmo_pdch_tchf_act() );
6519 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006520 execute( TC_dyn_ipa_pdch_tchf_act() );
6521 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006522
6523 execute( TC_rll_est_ind() );
6524 execute( TC_rll_est_req_DCCH_3() );
6525 execute( TC_rll_est_req_ACCH_3() );
6526 execute( TC_rll_rel_ind_DCCH_0() );
6527 execute( TC_rll_rel_ind_DCCH_3() );
6528 execute( TC_rll_rel_ind_ACCH_0() );
6529 execute( TC_rll_rel_ind_ACCH_3() );
6530 execute( TC_rll_rel_req() );
6531 execute( TC_rll_unit_data_req_DCCH() );
6532 execute( TC_rll_unit_data_req_ACCH() );
6533 execute( TC_rll_unit_data_ind_DCCH() );
6534 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006535
6536 execute( TC_chan_act_a51() );
6537 execute( TC_chan_act_a52() );
6538 execute( TC_chan_act_a53() );
6539 execute( TC_encr_cmd_a51() );
6540 execute( TC_encr_cmd_a52() );
6541 execute( TC_encr_cmd_a53() );
6542
Harald Welteee25aae2019-05-19 14:32:37 +02006543 execute( TC_err_rep_wrong_mdisc() );
6544 execute( TC_err_rep_wrong_msg_type() );
6545 execute( TC_err_rep_wrong_sequence() );
6546
Harald Weltee613f962018-04-18 22:38:16 +02006547 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006548
6549 execute( TC_tch_sign_l2_fill_frame() );
6550 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006551
6552 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006553 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006554}
6555
6556
6557}