blob: d9ad45bcc621d3c555b29d478046394f107d2457 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010038import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020039import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010040
41import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010042import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010043import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020044import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010045import from RSL_Emulation all;
46
47import from IPL4asp_Types all;
48import from TRXC_Types all;
49import from TRXC_CodecPort all;
50import from TRXC_CodecPort_CtrlFunct all;
51
Harald Welte883340c2018-02-28 18:59:29 +010052import from PCUIF_Types all;
53import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020054import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010055
Harald Welte7484fc42018-02-24 14:09:45 +010056import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010057import from MobileL3_RRM_Types all;
58import from MobileL3_Types all;
59import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020060import from L3_Common all;
61import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010062
Harald Welte8da48242018-02-27 20:41:32 +010063import from Osmocom_VTY_Functions all;
64import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020065import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010066
Harald Welte505cf9b2018-09-15 17:47:23 +030067friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020068friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020069friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010070friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030071
Harald Welte70767382018-02-21 12:16:40 +010072/* The tests assume a BTS with the following timeslot configuration:
73 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020074 * TS1 : TCH/F
75 * TS2 : TCH/F
76 * TS3 : TCH/F_PDCH (IPA Style)
77 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010078 * TS5 : TCH/H
79 * TS6 : SDCCH/8
80 * TS7 : PDCH
81 */
82
83modulepar {
84 charstring mp_rsl_ip := "127.0.0.2";
85 integer mp_rsl_port := 3003;
86 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070087 integer mp_trx1_arfcn := 873;
88 integer mp_trx2_arfcn := 875;
89 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070090 charstring mp_bts_trxc_ip := "127.0.0.1";
91 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010092 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020093 charstring mp_ctrl_ip := "127.0.0.1";
94 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020095 charstring mp_bsc_ctrl_ip := "127.0.0.1";
96 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020097 integer mp_tolerance_rxqual := 1;
98 integer mp_tolerance_rxlev := 3;
99 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200100 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200101 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200102 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200103 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
104 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200105 integer mp_ms_actual_ta_exp := 0;
106 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700114 /* frequency hopping status */
115 boolean mp_freq_hop_enabled := false;
116 /* frequency hopping parameters */
117 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100118}
119
Harald Welte629cc6b2018-03-11 17:19:05 +0100120type record of RslChannelNr ChannelNrs;
121
Harald Welte70767382018-02-21 12:16:40 +0100122type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100123 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100124 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100125 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100126 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100128 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100129
130 /* L1CTL port (for classic tests) */
131 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100132
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700133 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700134 port TRXC_CODEC_PT BTS_TRXC;
135 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100136
Harald Weltef50e3ae2018-09-10 10:27:56 +0200137 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100138 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200139 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100140
Harald Welte883340c2018-02-28 18:59:29 +0100141 /* PCU Interface of BTS */
142 port PCUIF_CODEC_PT PCU;
143 var integer g_pcu_conn_id;
144 /* Last PCU INFO IND we received */
145 var PCUIF_Message g_pcu_last_info;
146
Harald Welte48494ca2018-02-25 16:59:50 +0100147 /* SI configuration */
148 var SystemInformationConfig si_cfg := {
149 bcch_extended := false,
150 si1_present := false,
151 si2bis_present := false,
152 si2ter_present := false,
153 si2quater_present := false,
154 si7_present := false,
155 si8_present := false,
156 si9_present := false,
157 si13_present := false,
158 si13alt_present := false,
159 si15_present := false,
160 si16_present := false,
161 si17_present := false,
162 si2n_present := false,
163 si21_present := false,
164 si22_present := false
165 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100166
167 /* all logical channels available on the BTS */
168 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100169 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100170}
171
172/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200173type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100174 port L1CTL_PT L1CTL;
175
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700176 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700177 port TRXC_CODEC_PT BTS_TRXC;
178 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100179
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200180 /* port to be initialized optionally to access BSC VTY */
181 port TELNETasp_PT BSCVTY;
182
Harald Welte70767382018-02-21 12:16:40 +0100183 timer g_Tguard;
184 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
185
186 var ConnHdlrPars g_pars;
187 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100188 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200189
190 /* PCU Interface of BTS */
191 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100192}
193
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700194private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700195 var bitstring trx_mask := '00000000'B;
196 var integer trx_count := 0;
197 var RSLEm_Event ev;
198 timer T;
199
Harald Welte70767382018-02-21 12:16:40 +0100200 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
201 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
202
203 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
204 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
205 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
206
207 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
208 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700209
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700210 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700211 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700212 T.start(mp_ipa_up_timeout);
213 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700214 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
216 /* Make sure that all transceivers use unique stream ID */
217 if (trx_mask[enum2int(ev.sid)] == '1'B) {
218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
219 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
220 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700221
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700222 /* This message (RF RESource INDication) is sent by the IUT itself */
223 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
224 trx_mask[enum2int(ev.sid)] := '1'B;
225 trx_count := trx_count + 1;
226
227 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
228 if (trx_count < mp_transceiver_num) { repeat; }
229 }
230 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
231 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
232 [] T.timeout {
233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
234 "Timeout waiting for RSL bring up");
235 }
236 }
Harald Welte70767382018-02-21 12:16:40 +0100237}
238
239type record ConnHdlrPars {
240 RslChannelNr chan_nr,
241 RSL_IE_ChannelMode chan_mode,
242 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100243 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200244 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200245 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700246 BtsBand bts0_band optional,
247
248 /* Frequency hopping parameters (disabled if absent) */
249 MaioHsn maio_hsn optional,
250 /* MA bitmap to be indicated in RR Immediate Assignment */
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700251 MobileAllocationLV ma_map,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700252 /* The actual Mobile Allocation (ARFCN list) to be used */
253 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100254}
255
256/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700257private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100258 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100259}
260
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700261private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100262 max_retrans := RACH_MAX_RETRANS_7,
263 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100264 cell_barr_access := false,
265 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100266 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100267};
268
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700269private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100270 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200271 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100272 acs := '0'B,
273 neci := true,
274 rxlev_access_min := 0
275}
276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700277private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100278 mcc_mnc := '262F42'H,
279 lac := 42
280}
281
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700282private template (value) GPRSIndicator ts_GPRSIndicator_def := {
283 ra_colour := 0,
284 si13_pos := '0'B
285}
286
287private template (value) SI3RestOctets ts_SI3RestOctets_def
288modifies ts_SI3RestOctets := {
289 gprs_ind := {
290 presence := CSN1_H,
291 ind := ts_GPRSIndicator_def
292 }
293}
294
295private template (value) SI4RestOctets ts_SI4RestOctets_def
296modifies ts_SI4RestOctets := {
297 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700298 presence := CSN1_H,
299 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700300 }
301}
302
Harald Welte7484fc42018-02-24 14:09:45 +0100303/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100305 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100306 payload := {
307 si3 := {
308 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100309 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100310 ctrl_chan_desc := {
311 msc_r99 := true,
312 att := true,
313 bs_ag_blks_res := 1,
314 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100315 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100316 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
317 spare := '00'B,
318 bs_pa_mfrms := 0, /* 2 multiframes */
319 t3212 := 1 /* 6 minutes */
320 },
Harald Welte82ccef72018-02-25 16:17:33 +0100321 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100322 dn_ind := false,
323 pwrc := false,
324 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100325 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100326 },
Harald Weltef10153f2018-02-25 16:34:05 +0100327 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100328 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200329 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100330 }
331 }
332}
Harald Welte70767382018-02-21 12:16:40 +0100333
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700334private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100335 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100336 payload := {
337 si2 := {
338 bcch_freq_list := '00000000000000000000000000000000'O,
339 ncc_permitted := '11111111'B,
340 rach_control := ts_RachCtrl_default
341 }
342 }
343}
344
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700345private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100346 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100347 payload := {
348 si4 := {
349 lai := ts_LAI_default,
350 cell_sel_par := ts_CellSelPar_default,
351 rach_control := ts_RachCtrl_default,
352 cbch_chan_desc := omit,
353 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200354 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100355 }
356 }
357}
358
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700359private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100360runs on test_CT {
361 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700362 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100363}
364
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700365private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100366runs on test_CT {
367 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
368 log("Setting ", rsl_si_type, ": ", si_dec);
369 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
370}
371
Harald Welte505cf9b2018-09-15 17:47:23 +0300372friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100373 map(self:BTSVTY, system:BTSVTY);
374 f_vty_set_prompts(BTSVTY);
375 f_vty_transceive(BTSVTY, "enable");
376}
377
Harald Welte505cf9b2018-09-15 17:47:23 +0300378friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200379 map(self:BSCVTY, system:BSCVTY);
380 f_vty_set_prompts(BSCVTY, "OsmoBSC");
381 f_vty_transceive(BSCVTY, "enable");
382}
383
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200384friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
385 map(self:BSCVTY, system:BSCVTY);
386 f_vty_set_prompts(BSCVTY, "OsmoBSC");
387 f_vty_transceive(BSCVTY, "enable");
388}
389
Harald Welte883340c2018-02-28 18:59:29 +0100390/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200391private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
392 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100393 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200394 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
395 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100396 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200397 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100399 }
400}
401
Harald Weltef26de0b2018-04-04 20:28:05 +0200402private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
403 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100404 timer T := 2.0;
405 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100406 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200407 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100408 return;
409 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200410 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100411
412 T.start;
413 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200414 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100415 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100417 }
418 }
419}
420
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700421private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
422 out integer trxc_conn_id) {
423 var Result res;
424
425 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
426 "", -1, -1, { udp := {} }, {});
427 if (not ispresent(res.connId)) {
428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
429 "Could not connect to the control (TRXC) interface " &
430 "of FakeTRX, check your configuration");
431 }
432 trxc_conn_id := res.connId;
433}
434
Harald Welte70767382018-02-21 12:16:40 +0100435/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700436friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200437 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100438 g_AllChannels := {
439 /* TS 1..4: TCH/F */
440 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
441 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
442 /* TS 5: TCH/H */
443 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
444 /* TS 0: SDCCH/4 */
445 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
446 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
447 /* TS 6: SDCCH/8 */
448 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
449 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
450 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
451 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
452 };
453
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200454 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700455 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200456 g_AllChanTypes := {
457 /* TS 1..4: TCH/F */
458 valueof(ts_RslChanNr_Bm(1)),
459 /* TS 5: TCH/H */
460 valueof(ts_RslChanNr_Lm(5,1)),
461 /* TS 0: SDCCH/4 */
462 valueof(ts_RslChanNr_SDCCH4(0,2)),
463 /* TS 6: SDCCH/8 */
464 valueof(ts_RslChanNr_SDCCH8(6,4))
465 };
466 } else {
467 g_AllChanTypes := {
468 /* TS 1..4: TCH/F */
469 valueof(ts_RslChanNr_Bm(1)),
470 /* TS 0: SDCCH/4 */
471 valueof(ts_RslChanNr_SDCCH4(0,2)),
472 /* TS 6: SDCCH/8 */
473 valueof(ts_RslChanNr_SDCCH8(6,4))
474 };
475 }
Harald Welte70767382018-02-21 12:16:40 +0100476 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100477 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100478 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200479 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100480
481 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100482 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
483 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
484 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
485 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100486
Harald Weltef26de0b2018-04-04 20:28:05 +0200487 map(self:PCU, system:PCU);
488 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100489
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700490 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100491 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700492
493 /* Init TRXC interface to FakeTRX */
494 map(self:BTS_TRXC, system:BTS_TRXC);
495 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
496
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700497 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700498 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 +0700499 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700500 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
501 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100502 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200503
504 /* Wait some extra time to make sure the BTS emits a stable carrier.
505 * (this is only relevant when running the tests with a physical BTS.) */
506 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100507}
508
Harald Welte68e495b2018-02-25 00:05:57 +0100509/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700510friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100511 map(self:L1CTL, system:L1CTL);
512 f_connect_reset(L1CTL);
513}
514
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700515private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100516
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700517private type record length(8) of FreqHopGroups FreqHopConfig;
518
519private type record of FreqHopGroup FreqHopGroups;
520private type record FreqHopGroup {
521 uint6_t hsn,
522 FreqHopGroupItems trx_maio
523};
524
525private type record of FreqHopGroupItem FreqHopGroupItems;
526private type record FreqHopGroupItem {
527 uint8_t trx_nr,
528 uint6_t maio
529};
530
531friend function f_resolve_fh_params(inout ConnHdlrPars pars, uint8_t trx_nr := 0)
532{
533 var FreqHopGroups groups := mp_fh_config[pars.chan_nr.tn];
534 var integer i, j;
535
536 for (i := 0; i < lengthof(groups); i := i + 1) {
537 var FreqHopGroup g := groups[i];
538 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
539 var FreqHopGroupItem gi := g.trx_maio[j];
540 if (gi.trx_nr == trx_nr) {
541 pars.maio_hsn := valueof(ts_HsnMaio(g.hsn, gi.maio));
542 pars.ma := { }; /* to be composed below */
543 break;
544 }
545 }
546
547 if (ispresent(pars.maio_hsn)) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700548 /* Prepare the Mobile Allocation bitmask (length & padding) */
549 pars.ma_map.len := mp_transceiver_num / 8;
550 if (mp_transceiver_num mod 8 > 0)
551 { pars.ma_map.len := pars.ma_map.len + 1; }
552 pars.ma_map.ma := f_pad_bit('0'B, pars.ma_map.len * 8, '0'B);
553
554 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700555 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
556 var FreqHopGroupItem gi := g.trx_maio[j];
557 pars.ma := pars.ma & { l1ctl_ma_def[gi.trx_nr] };
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700558 pars.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700559 }
560
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700561 log("Freq. hopping parameters: maio_hsn := ", pars.maio_hsn,
562 ", ma := ", pars.ma, ", ma_map := ", pars.ma_map);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700563 break; /* We're done */
564 }
565 }
566}
567
Harald Welte70767382018-02-21 12:16:40 +0100568/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700569friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
570 boolean pcu_comp := false,
571 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100572runs on test_CT return ConnHdlr {
573 var charstring id := testcasename();
574 var ConnHdlr vc_conn;
575
576 vc_conn := ConnHdlr.create(id);
577 /* connect to RSL Emulation main component */
578 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
579 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700580
581 /* The ConnHdlr component may want to talk to some ports directly,
582 * so we disconnect it from the test_CT and connect it to the component.
583 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200584 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200585 unmap(self:PCU, system:PCU);
586 map(vc_conn:PCU, system:PCU);
587 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700588 if (trxc_comp) {
589 unmap(self:BTS_TRXC, system:BTS_TRXC);
590 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
591 }
Harald Welte70767382018-02-21 12:16:40 +0100592
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700593 /* Obtain frequency hopping parameters for a given timeslot */
594 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
595 f_resolve_fh_params(pars);
596 }
597
Harald Welte70767382018-02-21 12:16:40 +0100598 vc_conn.start(f_handler_init(fn, id, pars));
599 return vc_conn;
600}
601
Harald Welte70767382018-02-21 12:16:40 +0100602private altstep as_Tguard() runs on ConnHdlr {
603 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100605 }
606}
607
Harald Welte990a3612019-05-27 14:02:13 +0200608friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
609 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100610}
611
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700612private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100613 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700614 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100615}
616
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700617private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100618 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700619 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100620}
621
622/* first function started in ConnHdlr component */
623private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
624runs on ConnHdlr {
625 g_pars := pars;
626 g_chan_nr := pars.chan_nr;
627
628 map(self:L1CTL, system:L1CTL);
629 f_connect_reset(L1CTL);
630
Harald Welted48c0c72019-06-05 10:01:15 +0200631 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700632 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100633 }
Harald Welte70767382018-02-21 12:16:40 +0100634
635 g_Tguard.start(pars.t_guard);
636 activate(as_Tguard());
637
638 f_rslem_register(0, pars.chan_nr);
639
640 /* call the user-supplied test case function */
641 fn.apply(id);
642}
643
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700644private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
645 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200646runs on ConnHdlr return RSL_Message {
647 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100648 timer T := 3.0;
649 RSL.send(tx);
650 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100651 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200652 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100653 T.stop;
654 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100655 }
Harald Welte1eba3742018-02-25 12:48:14 +0100656 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100658 }
Harald Welte21240e62018-03-11 21:43:35 +0100659 [not ignore_other] as_l1_sacch();
660 [not ignore_other] as_meas_res();
661 [not ignore_other] as_l1_dcch();
662 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100664 }
Harald Welte21240e62018-03-11 21:43:35 +0100665 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100666 }
Harald Welteb1726c92018-03-30 11:56:38 +0200667 return rx;
668}
669
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700670friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
671 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200672runs on ConnHdlr {
673 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100674}
675
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700676friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
677 boolean encr_enable := false,
678 RSL_IE_List more_ies := {},
679 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
680runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200681 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200682 if (encr_enable) {
683 /* append encryption related IEs, if requested */
684 var RSL_IE_EncryptionInfo encr_info;
685 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
686 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
687encr_info})) };
688 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200689 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200690 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100691}
692
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700693friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100694 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 +0100695 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100696}
697
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700698/* Default Mobile Allocation to be used for frequency hopping */
699private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
700 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
701
Harald Welte2f2b2b72019-05-31 22:24:57 +0200702friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100703 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700704 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100705 float t_guard := 20.0) := {
706 chan_nr := valueof(chan_nr),
707 chan_mode := valueof(chan_mode),
708 t_guard := t_guard,
709 l1_pars := {
710 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100711 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100712 meas_ul := {
713 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200714 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100715 rxqual := 0
716 },
717 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200718 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100719 rxqual := 0
720 }
721 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200722 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100723 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200724 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200725 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100726 },
Harald Weltee613f962018-04-18 22:38:16 +0200727 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200728 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700729 bts0_band := omit,
730 maio_hsn := maio_hsn,
731 ma_map := c_MA_null,
732 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100733}
734
Harald Welte93640c62018-02-25 16:59:33 +0100735/***********************************************************************
736 * Channel Activation / Deactivation
737 ***********************************************************************/
738
Harald Welte70767382018-02-21 12:16:40 +0100739/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700740private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100741 for (var integer i := 0; i < 500; i := i+1) {
742 f_rsl_chan_act(g_pars.chan_mode);
743 f_rsl_chan_deact();
744 }
745 setverdict(pass);
746}
747testcase TC_chan_act_stress() runs on test_CT {
748 var ConnHdlr vc_conn;
749 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200750 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100751 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
752 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100754}
755
756/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700757private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100758 f_rsl_chan_act(g_pars.chan_mode);
759 /* attempt to activate the same lchan again -> expect reject */
760 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
761 alt {
762 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100764 }
765 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
766 setverdict(pass);
767 }
768 }
769 f_rsl_chan_deact();
770}
771testcase TC_chan_act_react() runs on test_CT {
772 var ConnHdlr vc_conn;
773 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100774 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100775 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
776 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100778}
779
780/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700781private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100782 timer T := 3.0;
783 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
784 T.start;
785 alt {
786 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
787 setverdict(pass);
788 }
789 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100791 }
792 }
793}
794testcase TC_chan_deact_not_active() runs on test_CT {
795 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100796 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100797 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
798 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100800}
801
802/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700803private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100804 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
805 alt {
806 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100808 }
809 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
810 setverdict(pass);
811 }
812 }
813}
814private type record WrongChanNrCase {
815 RslChannelNr chan_nr,
816 charstring description
817}
818private type record of WrongChanNrCase WrongChanNrCases;
819private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
820 chan_nr := chan_nr,
821 description := desc
822}
823
824testcase TC_chan_act_wrong_nr() runs on test_CT {
825 var ConnHdlr vc_conn;
826 var ConnHdlrPars pars;
827
Harald Welte294b0a22018-03-10 23:26:48 +0100828 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100829
830 var WrongChanNrCases wrong := {
831 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
832 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
833 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
834 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
835 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
836 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
837 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
838 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
839 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
840 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
841 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
842 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
843 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
844 };
845
846 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
847 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
848 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
849 vc_conn.done;
850 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100852}
853
Harald Weltee613f962018-04-18 22:38:16 +0200854/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200855friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200856 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200857 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200858
859 /* test on each of the channels we have */
860 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
861 pars.chan_nr := valueof(g_AllChanTypes[i]);
862
863 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
864 vc_conn := f_start_handler(fn, pars);
865 vc_conn.done;
866 }
867
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200869}
870
Harald Welte93640c62018-02-25 16:59:33 +0100871/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100872 * SACCH handling
873 ***********************************************************************/
874
875private function f_exp_sacch(boolean exp) runs on ConnHdlr {
876 timer T_sacch := 3.0;
877 T_sacch.start;
878 alt {
879 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100881 }
882 [not exp] T_sacch.timeout {
883 setverdict(pass);
884 }
885 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
886 setverdict(pass);
887 }
888 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100890 }
891 [] L1CTL.receive { repeat; }
892 [] RSL.receive { repeat; }
893 }
894}
895
896/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
897private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
898 f_l1_tune(L1CTL);
899 RSL.clear;
900
901 /* activate the logical channel */
902 f_est_dchan();
903 L1CTL.clear;
904
905 /* check that SACCH actually are received as expected */
906 f_exp_sacch(true);
907
908 /* deactivate SACCH on the logical channel */
909 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
910 f_sleep(1.0);
911 L1CTL.clear;
912
913 /* check that no SACCH are received anymore */
914 f_exp_sacch(false);
915
916 /* release the channel */
917 f_rsl_chan_deact();
918 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
919}
920testcase TC_deact_sacch() runs on test_CT {
921 var ConnHdlr vc_conn;
922 var ConnHdlrPars pars;
923 f_init();
924 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
925 //for (var integer i := 0; i < 1; i := i+1) {
926 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
927 log(testcasename(), ": Starting for ", g_AllChannels[i]);
928 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
929 vc_conn.done;
930 }
931 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100933}
934
Harald Welte55700662018-03-12 13:15:43 +0100935/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100936private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
937 var L1ctlDlMessage dl;
938 /* check that the specified SI5 value is actually sent */
939 timer T_sacch := 3.0;
940 L1CTL.clear;
941 T_sacch.start;
942 alt {
943 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
944 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
945 if (match(l3, l3_exp)) {
946 setverdict(pass);
947 } else {
948 repeat;
949 }
950 }
951 [] L1CTL.receive { repeat; }
952 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100954 }
955 }
956}
957
Harald Welte55700662018-03-12 13:15:43 +0100958/* verify that given SACCH payload is not present */
959private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
960 var L1ctlDlMessage dl;
961 /* check that the specified SI5 value is actually sent */
962 timer T_sacch := 3.0;
963 L1CTL.clear;
964 T_sacch.start;
965 alt {
966 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
967 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
968 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100970 } else {
971 repeat;
972 }
973 }
974 [] L1CTL.receive { repeat; }
975 [] T_sacch.timeout {
976 setverdict(pass);
977 }
978 }
979}
980
Harald Welte629cc6b2018-03-11 17:19:05 +0100981/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100982private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
983 /* Set a known default SACCH filling for SI5 */
984 var octetstring si5 := f_rnd_octstring(19);
985 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
986
987 f_l1_tune(L1CTL);
988 RSL.clear;
989
990 /* activate the logical channel */
991 f_est_dchan();
992
993 /* check that the specified SI5 value is actually sent */
994 f_sacch_present(si5);
995
996 /* release the channel */
997 RSL.clear;
998 f_rsl_chan_deact();
999 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1000}
1001testcase TC_sacch_filling() runs on test_CT {
1002 var ConnHdlr vc_conn;
1003 var ConnHdlrPars pars;
1004 f_init();
1005 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1006 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1007 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1008 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1009 vc_conn.done;
1010 }
1011 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001013}
1014
Harald Welte629cc6b2018-03-11 17:19:05 +01001015/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001016private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1017 /* Set a known default SACCH filling for SI5 */
1018 var octetstring si5 := f_rnd_octstring(19);
1019 var octetstring si5_diff := f_rnd_octstring(19);
1020 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1021
1022 f_l1_tune(L1CTL);
1023 RSL.clear;
1024
1025 log("Activating channel, expecting standard SI5");
1026 /* activate the logical channel */
1027 f_est_dchan();
1028 /* check that the specified SI5 value is actually sent */
1029 f_sacch_present(si5);
1030
1031 /* set channel-specific different SI5 */
1032 log("Setting channel specific SACCH INFO, expecting it");
1033 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1034 /* check that the specified lchan-specific value is now used */
1035 f_sacch_present(si5_diff);
1036
1037 /* deactivate the channel and re-activate it, this should result in default SI5 */
1038 log("De-activating and re-activating channel, expecting standard SI5");
1039 f_rsl_chan_deact();
1040 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1041 /* Verify that the TRX-wide default SACCH filling is present again */
1042 f_sacch_present(si5);
1043
1044 /* release the channel */
1045 RSL.clear;
1046 f_rsl_chan_deact();
1047 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1048}
1049testcase TC_sacch_info_mod() runs on test_CT {
1050 var ConnHdlr vc_conn;
1051 var ConnHdlrPars pars;
1052 f_init();
1053 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1054 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1055 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1056 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1057 vc_conn.done;
1058 }
1059 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001061}
1062
Harald Welte075d84c2018-03-12 13:07:24 +01001063/* Test SACCH scheduling of multiple different SI message types */
1064private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1065 var octetstring si5 := f_rnd_octstring(19);
1066 var octetstring si5bis := f_rnd_octstring(19);
1067 var octetstring si5ter := f_rnd_octstring(19);
1068 var octetstring si6 := f_rnd_octstring(19);
1069
1070 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1071 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1072 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1073 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1074
1075 f_l1_tune(L1CTL);
1076 RSL.clear;
1077
1078 /* activate the logical channel */
1079 f_est_dchan();
1080 L1CTL.clear;
1081
1082 /* check that SACCH actually are received as expected */
1083 f_sacch_present(si5);
1084 f_sacch_present(si5bis);
1085 f_sacch_present(si5ter);
1086 f_sacch_present(si6);
1087
1088 /* release the channel */
1089 f_rsl_chan_deact();
1090 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1091}
1092testcase TC_sacch_multi() runs on test_CT {
1093 var ConnHdlr vc_conn;
1094 var ConnHdlrPars pars;
1095 f_init();
1096 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1097 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1098 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1099 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1100 vc_conn.done;
1101 }
1102 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001104}
1105
Harald Welte55700662018-03-12 13:15:43 +01001106/* Test if SACH information is modified as expected */
1107private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1108 var octetstring si5 := f_rnd_octstring(19);
1109 var octetstring si6 := f_rnd_octstring(19);
1110
1111 /* First, configure both SI5 and SI6 to be transmitted */
1112 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1113 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1114
1115 f_l1_tune(L1CTL);
1116 RSL.clear;
1117
1118 /* activate the logical channel */
1119 f_est_dchan();
1120 L1CTL.clear;
1121
1122 /* check that SACCH actually are received as expected */
1123 f_sacch_present(si5);
1124 f_sacch_present(si6);
1125
1126 /* disable SI6 */
1127 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1128
1129 /* check that SI5 is still transmitted */
1130 f_sacch_present(si5);
1131 /* check if SI6 is now gone */
1132 f_sacch_missing(si6);
1133
1134 /* release the channel */
1135 f_rsl_chan_deact();
1136 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1137}
1138testcase TC_sacch_multi_chg() runs on test_CT {
1139 var ConnHdlr vc_conn;
1140 var ConnHdlrPars pars;
1141 f_init();
1142 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1143 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1144 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1145 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1146 vc_conn.done;
1147 }
1148 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001150}
1151
Harald Weltec8d363c2019-05-19 20:36:48 +02001152/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1153private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1154 var octetstring si5 := f_rnd_octstring(19);
1155 var octetstring si6 := f_rnd_octstring(19);
1156 var octetstring si5_specific := f_rnd_octstring(19);
1157 var octetstring si6_specific := f_rnd_octstring(19);
1158
1159 /* First, configure both SI5 and SI6 to be transmitted */
1160 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1161 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1162
1163 f_l1_tune(L1CTL);
1164 RSL.clear;
1165
1166 /* activate channel with different SACCH filling */
1167 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1168 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1169 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1170 }));
1171 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1172 RSL_IE_Body:{sacch_info := sacch_info})) };
1173 f_est_dchan(more_ies := addl_ies);
1174
1175 /* check that SACCH actually are received as expected */
1176 f_sacch_present(si5_specific);
1177 f_sacch_present(si6_specific);
1178
1179 /* release the channel */
1180 f_rsl_chan_deact();
1181 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1182}
1183testcase TC_sacch_chan_act() runs on test_CT {
1184 var ConnHdlr vc_conn;
1185 var ConnHdlrPars pars;
1186 f_init();
1187
1188 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1189 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1190 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1191 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1192 vc_conn.done;
1193 }
1194 /* TODO: do the above in parallel, rather than sequentially? */
1195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1196}
1197
Harald Welte8b01c792019-05-19 22:51:25 +02001198/* verify that SACCH DL transmission is started only if MS power IE present
1199 * see section 4.1.3 of 3GPP TS 48.058 */
1200private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1201 var octetstring si5 := f_rnd_octstring(19);
1202
1203 f_l1_tune(L1CTL);
1204 RSL.clear;
1205
1206 /* Step 1: Activate ASYNC HO channel without MS power IE */
1207
1208 /* Activate channel on BTS side */
1209 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1210 /* don't perform immediate assignment here, as we're testing non-IA case */
1211 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001212 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001213
1214 /* Verify that no DL SACCH is being received */
1215 f_sacch_missing(?);
1216
1217 f_rsl_chan_deact();
1218 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1219
1220
1221 /* Step 2: Activate ASYNC HO channel with MS power IE */
1222
1223 /* Activate channel on BTS side */
1224 var RSL_IE_List addl_ies := {
1225 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1226 };
1227 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1228 /* don't perform immediate assignment here, as we're testing non-IA case */
1229 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001230 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001231
1232 /* Verify that DL SACCH is being received */
1233 f_sacch_present(si5);
1234
1235 f_rsl_chan_deact();
1236 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1237}
1238testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1239 var ConnHdlr vc_conn;
1240 var ConnHdlrPars pars;
1241 f_init();
1242
1243 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1244 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1245 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1246 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1247 vc_conn.done;
1248 }
1249 /* TODO: do the above in parallel, rather than sequentially? */
1250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1251}
1252
1253/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1254 * see section 4.1.4 of 3GPP TS 48.058 */
1255private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1256 var octetstring si5 := f_rnd_octstring(19);
1257 var RSL_IE_List addl_ies;
1258
1259 f_l1_tune(L1CTL);
1260 RSL.clear;
1261
1262 /* Step 1: Activate SYNC HO channel without MS power IE */
1263
1264 /* Activate channel on BTS side */
1265 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1266 /* don't perform immediate assignment here, as we're testing non-IA case */
1267 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001268 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001269
1270 /* Verify that no DL SACCH is being received */
1271 f_sacch_missing(?);
1272
1273 f_rsl_chan_deact();
1274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1275
1276
1277 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1278
1279 /* Activate channel on BTS side */
1280 addl_ies := {
1281 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1282 };
1283 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1284 /* don't perform immediate assignment here, as we're testing non-IA case */
1285 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001286 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001287
1288 /* Verify that no DL SACCH is being received */
1289 f_sacch_missing(?);
1290
1291 f_rsl_chan_deact();
1292 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1293
1294
1295 /* Step 2b: Activate SYNC HO channel with TA IE */
1296
1297 /* Activate channel on BTS side */
1298 addl_ies := {
1299 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1300 };
1301 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1302 /* don't perform immediate assignment here, as we're testing non-IA case */
1303 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001304 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001305
1306 /* Verify that no DL SACCH is being received */
1307 f_sacch_missing(?);
1308
1309 f_rsl_chan_deact();
1310 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1311
1312
1313 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1314
1315 /* Activate channel on BTS side */
1316 addl_ies := {
1317 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1318 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1319 };
1320 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1321 /* don't perform immediate assignment here, as we're testing non-IA case */
1322 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001323 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001324
1325 /* Verify that DL SACCH is being received */
1326 f_sacch_present(si5);
1327
1328 f_rsl_chan_deact();
1329 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1330}
1331testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1332 var ConnHdlr vc_conn;
1333 var ConnHdlrPars pars;
1334 f_init();
1335
1336 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1337 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1338 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1339 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1340 vc_conn.done;
1341 }
1342 /* TODO: do the above in parallel, rather than sequentially? */
1343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1344}
Harald Welte629cc6b2018-03-11 17:19:05 +01001345
1346
1347/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001348 * RACH Handling
1349 ***********************************************************************/
1350
Harald Welte8c24c2b2018-02-26 08:31:31 +01001351/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001352private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001353 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001354 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001355 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001356
Harald Welte8c24c2b2018-02-26 08:31:31 +01001357 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001358 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001359 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001360 var OCT1 ra := f_rnd_ra_emerg();
1361 if (emerg == true) {
1362 ra := f_rnd_ra_emerg();
1363 } else {
1364 ra := f_rnd_ra_cs();
1365 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001366 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1367 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001369 }
1370 fn_last := fn;
1371
1372 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001373 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001374 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001375 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001376 T.stop;
1377 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001378 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001380 }
1381 [] RSL_CCHAN.receive { repeat; }
1382 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001383 test_failed := true;
1384 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001385 }
1386 }
1387 }
Maxba06feb2019-03-05 10:52:46 +01001388 if (test_failed) {
1389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001390 }
Maxba06feb2019-03-05 10:52:46 +01001391 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001393}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001394
Philipp Maier16ade782020-07-08 21:36:00 +02001395/* Normal variant */
1396testcase TC_rach_content() runs on test_CT {
1397 f_TC_rach_content(emerg := false);
1398}
1399
1400/* Emergency call variant */
1401testcase TC_rach_content_emerg() runs on test_CT {
1402 f_TC_rach_content(emerg := true);
1403}
1404
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1406testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001407 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001409 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001410 f_l1_tune(L1CTL);
1411
1412 var GsmFrameNumber fn_last := 0;
1413 for (var integer i := 0; i < 1000; i := i+1) {
1414 var OCT1 ra := f_rnd_ra_cs();
1415 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1416 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001418 }
1419 fn_last := fn;
1420 }
1421 var integer rsl_chrqd := 0;
1422 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001423 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001424 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001425 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001426 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001427 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001428 repeat;
1429 }
1430 [] RSL_CCHAN.receive { repeat; }
1431 [] T.timeout { }
1432 }
1433 if (rsl_chrqd == 1000) {
1434 setverdict(pass);
1435 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001437 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001439}
1440
Harald Welte3453ab42019-05-24 21:19:58 +02001441private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1442 var charstring bts_str := "bts " & int2str(bts_nr);
1443 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1444}
1445
1446/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1447private template integer tr_rach_slots_per_interval := (90 .. 130);
1448
1449/* Expect 0 RACH load on an idle BTS that has just started up */
1450testcase TC_rach_load_idle_thresh0() runs on test_CT {
1451 var ASP_RSL_Unitdata rx_ud;
1452
1453 f_init_vty_bsc();
1454 /* send load indications even at 0% load */
1455 f_vty_load_ind_thresh(0);
1456 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1457 f_sleep(2.0);
1458
1459 f_init();
1460
1461 timer T := 5.0;
1462 T.start;
1463 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001464 [] 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 +02001465 setverdict(pass);
1466 repeat;
1467 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001468 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001469 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1470 repeat;
1471 }
1472 [] RSL_CCHAN.receive {
1473 repeat;
1474 }
1475 [] T.timeout { }
1476 }
1477
1478 f_vty_load_ind_thresh(10);
1479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1480}
1481
1482/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1483testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1484 var ASP_RSL_Unitdata rx_ud;
1485
1486 f_init_vty_bsc();
1487 f_init();
1488
1489 timer T := 5.0;
1490 T.start;
1491 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001492 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001493 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1494 repeat;
1495 }
1496 [] RSL_CCHAN.receive {
1497 repeat;
1498 }
1499 [] T.timeout {
1500 setverdict(pass);
1501 }
1502 }
1503
1504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1505}
1506
1507/* Expect 0 RACH load on an idle BTS that has just started up */
1508testcase TC_rach_load_count() runs on test_CT {
1509 var ASP_RSL_Unitdata rx_ud;
1510 var integer load_access_count := 0;
1511
1512 f_init_vty_bsc();
1513 /* send load indications even at 0% load */
1514 f_vty_load_ind_thresh(0);
1515 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1516 f_sleep(2.0);
1517 f_init();
1518
1519 f_init_l1ctl();
1520 f_sleep(1.0);
1521 f_l1_tune(L1CTL);
1522
1523 var GsmFrameNumber fn_last := 0;
1524 for (var integer i := 0; i < 1000; i := i+1) {
1525 var OCT1 ra := f_rnd_ra_cs();
1526 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1527 if (fn == fn_last) {
1528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1529 }
1530 fn_last := fn;
1531 }
1532
1533 timer T := 5.0;
1534 T.start;
1535 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001536 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001537 -> value rx_ud {
1538 var RSL_IE_Body ie;
1539 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1540 load_access_count := load_access_count + ie.rach_load.access_count;
1541 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1542 setverdict(fail, "Access count cannot be < Busy count");
1543 }
1544 repeat;
1545 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001546 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001547 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1548 repeat;
1549 }
1550 [] RSL_CCHAN.receive {
1551 repeat;
1552 }
1553 [] T.timeout { }
1554 }
1555 if (load_access_count == 1000) {
1556 setverdict(pass);
1557 } else {
1558 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1559 }
1560
1561 f_vty_load_ind_thresh(10);
1562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1563}
1564
Harald Welte54a2a2d2018-02-26 09:14:05 +01001565private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001566 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001567 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001568 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001569 f_sleep(0.5);
1570
1571 /* Transmit RACH request + wait for confirmation */
1572 var OCT1 ra := f_rnd_ra_cs();
1573 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1574
1575 /* Check for expected result */
1576 timer T := 1.5;
1577 T.start;
1578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001579 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001580 setverdict(pass);
1581 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001582 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001584 }
1585 [] RSL_CCHAN.receive { repeat; }
1586 [not expect_pass] T.timeout {
1587 setverdict(pass);
1588 }
1589 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001591 }
1592 }
1593}
1594
1595/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1596testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001597 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001598 f_init_l1ctl();
1599 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001600 f_sleep(1.0);
1601
1602 /* default max-ta is 63 (full range of GSM timing advance */
1603
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001604 /* We allow early arrival up to 2 symbols */
1605 f_rach_toffs(-1*256, true);
1606 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001607 f_rach_toffs(-10*256, false);
1608
1609 /* 0 / 32 / 63 bits is legal / permitted */
1610 f_rach_toffs(0, true);
1611 f_rach_toffs(32*256, true);
1612 f_rach_toffs(63*256, true);
1613
1614 /* more than 63 bits is not legal / permitted */
1615 f_rach_toffs(64*256, false);
1616 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001618}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001619
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001620private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001621 var GsmFrameNumber fn;
1622 var RSL_Message rm;
1623
1624 f_l1_tune(L1CTL);
1625 RSL.clear;
1626
1627 /* Generate a random Handover Reference */
1628 var integer ho_ref := oct2int(f_rnd_octstring(1));
1629
1630 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1631 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1632 RSL_IE_Body:{ handover_ref := ho_ref }));
1633
1634 /* Activate a channel on the BTS side (no encryption) */
1635 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1636 act_type := t_RSL_IE_ActType_HO_SYNC);
1637
1638 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1639 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001640 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001641
1642 /* Send handover Access Burst */
1643 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1644
1645 /* TODO: test mismatching Handover Reference, and missing IE */
1646
1647 /* Wait for handover detection */
1648 timer T := 3.0;
1649 T.start;
1650 alt {
1651 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1652 log("Handover RACH has been detected: ", rm);
1653 setverdict(pass);
1654 }
1655 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1657 log2str("RSL_CHAN_RQD was not expected: ", rm));
1658 }
1659 [] RSL.receive { repeat; }
1660 [] T.timeout {
1661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1662 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1663 }
1664 }
1665
1666 /* Release the channel */
1667 f_rsl_chan_deact();
1668 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1669}
1670
1671/* Test handover RACH detection */
1672testcase TC_ho_rach() runs on test_CT {
1673 var ConnHdlrPars pars;
1674 var ConnHdlr vc_conn;
1675
1676 f_init();
1677
1678 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1679 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1680 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1681 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1682 vc_conn.done;
1683 }
1684
1685 /* TODO: do the above in parallel, rather than sequentially? */
1686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1687}
1688
Harald Welte93640c62018-02-25 16:59:33 +01001689/***********************************************************************
1690 * Measurement Processing / Reporting
1691 ***********************************************************************/
1692
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001693private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001694 spare := '0'B,
1695 lpd := 0,
1696 sapi := sapi,
1697 c_r := c_r,
1698 ea := true
1699}
1700
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001701private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001702 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001703 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001704 len := 0, /* overwritten */
1705 m := false,
1706 el := 1,
1707 payload := pl
1708}
1709
1710/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001711private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001712 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001713 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001714 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001715 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 +01001716 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001717 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001718
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001719 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1720 g_pars.l1_pars.ms_power_level, false,
1721 g_pars.l1_pars.ms_actual_ta);
1722
1723 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1724 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1725
1726 log("Sending Measurement Report: ", l1h, l2);
1727 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001728 repeat;
1729 }
1730}
1731
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001732private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001733 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001734 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001735 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1736 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001737 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1738 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001739 repeat;
1740 }
1741}
1742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001743private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001744 uint6_t rxlev,
1745 uint3_t rxqual
1746}
1747
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001748private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001749 MeasElem full,
1750 MeasElem sub
1751}
1752
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001753private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001754 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001755 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001756 MeasElemFS meas_ul,
1757 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001758 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001759 uint5_t ms_power_level,
1760 uint8_t ms_actual_ta
1761}
1762
1763/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1764private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1765 return 63 + (toffs256s/256);
1766}
1767
Harald Welted5684392018-03-10 18:22:04 +01001768private function f_max(integer a, integer b) return integer {
1769 if (a > b) {
1770 return a;
1771 } else {
1772 return b;
1773 }
1774}
1775
1776private function f_min(integer a, integer b) return integer {
1777 if (a < b) {
1778 return a;
1779 } else {
1780 return b;
1781 }
1782}
1783
1784/* compute negative tolerance val-tolerance, ensure >= min */
1785private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1786 val := val - tolerance;
1787 return f_max(val, min);
1788}
1789
1790/* compute positive tolerance val+tolerance, ensure <= max */
1791private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1792 val := val + tolerance;
1793 return f_min(val, max);
1794}
1795
1796/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1797private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1798return template integer {
1799 var template integer ret;
1800 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1801 return ret;
1802}
1803
1804
Harald Welte70767382018-02-21 12:16:40 +01001805/* build a template for matching measurement results against */
1806private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1807 var ConnL1Pars l1p := g_pars.l1_pars;
1808 var template RSL_IE_UplinkMeas ul_meas := {
1809 len := 3,
1810 rfu := '0'B,
1811 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001812 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001813 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001814 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001815 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001816 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1817 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001818 supp_meas_info := omit
1819 };
Harald Welte685d5982018-02-27 20:42:05 +01001820 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001821 ul_meas.len := (3+8);
1822 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001823 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001824 toa256_min := ?,
1825 toa256_max := ?,
1826 toa256_std_dev := ?
1827 }
Harald Welte685d5982018-02-27 20:42:05 +01001828 }
Harald Welte70767382018-02-21 12:16:40 +01001829 var template RSL_IE_BS_Power bs_power := {
1830 reserved := 0,
1831 epc := false,
1832 fpc := false,
1833 power_level := l1p.bs_power_level
1834 };
1835 var template RSL_IE_L1Info l1_info := {
1836 ms_power_lvl := l1p.ms_power_level,
1837 fpc := false,
1838 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001839 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001840 };
1841 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001842 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001843 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1844 ?, t_toffs);
1845}
1846
Philipp Maierdd841d32019-12-17 14:44:54 +01001847/* build a template for matching measurement results that do not contain any
1848 * MS related measurement (l1_info, l3_info and ms timing offset). */
1849private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1850 var ConnL1Pars l1p := g_pars.l1_pars;
1851 var template RSL_IE_UplinkMeas ul_meas := {
1852 len := 3,
1853 rfu := '0'B,
1854 dtx_d := l1p.dtx_enabled,
1855 rxlev_f_u := ?,
1856 reserved1 := '00'B,
1857 rxlev_s_u := ?,
1858 reserved2 := '00'B,
1859 rxq_f_u := ?,
1860 rxq_s_u := ?,
1861 supp_meas_info := omit
1862 };
1863 if (l1p.toa256_enabled) {
1864 ul_meas.len := (3+8);
1865 ul_meas.supp_meas_info := {
1866 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1867 toa256_min := ?,
1868 toa256_max := ?,
1869 toa256_std_dev := ?
1870 }
1871 }
1872 var template RSL_IE_BS_Power bs_power := {
1873 reserved := 0,
1874 epc := false,
1875 fpc := false,
1876 power_level := l1p.bs_power_level
1877 };
1878
1879 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1880}
1881
Harald Welte70767382018-02-21 12:16:40 +01001882/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001883private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001884 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001885 var boolean chan_est := false;
1886
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001887 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001888
1889 /* Receive osmocom specific measurement reports. This is the normal
1890 * case. Here we verify that the measurement reports we sent are
1891 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001892 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1893 /* increment counter of next to-be-expected meas rep */
1894 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1895 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001896 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001897
1898 /* The following two cases may only happen in the beginning
1899 * of the channel establishment phase. Once we have received
1900 * the "our" measurement report the first time, the channel
1901 * is established and empty or hardcoded TRXCON reports must
1902 * not occur anymore. */
1903 chan_est := true;
1904
1905 repeat;
1906 }
1907
1908 /* When the BTS has established the channel, the MS might need slightly
1909 * more time to establish the channel and actually start sending. The
1910 * result is then a measurement report that just lacks the measurement
1911 * information of the MS. This is normal and we tolerate this behavior. */
1912 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1913 /* increment counter of next to-be-expected meas rep */
1914 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1915 /* Re-start the timer expecting the next MEAS RES */
1916 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001917 repeat;
1918 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001919
1920 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1921 * measurements if the TTCN3 side does not supply measurement input in
1922 * time. In those cases TRXCON will either use a cached measurement
1923 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1924 * report the templates above will not match. We tolerate this
1925 * behavior, but only once. */
1926 [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 +01001927 /* increment counter of next to-be-expected meas rep */
1928 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1929 if (g_first_meas_res) {
1930 g_first_meas_res := false;
1931 repeat;
1932 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001934 }
Harald Welte70767382018-02-21 12:16:40 +01001935 }
1936 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001938 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001939 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001941 }
1942}
1943
Harald Weltee613f962018-04-18 22:38:16 +02001944private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1945 select (rsl_alg_id) {
1946 case (RSL_ALG_ID_A5_0) { return 0; }
1947 case (RSL_ALG_ID_A5_1) { return 1; }
1948 case (RSL_ALG_ID_A5_2) { return 2; }
1949 case (RSL_ALG_ID_A5_3) { return 3; }
1950 case (RSL_ALG_ID_A5_4) { return 4; }
1951 case (RSL_ALG_ID_A5_5) { return 5; }
1952 case (RSL_ALG_ID_A5_6) { return 6; }
1953 case (RSL_ALG_ID_A5_7) { return 7; }
1954 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1956 /* Make compiler happy by calling mtc.stop here. It is already
1957 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001958 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001959 }
1960 }
1961}
1962
1963private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1964 select (rsl_alg_id) {
1965 case (RSL_ALG_ID_A5_1) { return '000'B; }
1966 case (RSL_ALG_ID_A5_2) { return '001'B; }
1967 case (RSL_ALG_ID_A5_3) { return '010'B; }
1968 case (RSL_ALG_ID_A5_4) { return '011'B; }
1969 case (RSL_ALG_ID_A5_5) { return '100'B; }
1970 case (RSL_ALG_ID_A5_6) { return '101'B; }
1971 case (RSL_ALG_ID_A5_7) { return '110'B; }
1972 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1974 /* Make compiler happy by calling mtc.stop here. It is already
1975 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001976 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001977 }
1978 }
1979}
1980
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001981/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1982private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1983 var GsmFrameNumber fn;
1984 timer T := 8.0;
1985
1986 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1987 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1988
1989 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1990 /* Send the actual RACH */
1991 fn := f_L1CTL_RACH(L1CTL, ra);
1992
1993 T.start;
1994 alt {
1995 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1996 [] T.timeout {
1997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1998 }
1999 }
2000 T.stop
2001 return fn;
2002}
Harald Weltee613f962018-04-18 22:38:16 +02002003
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002004/* Tune to a dedicated channel: L1CTL only */
2005private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
2006 if (not ispresent(pars.maio_hsn)) {
2007 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2008 7 /* TODO: mp_tsc */,
2009 mp_trx0_arfcn));
2010 } else {
2011 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2012 7 /* TODO: mp_tsc */,
2013 pars.maio_hsn.hsn,
2014 pars.maio_hsn.maio,
2015 pars.ma));
2016 }
2017}
2018
Harald Welte70767382018-02-21 12:16:40 +01002019/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002020private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002021 var GsmFrameNumber fn;
2022 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002023 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002024 var integer ra := 23;
2025
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002026 /* Send RACH request and wait for ChanReq */
2027 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002028
2029 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002030 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002031
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002032 /* Craft channel description (with or without frequency hopping parameters) */
2033 if (ispresent(g_pars.maio_hsn)) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002034 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002035 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002036 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002037 }
2038
Harald Welte70767382018-02-21 12:16:40 +01002039 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002040 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002041 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2042
2043 /* receive IMM.ASS on MS side */
2044 var ImmediateAssignment ia_um;
2045 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002046
2047 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2048 if (ch_desc.h != ia_um.chan_desc.h) {
2049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2050 }
2051
Harald Welte70767382018-02-21 12:16:40 +01002052 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002053 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002054 /* enable encryption, if requested */
2055 if (encr_enable) {
2056 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2057 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2058 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002059
2060 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002061}
2062
2063/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002064private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002065 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002066 RSL.clear;
2067
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002068 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002069 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002070 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002071 }
Harald Welte70767382018-02-21 12:16:40 +01002072
2073 f_est_dchan();
2074
2075 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2076 * RSL measurement reports on Abis side */
2077 timer T := 8.0;
2078 T.start;
2079 alt {
2080 [] as_l1_sacch();
2081 [] as_meas_res();
2082 [] as_l1_dcch();
2083 [] L1CTL.receive { repeat; }
2084 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002085 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002086 * of any earlier errors, so if we reach this timeout, we're good */
2087 setverdict(pass);
2088 }
2089 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002091 }
2092 }
2093 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002094 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002095}
Harald Welte0472ab42018-03-12 15:02:26 +01002096
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002097/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2098private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002099 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002100 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2101 timer Tup := 10.0;
2102 Tup.start;
2103 alt {
2104 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2105 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2106 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002107
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002108 if (rx_lvl != max_rx_lvl) {
2109 repeat;
2110 }
2111 Tup.stop;
2112 }
2113 [] L1CTL.receive { repeat; }
2114 [] Tup.timeout {
2115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2116 log2str("Didn't reach full power ", max_rx_lvl));
2117 }
2118 }
2119 return max_rx_lvl;
2120}
2121
2122/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2123private function f_verify_ramp_up() runs on ConnHdlr {
2124 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002125 var integer initial_rx_lvl := -1;
2126 var integer last_rx_lvl := -1;
2127 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2128
2129 timer T := 2.0;
2130 alt {
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2132 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2133 log("Received rx_level=", rx_lvl);
2134 if (initial_rx_lvl == -1) {
2135 initial_rx_lvl := rx_lvl;
2136 last_rx_lvl := rx_lvl;
2137
2138 /* Expect a somehow low value during first received messages */
2139 if (initial_rx_lvl >= max_rx_lvl / 2) {
2140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2141 log2str("Detected high initial tx power during ramp up: ",
2142 initial_rx_lvl , ", full power is", max_rx_lvl));
2143 }
2144 }
2145
2146 /* received Rx level bigger than maximum allowed power by CN */
2147 if (rx_lvl > max_rx_lvl) {
2148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2149 log2str("Detected Tx power higher than full power: ",
2150 rx_lvl , " > ", max_rx_lvl));
2151 }
2152
2153 /* Make sure it never decreases, since we are rumping up */
2154 if (last_rx_lvl > rx_lvl) {
2155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2156 log2str("Detected Tx power decrease during ramp up: ",
2157 last_rx_lvl , " -> ", rx_lvl));
2158 }
2159
2160 if (rx_lvl == max_rx_lvl and not T.running) {
2161 /* We reached the maximum power, start timer and receive
2162 /* a few more to make sure we don't surpass it */
2163 log("Reached full power, wating a bit more until success");
2164 T.start;
2165 }
2166
2167 last_rx_lvl := rx_lvl;
2168 repeat;
2169 }
2170 [] L1CTL.receive { repeat; }
2171 [] T.timeout { }
2172 }
2173
2174 /* We didn't increase tx power during ramp up */
2175 if (initial_rx_lvl < last_rx_lvl) {
2176 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2177 } else {
2178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2179 log2str("No Tx power increase during whole ramp up: ",
2180 initial_rx_lvl , " -> ", last_rx_lvl));
2181 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002182}
2183
2184/* verify BTS ramps power down to rx_level 0 */
2185private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2186 var L1ctlDlMessage l1_dl;
2187 var integer last_rx_lvl := max_rx_lvl;
2188
2189 timer Tdown := 5.0;
2190 Tdown.start;
2191 alt {
2192 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2193 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2194 log("Received rx_level=", rx_lvl);
2195
2196 /* received Rx level bigger than maximum allowed power by CN */
2197 if (rx_lvl > max_rx_lvl) {
2198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2199 log2str("Detected Tx power higher than full power: ",
2200 rx_lvl , " > ", max_rx_lvl));
2201 }
2202
2203 /* Make sure it never increases, since we are rumping down */
2204 if (last_rx_lvl < rx_lvl) {
2205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2206 log2str("Detected Tx power increase during ramp up: ",
2207 last_rx_lvl , " -> ", rx_lvl));
2208 }
2209
2210 last_rx_lvl := rx_lvl;
2211 if (last_rx_lvl != 0) {
2212 repeat;
2213 }
2214 /* we reached power level 0, we are done */
2215 Tdown.stop;
2216 }
2217 [] L1CTL.receive { repeat; }
2218 [] Tdown.timeout { }
2219 }
2220
2221 /* We didn't increase tx power during ramp down */
2222 if (max_rx_lvl > last_rx_lvl) {
2223 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2224 } else {
2225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2226 log2str("No Tx power decrease during whole ramp down: ",
2227 max_rx_lvl , " -> ", last_rx_lvl));
2228 }
2229}
2230
2231/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002232private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002233 f_l1_tune(L1CTL);
2234 RSL.clear;
2235
2236 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002237
2238 setverdict(pass);
2239}
2240testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2241 var ConnHdlr vc_conn;
2242 var ConnHdlrPars pars;
2243 f_init();
2244 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2245 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2246 pcu_comp := false, trxc_comp := true);
2247 vc_conn.done;
2248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2249}
2250
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002251/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002252private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002253 f_connhdlr_init_vty_bsc();
2254
2255 f_l1_tune(L1CTL);
2256 RSL.clear;
2257
2258 /* Wait until BTS is started and at full power */
2259 var integer max_rx_lvl := f_wait_ramp_up();
2260 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2261
2262 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2263 f_verify_ramp_down(max_rx_lvl);
2264
2265 setverdict(pass);
2266}
2267testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2268 var ConnHdlr vc_conn;
2269 var ConnHdlrPars pars;
2270 f_init();
2271 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2272 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2273 pcu_comp := false, trxc_comp := true);
2274 vc_conn.done;
2275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2276}
2277
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002278/* Verify Tx power:
2279 * + ramping down during ADM state UNLOCKED->LOCKED
2280 * + ramping up during ADM state LOCKED->UNLOCKED
2281 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002282private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002283 var L1ctlDlMessage l1_dl;
2284 var integer last_rx_lvl;
2285
2286 f_connhdlr_init_vty_bsc();
2287
2288 f_l1_tune(L1CTL);
2289 RSL.clear;
2290
2291 /* Wait until BTS is started and at full power */
2292 var integer max_rx_lvl := f_wait_ramp_up();
2293 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2294
2295 log("ADM STATE UNLOCKED->LOCKED");
2296 f_vty_enter_cfg_trx(BSCVTY);
2297 f_vty_transceive(BSCVTY, "rf_locked 1");
2298 last_rx_lvl := max_rx_lvl;
2299 f_verify_ramp_down(max_rx_lvl);
2300
2301 /* Let some time after we received 0dBm, then check we don't receive BCCH
2302 * anymore because scheduler has stopped after ramping down */
2303 f_sleep(2.0);
2304 L1CTL.clear;
2305 timer Tlocked := 2.0;
2306 Tlocked.start;
2307 alt {
2308 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2310 log2str("Received data_ind during rf_locked: ", l1_dl));
2311 }
2312 [] L1CTL.receive { repeat; }
2313 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2314 }
2315
2316 log("ADM STATE LOCKED->UNLOCKED");
2317 f_vty_transceive(BSCVTY, "rf_locked 0");
2318 f_verify_ramp_up();
2319 setverdict(pass);
2320}
2321testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2322 var ConnHdlr vc_conn;
2323 var ConnHdlrPars pars;
2324 f_init();
2325 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2326 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2327 pcu_comp := false, trxc_comp := true);
2328 vc_conn.done;
2329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2330}
2331
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002332private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002333 timer T := 8.0;
2334 T.start;
2335 var RSL_Message rsl;
2336 alt {
2337 [] as_l1_sacch();
2338 [] L1CTL.receive { repeat; }
2339 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2340 if (rsl.ies[3].body.bs_power.power_level == level) {
2341 setverdict(pass)
2342 } else {
2343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2344 }
2345 }
2346 [] T.timeout {
2347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2348 }
2349 }
2350}
2351
2352/* see if the rsl meas res contains our expeced bs power level
2353bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002354private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002355 f_l1_tune(L1CTL);
2356 RSL.clear;
2357
2358 if (mp_bts_trxc_port != -1) {
2359 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2360 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2361 }
2362
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002363 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002364 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2365 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2366
2367 f_est_dchan(more_ies :={valueof(pwr)});
2368
2369 f_check_meas_bs_power_level(pwr_var);
2370
2371 f_rsl_chan_deact();
2372 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2373}
2374
2375/* see if the rsl meas res contains our expeced bs power level
2376bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002377private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002378 f_l1_tune(L1CTL);
2379 RSL.clear;
2380
2381 if (mp_bts_trxc_port != -1) {
2382 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2383 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2384 }
2385
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002386 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002387 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2388
2389 f_est_dchan();
2390
2391 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2392
2393 f_check_meas_bs_power_level(pwr_var);
2394
2395 f_rsl_chan_deact();
2396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2397}
2398
2399testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2400 var ConnHdlr vc_conn;
2401 var ConnHdlrPars pars;
2402 f_init();
2403 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2404 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2405 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2406 pcu_comp := false, trxc_comp := true);
2407 vc_conn.done;
2408 }
2409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2410}
2411
2412testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2413 var ConnHdlr vc_conn;
2414 var ConnHdlrPars pars;
2415 f_init();
2416 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2417 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2418 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2419 pcu_comp := false, trxc_comp := true);
2420 vc_conn.done;
2421 }
2422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2423}
2424
Eric Wild61edb7e2019-06-03 12:38:31 +02002425/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2426second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2427These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002428private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002429 var uint5_t pwr_var := 7;
2430 var L1ctlDlMessage l1_dl;
2431
2432 f_trxc_fake_rssi(rxlev2dbm(10));
2433 f_l1_tune(L1CTL);
2434 RSL.clear;
2435
2436 var RSL_IE_List addl_ies;
2437 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2438
2439 addl_ies := {
2440 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2441 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2442 };
2443
2444 /* establish with power parameters */
2445 f_est_dchan(more_ies := addl_ies);
2446
2447 /* set a high value to ensure L1 power control level increases */
2448 f_trxc_fake_rssi(rxlev2dbm(20));
2449
2450 timer T2 := 6.0;
2451 T2.start;
2452 alt {
2453 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002454 /* Update sent MS power to follow what BTS requests */
2455 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2456 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002457 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002458 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002459 T2.stop;
2460 }
2461 [] L1CTL.receive { repeat; }
2462 [] T2.timeout {
2463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2464 "Power Level in L1 header has not increased sufficiently");
2465 }
2466 }
2467
2468 /* set a low value to ensure L1 power control level decreases */
2469 f_trxc_fake_rssi(rxlev2dbm(0));
2470
2471 timer T4 := 6.0;
2472 T4.start;
2473 alt {
2474 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002475 /* Update sent MS power to follow what BTS requests */
2476 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2477 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002478 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002479 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002480 T4.stop;
2481 setverdict(pass, "Power level in L1 decreased/increased as expected");
2482 }
2483 [] L1CTL.receive { repeat; }
2484 [] T4.timeout {
2485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2486 "Power Level in L1 header has not decreased sufficiently");
2487 }
2488 }
2489
2490 f_rsl_chan_deact();
2491 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2492
2493}
2494
2495/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002496private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002497 var uint5_t pwr_var := 7;
2498 var L1ctlDlMessage l1_dl;
2499
2500 /* set a low value to ensure power increases */
2501 f_trxc_fake_rssi(rxlev2dbm(10));
2502 f_l1_tune(L1CTL);
2503 RSL.clear;
2504
2505 var RSL_IE_List addl_ies;
2506 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2507
2508 addl_ies := {
2509 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2510 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2511 };
2512
2513 /* establish with power parameters */
2514 f_est_dchan(more_ies := addl_ies);
2515
2516 timer T1 := 10.0;
2517 T1.start;
2518 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002519 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2520 /* Update sent MS power to follow what BTS requests */
2521 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2522 repeat;
2523 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002524 [] L1CTL.receive { repeat; }
2525 [] T1.timeout {
2526 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2527 setverdict(fail, "Power level in L1 header should not have changed");
2528 }
2529 }
2530 }
2531
2532 f_rsl_chan_deact();
2533 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2534
2535}
2536
2537/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002538private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002539 var L1ctlDlMessage l1_dl;
2540 var uint5_t pwr_var := 15;
2541 var uint5_t pwr_max_var := f_get_max_power_from_band();
2542
2543 /* set a low value to ensure power increases */
2544 f_trxc_fake_rssi(rxlev2dbm(10));
2545 f_l1_tune(L1CTL);
2546 RSL.clear;
2547
2548 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2549 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2550
2551 /* establish with fixed power level */
2552 f_est_dchan(more_ies :={valueof(pwr)});
2553
2554 /* check our initial power level */
2555 f_wait_for_l1_power_level(pwr_var);
2556
2557 /* update power param to enable power loop
2558 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2559 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2560
2561 /* wait, then check that our power level was reduced */
2562 timer T1 := 10.0;
2563 T1.start;
2564 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002565 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2566 /* Update sent MS power to follow what BTS requests */
2567 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2568 repeat;
2569 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002570 [] L1CTL.receive { repeat; }
2571 [] T1.timeout {
2572 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2573 if( f_power_level_is_highest_dbm(rcv) ){
2574 setverdict(pass, "Power level in L1 header reduced as expected");
2575 } else {
2576 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2577 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2578 }
2579 }
2580 }
2581
2582 f_rsl_chan_deact();
2583 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2584
2585}
2586
2587/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002588private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002589 var L1ctlDlMessage l1_dl;
2590
2591 /* set a high value to ensure power decreases */
2592 f_trxc_fake_rssi(rxlev2dbm(50));
2593 f_l1_tune(L1CTL);
2594 RSL.clear;
2595
2596 var uint5_t pwr_var := 5;
2597 var uint5_t pwr_target_val := 15;
2598
2599 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2600 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2601
2602 /* establish with fixed power level */
2603 f_est_dchan(more_ies :={valueof(pwr)});
2604
2605 /* check our initial power level */
2606 f_wait_for_l1_power_level(pwr_var);
2607
2608 /* update power param to enable power loop
2609 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002610 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002611
2612 /* wait, then check that our power level was increased */
2613 timer T1 := 10.0;
2614 T1.start;
2615 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002616 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2617 /* Update sent MS power to follow what BTS requests */
2618 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2619 repeat;
2620 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002621 [] L1CTL.receive { repeat; }
2622 [] T1.timeout {
2623 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2624 setverdict(pass, "Power level in L1 header increased to lowest power value");
2625 } else {
2626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2627 "Power level in L1 header NOT increased to lowest power value");
2628 }
2629 }
2630 }
2631
2632 f_rsl_chan_deact();
2633 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2634
2635}
2636
Eric Wild095024b2019-06-17 15:08:57 +02002637/* see if we change the power level without receiving power parameters, which should not happen
2638rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002639private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002640 var L1ctlDlMessage l1_dl;
2641
2642 /* set a high value to ensure power decreases */
2643 f_trxc_fake_rssi(rxlev2dbm(50));
2644 f_l1_tune(L1CTL);
2645 RSL.clear;
2646
2647 var uint5_t pwr_var := 5;
2648
2649 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2650 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2651
2652 /* establish with fixed power level */
2653 f_est_dchan(more_ies :={valueof(pwr)});
2654
2655 /* check our initial power level */
2656 f_wait_for_l1_power_level(pwr_var);
2657
2658 /* wait, then check that our power level did not change */
2659 timer T1 := 10.0;
2660 T1.start;
2661 alt {
2662 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2663 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2665 "BS power control should not be active unless we receive a power parameters IE!");
2666 }
2667 repeat;
2668 }
2669 [] L1CTL.receive { repeat; }
2670 [] T1.timeout { setverdict(pass); }
2671 }
2672
2673 f_rsl_chan_deact();
2674 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2675
2676}
2677
Eric Wild095024b2019-06-17 15:08:57 +02002678/* see if we change the power level without receiving power parameters, which should not happen
2679ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002680private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002681 var L1ctlDlMessage l1_dl;
2682
2683 /* set a high value to ensure power decreases */
2684 f_trxc_fake_rssi(rxlev2dbm(50));
2685 f_l1_tune(L1CTL);
2686 RSL.clear;
2687
2688 var uint5_t pwr_var := 5;
2689
2690 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2691 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2692
2693 /* establish with fixed power level */
2694 f_est_dchan(more_ies :={valueof(pwr)});
2695
2696 /* check our initial power level */
2697 f_wait_for_l1_power_level(pwr_var);
2698
2699 /* pwr control without power params IE, should NOT activate MS power control*/
2700 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2701
2702 /* wait, then check that our power level did not change */
2703 timer T1 := 10.0;
2704 T1.start;
2705 alt {
2706 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2707 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2709 "BS power control should not be active unless we receive a power parameters IE!");
2710 }
2711 repeat;
2712 }
2713 [] L1CTL.receive { repeat; }
2714 [] T1.timeout { setverdict(pass); }
2715 }
2716
2717 f_rsl_chan_deact();
2718 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2719
2720}
2721
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002722private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002723 var L1ctlDlMessage l1_dl;
2724 timer T0 := 10.0;
2725 T0.start;
2726 alt {
2727 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2728 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2730 "Power level in L1 header != signaled (RSL) power level.");
2731 }
2732 }
2733 [] L1CTL.receive { repeat; }
2734 [] T0.timeout {
2735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2736 "Timeout waiting for initial power level");
2737 }
2738 }
2739 T0.stop;
2740}
2741
2742private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2743 var IntegerRecord min_dbm_level;
2744 var IntegerRecord max_dbm_level;
2745 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2746
2747 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2748 if (min_dbm_level[i] == level) {
2749 return true;
2750 }
2751 }
2752 return false;
2753}
2754
2755private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2756 var IntegerRecord min_dbm_level;
2757 var IntegerRecord max_dbm_level;
2758 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2759
2760 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2761 if (max_dbm_level[i] == level) {
2762 return true;
2763 }
2764 }
2765 return false;
2766}
2767
2768private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2769 var IntegerRecord min_dbm_level;
2770 var IntegerRecord max_dbm_level;
2771 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2772 return max_dbm_level[0];
2773}
2774
2775type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002776private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002777private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2778 // 45.005 4.1.1
2779 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2780 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2781 2, 1, 0};
2782 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2783 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2784 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2785 var IntegerRecord rv;
2786
2787 select(band){
2788 case (BtsBand_allGSM){
2789 rv := gsm_power;
2790 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2791 max_dbm_level := {2, 1, 0};
2792 }
2793 case("DCS1800"){
2794 rv := dcs_power;
2795 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2796 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2797 }
2798 case("PCS1900"){
2799 rv := pcs_power;
2800 min_dbm_level := {15};
2801 max_dbm_level := {30};
2802 }
2803 }
2804
2805 return rv;
2806}
2807
2808private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2809 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2810}
2811
2812testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2813 var ConnHdlr vc_conn;
2814 var ConnHdlrPars pars;
2815 f_init();
2816 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2817 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2818 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2819 pars.bts0_band := f_vty_get_bts0_band();
2820 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2821 vc_conn.done;
2822 }
2823 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2825}
2826
2827testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2828 var ConnHdlr vc_conn;
2829 var ConnHdlrPars pars;
2830 f_init();
2831 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2832 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2833 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2834 pars.bts0_band := f_vty_get_bts0_band();
2835 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2836 vc_conn.done;
2837 }
2838 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2840}
2841
2842testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2843 var ConnHdlr vc_conn;
2844 var ConnHdlrPars pars;
2845 f_init();
2846 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2847 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2848 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2849 pars.bts0_band := f_vty_get_bts0_band();
2850 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2851 vc_conn.done;
2852 }
2853 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2855}
2856
2857testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2858 var ConnHdlr vc_conn;
2859 var ConnHdlrPars pars;
2860 f_init();
2861 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2862 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2863 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2864 pars.bts0_band := f_vty_get_bts0_band();
2865 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2866 vc_conn.done;
2867 }
2868 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2870}
2871
Eric Wild280ccb82019-06-17 11:11:52 +02002872testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2873 var ConnHdlr vc_conn;
2874 var ConnHdlrPars pars;
2875 f_init();
2876 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2877 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2878 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2879 pars.bts0_band := f_vty_get_bts0_band();
2880 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2881 vc_conn.done;
2882 }
2883 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2885}
2886
Eric Wild095024b2019-06-17 15:08:57 +02002887testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2888 var ConnHdlr vc_conn;
2889 var ConnHdlrPars pars;
2890 f_init();
2891 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2892 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2893 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2894 pars.bts0_band := f_vty_get_bts0_band();
2895 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2896 vc_conn.done;
2897 }
2898 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2900}
2901
Harald Welte70767382018-02-21 12:16:40 +01002902testcase TC_meas_res_sign_tchf() runs on test_CT {
2903 var ConnHdlr vc_conn;
2904 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002905 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002906 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2907 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002908 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2909 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002910 vc_conn.done;
2911 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002913}
2914testcase TC_meas_res_sign_tchh() runs on test_CT {
2915 var ConnHdlr vc_conn;
2916 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002917 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002918 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2919 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002920 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2921 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002922 vc_conn.done;
2923 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002925}
2926testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2927 var ConnHdlr vc_conn;
2928 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002929 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002930 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2931 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002932 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2933 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002934 vc_conn.done;
2935 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002937}
2938testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2939 var ConnHdlr vc_conn;
2940 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002941 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002942 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2943 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002944 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2945 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002946 vc_conn.done;
2947 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002949}
Harald Welte685d5982018-02-27 20:42:05 +01002950testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2951 var ConnHdlr vc_conn;
2952 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002953 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002954 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2955 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2956 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2957 pars.l1_pars.toa256_enabled := true;
2958 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2959 vc_conn.done;
2960 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002962}
2963
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002964/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2965 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002966private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002967 var L1ctlDlMessage l1_dl;
2968 var RSL_IE_MS_Power ms_power;
2969 var RSL_Message rsl;
2970 var uint5_t power_level := 0;
2971
2972 f_l1_tune(L1CTL);
2973 RSL.clear;
2974
2975 f_est_dchan();
2976
2977 ms_power.reserved := 0;
2978 ms_power.fpc_epc := false;
2979
2980 /* Send the first power control command. This will disable any BTS/TRX
2981 * internal power control and switch the MS (which is not in scope of
2982 * this test) to a constant power level. We start with a power level
2983 * of 0 */
2984 ms_power.power_level := power_level;
2985 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2986 RSL.send(rsl);
2987
2988 alt {
2989
2990 /* Pick all SACCH blocks for checking */
2991 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2992
2993 /* The first byte of the L1 header contains the power level.
2994 * The reserved bits and the fpc bit is set to 0, so we may
2995 * compare directly. */
2996 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2997 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2998 }
2999
3000 /* Signal a new power level via RSL for the next turn. */
3001 if (power_level < 31) {
3002 power_level := power_level + 1;
3003 ms_power.power_level := power_level;
3004 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3005 RSL.send(rsl);
3006 repeat;
3007 }
3008
3009 }
3010
3011 /* Ignore all other blocks */
3012 [] L1CTL.receive { repeat; }
3013
3014 }
3015
3016 f_rsl_chan_deact();
3017 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3018
3019 setverdict(pass);
3020}
3021
3022testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3023 var ConnHdlr vc_conn;
3024 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003025 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003026
3027 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3028 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3029 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3030 vc_conn.done;
3031 }
3032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3033}
Harald Welte70767382018-02-21 12:16:40 +01003034
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003035/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003036TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003037private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003038 var L1ctlDlMessage l1_dl;
3039 var uint5_t ta_to_test := 16;
3040
3041
3042 f_l1_tune(L1CTL);
3043 RSL.clear;
3044
3045 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003046 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003047
3048 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3049
3050
3051 alt {
3052
3053 /* Pick all SACCH blocks for checking */
3054 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3055
3056 /* The second byte of the L1 header contains the TA. */
3057 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3058 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3059 }
3060
3061 }
3062
3063 /* Ignore all other blocks */
3064 [] L1CTL.receive { repeat; }
3065
3066 }
3067
3068 f_rsl_chan_deact();
3069 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3070
3071 setverdict(pass);
3072}
3073
3074testcase TC_rsl_chan_initial_ta() runs on test_CT {
3075 var ConnHdlr vc_conn;
3076 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003077 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003078 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003079 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3080 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003081 vc_conn.done;
3082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3083}
3084
Eric Wilde57e1a62019-05-28 13:30:55 +02003085/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003086private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003087 var L1ctlDlMessage l1_dl;
3088 var uint5_t ms_power_level := 7;
3089
3090 var RSL_IE_MS_Power ms_power;
3091 ms_power.reserved := 0;
3092 ms_power.fpc_epc := false;
3093 ms_power.power_level := ms_power_level;
3094
3095 f_l1_tune(L1CTL);
3096 RSL.clear;
3097
3098 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3099
3100 timer T := 1.0;
3101 T.start;
3102 alt {
3103 /* Pick all SACCH blocks for checking */
3104 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3105 /* The first byte of the L1 header contains the power level.. */
3106 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3107 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3108 }
3109 }
3110 /* Ignore all other blocks */
3111 [] L1CTL.receive { repeat; }
3112 [] T.timeout {
3113 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3114 }
3115 }
3116
3117 f_rsl_chan_deact();
3118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3119 setverdict(pass);
3120}
3121
3122testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3123 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3124 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3125}
3126
Harald Welte0472ab42018-03-12 15:02:26 +01003127/* 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 +01003128private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003129 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003130 RSL.clear;
3131
3132 f_est_dchan();
3133 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003134 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003135
3136 timer T := 40.0;
3137 T.start;
3138 alt {
3139 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3140 setverdict(pass)
3141 }
3142 [] RSL.receive { repeat };
3143 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003145 }
3146 }
3147 f_rsl_chan_deact();
3148}
3149testcase TC_conn_fail_crit() runs on test_CT {
3150 var ConnHdlr vc_conn;
3151 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003152 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003153 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3154 pars.t_guard := 60.0;
3155 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3156 vc_conn.done;
3157}
3158
Harald Welte93640c62018-02-25 16:59:33 +01003159/***********************************************************************
3160 * Paging
3161 ***********************************************************************/
3162
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003163private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003164 if (tmsi == 'FFFFFFFF'O) {
3165 return true;
3166 } else {
3167 return false;
3168 }
3169}
Harald Welte70767382018-02-21 12:16:40 +01003170
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003171private type record allowedFn { integer frame_nr }
3172private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3173private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3174private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3175private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3176private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3177private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3178private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3179private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3180private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003181{
3182 var integer frame_nr_51;
3183 frame_nr_51 := frame_nr mod 51
3184
3185 var allowedFn fn_check;
3186 fn_check.frame_nr := frame_nr_51;
3187
3188 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003190 return;
3191 }
3192
3193 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3194 return;
3195 }
3196 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3197 return;
3198 }
3199 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3200 return;
3201 }
3202 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3203 return;
3204 }
3205 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3206 return;
3207 }
3208 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3209 return;
3210 }
3211 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3212 return;
3213 }
3214 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3215 return;
3216 }
3217
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003219 return;
3220}
3221
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003222private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3223 inout integer num_paging_rcv_ids,
3224 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003225runs on test_CT {
3226 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003227 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003228 repeat;
3229 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003230 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003231 var octetstring without_plen :=
3232 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3233 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003234
3235 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3236
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003237 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3238 /* Ignore empty RR Paging Request (PCH filling) messages.
3239 * TODO: does it make sense to count them? */
3240 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003241 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3242 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003243 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003244 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3245 }
3246 } else if (match(rr, tr_PAGING_REQ2)) {
3247 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3248 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3249 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3250 }
3251 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3252 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3253 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003254 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003255 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3256 }
3257 } else if (match(rr, tr_PAGING_REQ3)) {
3258 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3259 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3260 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3261 }
3262 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3263 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3264 }
3265 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3266 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3267 }
3268 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3269 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3270 }
3271 }
3272 repeat;
3273 }
3274}
3275
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003276private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003277 boolean combined_ccch,
3278 integer bs_ag_blks_res,
3279 float load_factor,
3280 boolean exp_load_ind,
3281 boolean exp_overload,
3282 boolean use_tmsi
3283}
3284
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003285private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003286 integer num_paging_sent,
3287 integer num_paging_rcv_msgs,
3288 integer num_paging_rcv_ids,
3289 integer num_overload
3290}
3291
Harald Welte68e495b2018-02-25 00:05:57 +01003292/* Helper function for paging related testing */
3293private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003294 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003295 f_init_l1ctl();
3296 f_l1_tune(L1CTL);
3297
3298 var PagingTestState st := {
3299 num_paging_sent := 0,
3300 num_paging_rcv_msgs := 0,
3301 num_paging_rcv_ids := 0,
3302 num_overload := 0
3303 };
3304
3305 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3306 var float max_pch_imsi_per_sec;
3307 if (cfg.use_tmsi) {
3308 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3309 } else {
3310 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3311 }
3312 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3313 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003314 var float time_total := 20.0;
3315 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3316 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003317
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003318 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3319 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003320
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003321 timer T_itv := 0.0;
3322 T_itv.start;
3323 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003324 alt {
3325 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003326 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003327 st.num_overload := st.num_overload + 1;
3328 repeat;
3329 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003330 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003332 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003333 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003334 log("Rx LOAD_IND");
3335 /* FIXME: analyze/verify interval + contents */
3336 repeat;
3337 }
3338 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003339 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003340 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003341 [] T_itv.timeout {
3342 /* Send paging cmds based on elapsed time */
3343 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3344 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003345 var MobileIdentityV mi;
3346
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003347 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003348 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003349 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003350 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003351 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003352 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003353
3354 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003355 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 +02003356
3357 st.num_paging_sent := st.num_paging_sent + 1;
3358 }
3359 if (st.num_paging_sent < pkt_total) {
3360 /* Wait for interval to next PAGING COMMAND */
3361 var float time_now := T_total.read;
3362 var float next_sched := int2float(st.num_paging_sent)*interval;
3363 if (next_sched > time_now) {
3364 T_itv.start(next_sched - time_now);
3365 } else {
3366 T_itv.start(0.0);
3367 }
3368 } else {
3369 /* We are done, no need to keep counting */
3370 T_total.stop;
3371 }
3372 }
3373 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003374 }
3375 }
3376
3377 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3378 timer T_wait := 18.0;
3379 T_wait.start;
3380 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003381 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003382 [] L1CTL.receive { repeat; }
3383 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003384 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3385 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003386 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003388 }
Harald Welte68e495b2018-02-25 00:05:57 +01003389 }
3390
3391 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3392 " rcvd_ids=", st.num_paging_rcv_ids);
3393 return st;
3394}
3395
3396/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3397 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3398 * - that CCCH LOAD IND (PCH) are being generated
3399 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3400testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003401 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003402 var PagingTestCfg cfg := {
3403 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003404 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003405 load_factor := 0.8,
3406 exp_load_ind := true,
3407 exp_overload := false,
3408 use_tmsi := false
3409 };
3410 var PagingTestState st := f_TC_paging(cfg);
3411 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3413 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003414 } else {
3415 setverdict(pass);
3416 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003418}
3419
3420/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3421 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3422 * - that CCCH LOAD IND (PCH) are being generated
3423 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3424testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003425 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003426 var PagingTestCfg cfg := {
3427 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003428 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003429 load_factor := 0.8,
3430 exp_load_ind := true,
3431 exp_overload := false,
3432 use_tmsi := true
3433 };
3434 var PagingTestState st := f_TC_paging(cfg);
3435 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3437 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003438 } else {
3439 setverdict(pass);
3440 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003442}
3443
3444/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3445 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3446 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3447 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3448testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003449 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003450 var PagingTestCfg cfg := {
3451 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003452 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003453 load_factor := 2.0,
3454 exp_load_ind := true,
3455 exp_overload := true,
3456 use_tmsi := false
3457 };
3458 var PagingTestState st := f_TC_paging(cfg);
3459 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3460 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003461 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003462 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 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 +01003464 } else {
3465 setverdict(pass);
3466 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003468}
3469
3470/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3471 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3472 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3473 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3474testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003475 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003476 var PagingTestCfg cfg := {
3477 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003478 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003479 load_factor := 2.0,
3480 exp_load_ind := true,
3481 exp_overload := true,
3482 use_tmsi := true
3483 };
3484 var PagingTestState st := f_TC_paging(cfg);
3485 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3486 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003487 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003488 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003489 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 +01003490 } else {
3491 setverdict(pass);
3492 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003494}
3495
3496
Harald Welte93640c62018-02-25 16:59:33 +01003497/***********************************************************************
3498 * Immediate Assignment / AGCH
3499 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003500private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003501 len := 0,
3502 ma := ''B
3503}
Harald Welte93640c62018-02-25 16:59:33 +01003504
Harald Weltee8d750e2018-06-10 21:41:35 +02003505private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3506 return int2str(num_tx) & " sent, "
3507 & int2str(num_rx) & " received, "
3508 & int2str(num_del) & " deleted";
3509}
3510
3511private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3512 var L1ctlDlMessage l1_dl;
3513 timer T := 10.0;
3514 var integer num_tx := 0;
3515 var integer num_rx := 0;
3516 var integer num_del := 0;
3517 var charstring res_str;
3518 var float rx_ratio;
3519
Harald Welte10474062019-05-30 16:48:17 +02003520 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003521 f_init_l1ctl();
3522 f_l1_tune(L1CTL);
3523
3524 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003525 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003526 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3527 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003528 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003529 num_tx := num_tx+1;
3530 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003531 }
3532 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003533 T.start;
3534 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003535 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003536 num_del := num_del+1;
3537 repeat;
3538 }
3539 [] RSL_CCHAN.receive {
3540 repeat;
3541 }
3542 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003543 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3544 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3545 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003546 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003547 } else {
3548 num_rx := num_rx+1;
3549 }
3550 repeat;
3551 }
3552 [] L1CTL.receive { repeat; }
3553 [] T.timeout { }
3554 }
3555 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3556 log("AGCH test: " & res_str);
3557 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003559 }
3560 rx_ratio := int2float(num_rx) / int2float(num_tx);
3561 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003562 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 +02003563 } else {
3564 setverdict(pass);
3565 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003567}
3568
Harald Weltee8d750e2018-06-10 21:41:35 +02003569/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3570testcase TC_imm_ass_1000_20ms() runs on test_CT {
3571 f_TC_imm_ass(1000, 0.02, 0.25);
3572}
3573
3574/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3575testcase TC_imm_ass_200_0ms() runs on test_CT {
3576 f_TC_imm_ass(200, 0.0, 0.05);
3577}
3578
3579/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3580testcase TC_imm_ass_200_76ms() runs on test_CT {
3581 f_TC_imm_ass(150, 0.076, 1.00);
3582}
3583
3584
3585
Harald Welte48494ca2018-02-25 16:59:50 +01003586/***********************************************************************
3587 * BCCH
3588 ***********************************************************************/
3589
3590/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003591private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003592 GsmFrameNumber frame_number,
3593 SystemInformation si
3594}
3595
3596/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003597private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003598
3599/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003600private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003601
3602/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003603private function f_si_vecslot_contains(SystemInformationVector arr,
3604 RrMessageType key,
3605 boolean bcch_ext := false)
3606return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003607 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3608 var integer fn_mod51 := arr[i].frame_number mod 51;
3609 if (not bcch_ext and fn_mod51 == 2 or
3610 bcch_ext and fn_mod51 == 6) {
3611 if (arr[i].si.header.message_type == key) {
3612 return true;
3613 }
3614 }
3615 }
3616 return false;
3617}
3618
3619/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003620private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3621 integer tc, RrMessageType key,
3622 boolean ext_bcch := false)
3623{
Harald Welte48494ca2018-02-25 16:59:50 +01003624 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003626 }
3627}
3628
3629/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003630private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3631 RrMessageType key)
3632return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003633 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3634 if (f_si_vecslot_contains(arr[tc], key) or
3635 f_si_vecslot_contains(arr[tc], key, true)) {
3636 return true;
3637 }
3638 }
3639 return false;
3640}
3641
3642/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003643private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3644 RrMessageType key,
3645 boolean bcch_ext := false,
3646 integer n := 1, integer m := 4)
3647return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003648 var integer count := 0;
3649 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003651 }
3652 for (var integer i:= 0; i < m; i := i + 1) {
3653 var integer fn_mod51 := arr[i].frame_number mod 51;
3654 if (not bcch_ext and fn_mod51 == 2 or
3655 bcch_ext and fn_mod51 == 6) {
3656 if (arr[i].si.header.message_type == key) {
3657 count := count + 1;
3658 }
3659 }
3660 }
3661 if (count >= n) {
3662 return true;
3663 } else {
3664 return false;
3665 }
3666}
3667
3668/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003669private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3670 integer tc, RrMessageType key,
3671 boolean ext_bcch := false,
3672 integer n, integer m)
3673{
Harald Welte48494ca2018-02-25 16:59:50 +01003674 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003676 }
3677}
3678
3679/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003680private function f_si_vecslot_contains_only(SystemInformationVector arr,
3681 RrMessageType key,
3682 boolean bcch_ext := false)
3683return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003684 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3685 var integer fn_mod51 := arr[i].frame_number mod 51;
3686 if (not bcch_ext and fn_mod51 == 2 or
3687 bcch_ext and fn_mod51 == 6) {
3688 if (arr[i].si.header.message_type != key) {
3689 return false;
3690 }
3691 }
3692 }
3693 return true;
3694}
3695
3696/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003697private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3698 integer tc, RrMessageType key,
3699 boolean ext_bcch := false)
3700{
Harald Welte48494ca2018-02-25 16:59:50 +01003701 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003703 }
3704}
3705
3706/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003707private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003708 boolean bcch_extended,
3709 boolean si1_present,
3710 boolean si2bis_present,
3711 boolean si2ter_present,
3712 boolean si2quater_present,
3713 boolean si7_present,
3714 boolean si8_present,
3715 boolean si9_present,
3716 boolean si13_present,
3717 boolean si13alt_present,
3718 boolean si15_present,
3719 boolean si16_present,
3720 boolean si17_present,
3721 boolean si2n_present,
3722 boolean si21_present,
3723 boolean si22_present
3724}
3725
3726/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003727private function f_validate_si_scheduling(SystemInformationConfig cfg,
3728 SystemInformationVectorPerTc si_per_tc)
3729{
Harald Welte48494ca2018-02-25 16:59:50 +01003730 var integer i;
3731 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3732 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003734 }
3735 }
3736 if (cfg.si1_present) {
3737 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3738 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3739 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3740 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3741 /* make sure *ALL* contain SI1 */
3742 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3743 }
3744 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3745 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3746 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3747 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3748 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3749 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3750
3751 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3752 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3753 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3754 * consecutive occurrences of TC = 4. */
3755 if (cfg.si2bis_present and not cfg.si2ter_present) {
3756 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3757 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3758 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3759 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3760 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3761 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3762 }
3763
3764 if (cfg.si7_present or cfg.si8_present) {
3765 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3766 * if System Information type 4 does not contain all information needed for cell
3767 * selection and reselection. */
3768 if (not cfg.bcch_extended) {
3769 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3770 }
3771 if (cfg.si7_present) {
3772 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3773 }
3774 if (cfg.si8_present) {
3775 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3776 }
3777 }
3778
3779 if (cfg.si2quater_present) {
3780 /* iii) System information type 2 quater is sent if needed, as determined by the system
3781 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3782 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3783 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3784 * within any of 4 consecutive occurrences of TC = 5. */
3785 if (not (cfg.bcch_extended)) {
3786 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3787 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3788 } else {
3789 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3790 }
3791 } else {
3792 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3793 }
3794 }
3795 if (cfg.si9_present) {
3796 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3797 * in system information type 3 as defined in 3GPP TS 44.018. */
3798 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3799 }
3800 if (cfg.si13_present) {
3801 /* vii) System Information type 13 is only related to the GPRS service. System Information
3802 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3803 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3804 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3805 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3806 * within any of 4 consecutive occurrences of TC=4. */
3807 if (not cfg.bcch_extended) {
3808 log("not-bccch-extended");
3809 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3810 } else {
3811 log("bccch-extended");
3812 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3813 }
3814 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003816 }
3817 }
3818 if (cfg.si16_present or cfg.si17_present) {
3819 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3820 * should not be sent in a cell where network sharing is used (see rule xv). */
3821 if (cfg.si22_present) {
3822 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3823 }
3824 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003826 }
3827 if (not cfg.bcch_extended) {
3828 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3829 }
3830 if (cfg.si16_present) {
3831 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3832 }
3833 if (cfg.si17_present) {
3834 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3835 }
3836 }
3837
3838 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3839 * broadcast information. The frequency with which they are sent is determined by the
3840 * system operator. System Information type 9 identifies the scheduling of System
3841 * Information type 18 and 20 messages. */
3842
3843 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3844 * Information Type 19 is present, then its scheduling shall be indicated in System
3845 * Information Type 9. */
3846
3847 if (cfg.si15_present) {
3848 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3849 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3850 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3851 * 4 consecutive occurrences of TC = 1. */
3852 if (not cfg.bcch_extended) {
3853 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3854 } else {
3855 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3856 }
3857 }
3858 if (cfg.si13alt_present) {
3859 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3860 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3861 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3862 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3863 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3864 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3865 * of TC = 4. */
3866 if (cfg.si13_present) {
3867 testcase.stop("Error: Cannot have SI13alt and SI13");
3868 }
3869 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003871 }
3872 if (not cfg.bcch_extended) {
3873 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3874 } else {
3875 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3876 }
3877 }
3878 if (cfg.si2n_present) {
3879 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3880 * as determined by the system operator. In the case that the message is sent on the
3881 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3882 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3883 * consecutive occurrences of TC = 4. */
3884 if (not cfg.bcch_extended) {
3885 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3886 } else {
3887 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3888 }
3889 }
3890 if (cfg.si21_present) {
3891 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3892 * determined by the system operator. If Extended Access Barring is in use in the cell
3893 * then this message is sent at least once within any of 4 consecutive occurrences of
3894 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3895 * cell then this message shall only be sent on BCCH Ext. */
3896 if (not cfg.bcch_extended) {
3897 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3898 } else {
3899 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3900 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003902 }
3903 }
3904 }
3905 if (cfg.si22_present) {
3906 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3907 * should not be sent in a cell where SoLSA is used (see rule viii). System
3908 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3909 * =2 and TC=6. */
3910 if (cfg.si16_present or cfg.si17_present) {
3911 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3912 }
3913 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3914 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003916 }
3917 if (not cfg.bcch_extended) {
3918 testcase.stop("Error: SI22 requires BCCH Extd!");
3919 } else {
3920 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3921 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3922 }
3923 }
3924}
3925
3926/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003927private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3928return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003929 timer T := duration;
3930 var SystemInformationVectorPerTc si_per_tc;
3931 var L1ctlDlMessage l1_dl;
3932
3933 /* initialize all per-TC vectors empty */
3934 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3935 si_per_tc[i] := {};
3936 }
3937
3938 /* flush all previous L1 queued msgs */
3939 pt.clear;
3940
3941 T.start;
3942 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003943 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003944 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3945 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3946 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003947 repeat;
3948 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003949
Harald Welte48494ca2018-02-25 16:59:50 +01003950 var integer tc := f_gsm_compute_tc(sig.frame_number);
3951 log("SI received at TC=", tc, ": ", sig.si);
3952 /* append to the per-TC bucket */
3953 si_per_tc[tc] := si_per_tc[tc] & { sig };
3954 repeat;
3955 }
3956 [] pt.receive { repeat; }
3957 [] T.timeout { }
3958 }
3959
3960 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3961 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3962 }
3963 log("si_per_tc=", si_per_tc);
3964 return si_per_tc;
3965}
3966
3967/* helper function: Set given SI via RSL + validate scheduling.
3968 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003969private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003970 var SystemInformationVectorPerTc si_per_tc;
3971 f_init_l1ctl();
3972 f_l1_tune(L1CTL);
3973
3974 /* Sample + Validate Scheduling */
3975 si_per_tc := f_l1_sample_si(L1CTL);
3976 f_validate_si_scheduling(si_cfg, si_per_tc);
3977
3978 setverdict(pass);
3979}
3980
3981testcase TC_si_sched_default() runs on test_CT {
3982 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003983 /* 2+3+4 are mandatory and set in f_init() */
3984 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003986}
3987
3988testcase TC_si_sched_1() runs on test_CT {
3989 f_init();
3990 si_cfg.si1_present := true;
3991 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003992 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003994}
3995
3996testcase TC_si_sched_2bis() runs on test_CT {
3997 f_init();
3998 si_cfg.si2bis_present := true;
3999 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4000 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004002}
4003
4004testcase TC_si_sched_2ter() runs on test_CT {
4005 f_init();
4006 si_cfg.si2ter_present := true;
4007 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4008 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004010}
4011
4012testcase TC_si_sched_2ter_2bis() runs on test_CT {
4013 f_init();
4014 si_cfg.si2bis_present := true;
4015 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4016 si_cfg.si2ter_present := true;
4017 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4018 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004020}
4021
4022testcase TC_si_sched_2quater() runs on test_CT {
4023 f_init();
4024 si_cfg.si2quater_present := true;
4025 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4026 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004028}
4029
4030testcase TC_si_sched_13() runs on test_CT {
4031 f_init();
4032 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004033 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004034 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004036}
4037
4038testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4039 f_init();
4040 si_cfg.si2bis_present := true;
4041 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4042 si_cfg.si2ter_present := true;
4043 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4044 si_cfg.si2quater_present := true;
4045 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4046 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004047 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004048 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004050}
4051
4052
Harald Welte68e495b2018-02-25 00:05:57 +01004053testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004054 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004055 /* FIXME: enable / disable individual BCCH info */
4056 //ts_RSL_BCCH_INFO(si_type, info);
4057 /* expect no ERROR REPORT after either of them *
4058 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004060}
4061
Harald Welte93640c62018-02-25 16:59:33 +01004062/***********************************************************************
4063 * Low-Level Protocol Errors / ERROR REPORT
4064 ***********************************************************************/
4065
Harald Welte01d982c2018-02-25 01:31:40 +01004066private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4067 timer T := 5.0;
4068 T.start;
4069 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004070 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004071 setverdict(pass);
4072 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004073 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004075 }
4076 [] RSL_CCHAN.receive {
4077 repeat;
4078 }
4079 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004081 }
4082 }
4083}
4084
4085/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4086testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004087 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004088 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4089 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004090 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004091
4092 f_exp_err_rep(RSL_ERR_PROTO);
4093}
4094
4095/* Provoke a mandatory IE error and match on ERROR REPORT */
4096testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004097 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004098
4099 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4100 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004101 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004102
4103 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4104}
4105
4106/* Provoke an IE content error and match on ERROR REPORT */
4107testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004108 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004109 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4110 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004111 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004112
4113 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4114}
4115
Harald Welteee25aae2019-05-19 14:32:37 +02004116/* attempt to activate channel with wrong RSL Message Discriminator IE */
4117function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4118 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4119 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4120 RSL.send(rsl);
4121 f_rslem_unregister(0, g_chan_nr);
4122}
4123testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4124 var ConnHdlr vc_conn;
4125 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4126
Harald Welte10474062019-05-30 16:48:17 +02004127 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004128
4129 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4130 vc_conn.done;
4131 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4132
4133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4134}
4135
4136/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004137private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004138 var template (value) RSL_Message rsl_tx;
4139 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4140 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4141 RSL.send(rsl_tx);
4142 f_rslem_unregister(0, g_chan_nr);
4143}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004144private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004145 var template (value) RSL_Message rsl_tx;
4146 /* we first have to activate the dedicated channel */
4147 f_rsl_chan_act(g_pars.chan_mode);
4148 /* ... to then send an invalid RLL message */
4149 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4150 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4151 RSL.send(rsl_tx);
4152 f_rslem_unregister(0, g_chan_nr);
4153}
4154testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4155 var ConnHdlr vc_conn;
4156 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4157 var template (value) RSL_Message rsl_tx;
4158
Harald Welte10474062019-05-30 16:48:17 +02004159 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004160
4161 /* Common Channel with wrong message type */
4162 RSL_CCHAN.clear;
4163 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4164 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004165 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004166 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4167
4168 /* TRX Management */
4169 RSL_CCHAN.clear;
4170 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4171 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004172 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004173 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4174
4175 /* Dedicated Channel */
4176 RSL_CCHAN.clear;
4177 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4178 vc_conn.done;
4179 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4180
4181 /* RLL */
4182 RSL_CCHAN.clear;
4183 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4184 vc_conn.done;
4185 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4186}
4187
4188/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004189private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004190 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4191 f_rslem_unregister(0, g_chan_nr);
4192}
4193testcase TC_err_rep_wrong_sequence() runs on test_CT {
4194 var ConnHdlr vc_conn;
4195 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4196
Harald Welte10474062019-05-30 16:48:17 +02004197 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004198
4199 RSL_CCHAN.clear;
4200 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4201 vc_conn.done;
4202 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4203}
4204
Harald Welte93640c62018-02-25 16:59:33 +01004205/***********************************************************************
4206 * IPA CRCX/MDCX/DLCS media stream handling
4207 ***********************************************************************/
4208
Harald Weltea871a382018-02-25 02:03:14 +01004209/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004210private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004211 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4212 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004213}
4214testcase TC_ipa_dlcx_not_active() runs on test_CT {
4215 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004216 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004217 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4218 vc_conn.done;
4219}
Harald Welte68e495b2018-02-25 00:05:57 +01004220
Harald Weltea3f1df92018-02-25 12:49:55 +01004221/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004222private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004223 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4224 "IPA CRCX ACK");
4225 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4226 "IPA CRCX NACK");
4227}
4228testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4229 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004230 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004231 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4232 vc_conn.done;
4233}
4234
4235/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004236private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004237 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4238 "IPA CRCX ACK");
4239 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4240 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4241 var uint7_t rtp_pt2 := f_rnd_int(127);
4242 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4243 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4244 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4245 "IPA MDCX ACK");
4246 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4247 "IPA DLCX ACK");
4248}
4249testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4250 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004251 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004252 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4253 vc_conn.done;
4254}
4255
Harald Welte3ae11da2018-02-25 13:36:06 +01004256/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004257private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004258 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4259 "IPA CRCX ACK");
4260 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4261 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4262 var uint7_t rtp_pt2 := f_rnd_int(127);
4263 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4264 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4265 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4266 "IPA MDCX ACK");
4267 /* Second MDCX */
4268 remote_ip := f_rnd_int(c_UINT32_MAX);
4269 remote_port := f_rnd_int(c_UINT16_MAX);
4270 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4271 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4272 "IPA MDCX ACK");
4273 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4274 "IPA DLCX ACK");
4275}
4276testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004278 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004279 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4280 vc_conn.done;
4281}
4282
Harald Welte9912eb52018-02-25 13:30:15 +01004283/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004284private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004285 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4286 "IPA CRCX NACK");
4287}
4288testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4289 var ConnHdlrPars pars;
4290 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004291 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004292
4293 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4294 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4295 vc_conn.done;
4296
4297 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4298 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4299 vc_conn.done;
4300}
4301
Harald Weltea3f1df92018-02-25 12:49:55 +01004302
Harald Welte883340c2018-02-28 18:59:29 +01004303/***********************************************************************
4304 * PCU Socket related tests
4305 ***********************************************************************/
4306
Harald Welte07bd2d22019-05-25 11:03:30 +02004307/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004308friend 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 +01004309runs on test_CT {
4310 timer T := 3.0;
4311
4312 /* we don't expect any RTS.req before PDCH are active */
4313 T.start;
4314 alt {
4315 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004317 }
4318 [] PCU.receive { repeat; }
4319 [] T.timeout { }
4320 }
4321
4322 /* Send PDCH activate request for known PDCH timeslot */
4323 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4324
4325 /* we now expect RTS.req for this timeslot (only) */
4326 T.start;
4327 alt {
4328 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4329 setverdict(pass);
4330 }
4331 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4332 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004334 }
4335 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004337 }
4338 [] PCU.receive { repeat; }
4339 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004341 }
4342 [not exp_success] T.timeout {
4343 setverdict(pass);
4344 }
4345 }
4346}
4347
Harald Welte07bd2d22019-05-25 11:03:30 +02004348/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004349friend 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 +01004350runs on test_CT {
4351 timer T := 3.0;
4352
4353 /* Send PDCH activate request for known PDCH timeslot */
4354 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4355
4356 PCU.clear;
4357 /* we now expect no RTS.req for this timeslot */
4358 T.start;
4359 alt {
4360 [] 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 +02004361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004362 }
4363 [] PCU.receive { repeat; }
4364 [] T.timeout {
4365 setverdict(pass);
4366 }
4367 }
4368}
4369
Harald Weltead033dc2019-05-25 17:28:16 +02004370friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004371 f_init();
4372 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4373}
4374
Harald Welte883340c2018-02-28 18:59:29 +01004375/* PDCH activation via PCU socket; check for presence of RTS.req */
4376testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004377 f_init_pcu_test();
4378
Harald Welte883340c2018-02-28 18:59:29 +01004379 f_TC_pcu_act_req(0, 0, 7, true);
4380}
4381
4382/* PDCH activation via PCU socket on non-PDCU timeslot */
4383testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004384 f_init_pcu_test();
4385
Harald Welte883340c2018-02-28 18:59:29 +01004386 f_TC_pcu_act_req(0, 0, 1, false);
4387}
4388
4389/* PDCH activation via PCU socket on wrong BTS */
4390testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004391 f_init_pcu_test();
4392
Harald Welte883340c2018-02-28 18:59:29 +01004393 f_TC_pcu_act_req(23, 0, 7, false);
4394}
4395
4396/* PDCH activation via PCU socket on wrong TRX */
4397testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004398 f_init_pcu_test();
4399
Harald Welte883340c2018-02-28 18:59:29 +01004400 f_TC_pcu_act_req(0, 23, 7, false);
4401}
4402
4403/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4404testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004405 f_init_pcu_test();
4406
Harald Welte883340c2018-02-28 18:59:29 +01004407 /* Activate PDCH */
4408 f_TC_pcu_act_req(0, 0, 7, true);
4409 f_sleep(1.0);
4410 /* and De-Activate again */
4411 f_TC_pcu_deact_req(0, 0, 7);
4412}
4413
4414/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4415testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004416 f_init_pcu_test();
4417
Harald Welte883340c2018-02-28 18:59:29 +01004418 f_TC_pcu_deact_req(0, 0, 1);
4419}
4420
4421/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4422testcase TC_pcu_ver_si13() runs on test_CT {
4423 const octetstring si13 := '00010203040506070909'O;
4424 var PCUIF_send_data sd;
4425 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004426 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004427
4428 /* Set SI13 via RSL */
4429 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004430
Harald Welte883340c2018-02-28 18:59:29 +01004431 T.start;
4432 alt {
4433 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4434 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4435 setverdict(pass);
4436 } else {
4437 repeat;
4438 }
4439 }
4440 [] PCU.receive { repeat; }
4441 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004443 }
4444 }
4445}
4446
4447private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4448
4449/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004450friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004451 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4452runs on test_CT
4453{
4454 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4455 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4456}
4457
4458/* 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 +02004459friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4460 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004461runs on test_CT
4462{
4463 var PCUIF_send_data sd;
4464
4465 timer T := 3.0;
4466 T.start;
4467 alt {
4468 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4469 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4470 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4471 sd.data.u.rts_req.fn, sapi, data);
4472 }
4473 [] PCU.receive { repeat; }
4474 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004476 }
4477 }
4478}
4479
4480/* Send DATA.req on invalid BTS */
4481testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004482 var TfiUsfArr tua := f_TfiUsfArrInit();
4483 var octetstring data := '0000'O & f_rnd_octstring(21);
4484
4485 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004486
Harald Welte883340c2018-02-28 18:59:29 +01004487 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004488 f_TfiUsfArrSet(tua, 7, 0);
4489 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4490 f_sleep(1.0);
4491
4492 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004493}
4494
4495/* Send DATA.req on invalid TRX */
4496testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004497 var TfiUsfArr tua := f_TfiUsfArrInit();
4498 var octetstring data := '0000'O & f_rnd_octstring(21);
4499
4500 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004501
Harald Welte883340c2018-02-28 18:59:29 +01004502 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004503 f_TfiUsfArrSet(tua, 7, 0);
4504 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4505 f_sleep(1.0);
4506
4507 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004508}
4509
4510/* Send DATA.req on invalid timeslot */
4511testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004512 var TfiUsfArr tua := f_TfiUsfArrInit();
4513 var octetstring data := '0000'O & f_rnd_octstring(21);
4514
4515 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004516
Harald Welte883340c2018-02-28 18:59:29 +01004517 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004518 f_TfiUsfArrSet(tua, 7, 0);
4519 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4520 f_sleep(1.0);
4521
4522 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004523}
4524
4525/* Send DATA.req on timeslot that hasn't been activated */
4526testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004527 var TfiUsfArr tua := f_TfiUsfArrInit();
4528 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004529
Harald Welte7162a612019-05-26 12:56:09 +02004530 f_virtphy_common();
4531
4532 f_TfiUsfArrSet(tua, 7, 0);
4533 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4534 f_sleep(1.0);
4535
4536 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004537}
4538
Harald Weltead033dc2019-05-25 17:28:16 +02004539private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004540 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4541 boolean wait_rts := true)
4542runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004543 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004544 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004545
4546 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004547 if (wait_rts) {
4548 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4549 } else {
4550 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4551 }
Harald Weltead033dc2019-05-25 17:28:16 +02004552
4553 T.start;
4554 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004555 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004556 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4557 setverdict(pass);
4558 }
Harald Welte7162a612019-05-26 12:56:09 +02004559 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4560 setverdict(fail, "Received unexpected ", rx_dl);
4561 }
Harald Weltead033dc2019-05-25 17:28:16 +02004562 [] L1CTL.receive {
4563 repeat;
4564 }
Harald Welte7162a612019-05-26 12:56:09 +02004565 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004566 setverdict(fail, "Timeout waiting for ", data);
4567 }
Harald Welte7162a612019-05-26 12:56:09 +02004568 [not expect_data] T.timeout {
4569 setverdict(pass);
4570 }
Harald Weltead033dc2019-05-25 17:28:16 +02004571 }
4572}
4573
4574private function f_disable_dynamic_ts() runs on test_CT
4575{
4576 f_init_vty_bsc();
4577 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4578 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4579 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4580 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004581 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004582}
4583
4584private function f_virtphy_common() runs on test_CT {
4585 f_disable_dynamic_ts();
4586 f_init_l1ctl();
4587 f_l1_tune(L1CTL);
4588}
4589
4590testcase TC_pcu_data_req_pdtch() runs on test_CT {
4591 var TfiUsfArr tua := f_TfiUsfArrInit();
4592 var octetstring data := '0000'O & f_rnd_octstring(21);
4593
4594 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004595
Harald Welte883340c2018-02-28 18:59:29 +01004596 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004597 f_TfiUsfArrSet(tua, 7, 0);
4598 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4599 f_sleep(1.0);
4600
4601 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004602}
4603
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004604/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004605testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004606 var TfiUsfArr tua := f_TfiUsfArrInit();
4607 var octetstring data := '0000'O & f_rnd_octstring(21);
4608
4609 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004610
Harald Welte883340c2018-02-28 18:59:29 +01004611 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004612 f_TfiUsfArrSet(tua, 7, 0);
4613 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4614 f_sleep(1.0);
4615
4616 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004617}
4618
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004619private function f_TC_pcu_ptcch_ul(uint16_t ra)
4620runs on test_CT {
4621 var template PCUIF_Message pcu_rach_ind;
4622 var PCUIF_send_data sd;
4623 var GsmFrameNumber fn;
4624 timer T;
4625
4626 /* Send an Access Burst on PTCCH/U over the Um-interface */
4627 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4628 chan_nr := ts_RslChanNr_PDCH(7),
4629 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4630
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004631 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4632 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004633
4634 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4635 T.start(52.0 * 4.615 / 1000.0);
4636 alt {
4637 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4638 log("Rx an Access Burst on the PCU interface: ", sd.data);
4639 setverdict(pass);
4640 T.stop;
4641 }
4642 [] PCU.receive { repeat; }
4643 [] T.timeout {
4644 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4645 /* Keep going, that's not the end of the world */
4646 }
4647 }
4648}
4649
4650testcase TC_pcu_ptcch() runs on test_CT {
4651 var L1ctlDlMessage dl;
4652 var octetstring data;
4653 timer T;
4654
4655 f_init_pcu_test();
4656 f_init_l1ctl();
4657 f_l1_tune(L1CTL);
4658
4659 /* Activate PDCH channel on TS7 */
4660 f_TC_pcu_act_req(0, 0, 7, true);
4661
4662 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004663 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004664 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4665 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004666 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004667
4668 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4669 for (var integer i := 0; i < 16; i := i + 1) {
4670 log("Sending an Access Burst towards the L1CTL interface");
4671 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4672 }
4673
4674 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4675 data := f_rnd_octstring(23);
4676
4677 /* Verify PTCCH/D: send a random data block, make sure it's received */
4678 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4679 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4680
4681 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4682 * let's give it more time in case if we miss the beginning. */
4683 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4684 alt {
4685 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4686 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4687 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4688 frame := data)) -> value dl {
4689 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4690 setverdict(pass);
4691 T.stop;
4692 }
4693 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4694 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4695 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4696 l2_data := data)) -> value dl {
4697 log("Rx PTCCH/D data block on L1CTL: ", dl);
4698 setverdict(pass);
4699 T.stop;
4700 }
4701 [] L1CTL.receive { repeat; }
4702 [] T.timeout {
4703 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4704 }
4705 }
4706}
4707
Harald Welte883340c2018-02-28 18:59:29 +01004708/* Send AGCH from PCU; check it appears on Um side */
4709testcase TC_pcu_data_req_agch() runs on test_CT {
4710 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004711 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004712 f_init_l1ctl();
4713 f_l1_tune(L1CTL);
4714
4715 f_TC_pcu_act_req(0, 0, 7, true);
4716 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4717
4718 T.start;
4719 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004720 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004721 setverdict(pass);
4722 }
4723 [] L1CTL.receive { repeat; }
4724 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004726 }
4727 }
4728}
4729
Harald Welte928622b2019-05-26 13:22:59 +02004730/* Send AGCH from PCU; check it appears on Um side */
4731testcase TC_pcu_data_req_pch() runs on test_CT {
4732 timer T := 3.0;
4733 f_init_pcu_test();
4734 f_init_l1ctl();
4735 f_l1_tune(L1CTL);
4736
4737 f_TC_pcu_act_req(0, 0, 7, true);
4738 /* three characters prefix: last 3 digits of IMSI as ASCII */
4739 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4740
4741 T.start;
4742 alt {
4743 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4744 setverdict(pass);
4745 }
4746 [] L1CTL.receive { repeat; }
4747 [] T.timeout {
4748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4749 }
4750 }
4751}
4752
Harald Welte883340c2018-02-28 18:59:29 +01004753/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4754testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4755 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004756 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004757 f_init_l1ctl();
4758 f_l1_tune(L1CTL);
4759
4760 /* append 3 last imsi digits so BTS can compute pagng group */
4761 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4762
4763 timer T := 0.5;
4764 T.start;
4765 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004766 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004767 /* TODO: verify paging group */
4768 setverdict(pass);
4769 }
4770 [] L1CTL.receive { repeat; }
4771 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004773 }
4774 }
4775}
4776
4777/* Send RACH from Um side, expect it to show up on PCU socket */
4778testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004779 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004780 f_init_l1ctl();
4781 f_l1_tune(L1CTL);
4782
4783 var GsmFrameNumber fn_last := 0;
4784 for (var integer i := 0; i < 1000; i := i+1) {
4785 var OCT1 ra := f_rnd_ra_ps();
4786 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4787 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004789 }
4790 fn_last := fn;
4791
4792 timer T := 2.0;
4793 T.start;
4794 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004795 [] 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 +01004796 T.stop;
4797 }
4798 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004800 }
4801 [] PCU.receive { repeat; }
4802 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004804 }
4805 }
4806 }
4807 setverdict(pass);
4808}
4809
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004810/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4811 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4812testcase TC_pcu_ext_rach_content() runs on test_CT {
4813 var template PCUIF_Message pcu_rach_ind;
4814 var GsmFrameNumber fn_last := 0;
4815 var L1ctlRachSynchSeq synch_seq;
4816 var PCUIF_BurstType pcu_bt;
4817 var GsmFrameNumber fn;
4818 var BIT11 ra11;
4819
4820 f_init_pcu_test();
4821 f_init_l1ctl();
4822 f_l1_tune(L1CTL);
4823
4824 for (var integer i := 0; i < 1000; i := i+1) {
4825 /* We need to test both TS1 & TS2 */
4826 if (i rem 2 == 0) {
4827 synch_seq := RACH_SYNCH_SEQ_TS1;
4828 pcu_bt := BURST_TYPE_1;
4829 } else {
4830 synch_seq := RACH_SYNCH_SEQ_TS2;
4831 pcu_bt := BURST_TYPE_2;
4832 }
4833
4834 ra11 := f_rnd_ra11_ps();
4835 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4836 if (fn == fn_last) {
4837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4838 "Two RACH in same FN?!?");
4839 }
4840 fn_last := fn;
4841
4842 /* Compose the expected message */
4843 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004844 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004845 ra := bit2int(ra11),
4846 is_11bit := 1,
4847 burst_type := pcu_bt,
4848 fn := fn);
4849
4850 timer T := 2.0;
4851 T.start;
4852 alt {
4853 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4854 T.stop;
4855 }
4856 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4858 }
4859 [] PCU.receive { repeat; }
4860 [] T.timeout {
4861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4862 }
4863 }
4864 }
4865 setverdict(pass);
4866}
4867
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004868private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4869runs on test_CT {
4870 var template PCUIF_send_data sdt;
4871 var PCUIF_send_data sd;
4872 var int16_t lqual_cb;
4873 timer T := 1.0;
4874
4875 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4876 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4877
4878 /* Send a random PDTCH frame over Um */
4879 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4880 '0000'O & f_rnd_octstring(21)));
4881
4882 T.start;
4883 alt {
4884 /* If expected link quality is above the threshold */
4885 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4886 lqual_cb := sd.data.u.data_ind.lqual_cb;
4887 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4888
4889 /* Make sure the actual link quality matches the expected value */
4890 if (not match(lqual_cb, lqual_cb_exp)) {
4891 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4892 "expected value ", lqual_cb_exp));
4893 } else {
4894 setverdict(pass);
4895 }
4896 }
4897 /* If expected link quality is below the threshold */
4898 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4900 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4901 }
4902 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4903 [] PCU.receive { repeat; }
4904 [lqual_cb_exp < thresh] T.timeout {
4905 log("Rx nothing, as expected");
4906 setverdict(pass);
4907 }
4908 [lqual_cb_exp >= thresh] T.timeout {
4909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4910 "Timeout waiting for PCUIF_DATA.ind");
4911 }
4912 }
4913}
4914
4915/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4916testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4917 f_init_pcu_test();
4918 PCU.clear;
4919
4920 f_init_l1ctl();
4921 f_l1_tune(L1CTL);
4922
4923 /* Activate a PDCH channel on TS7 */
4924 f_TC_pcu_act_req(0, 0, 7, true);
4925
4926 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004927 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004928 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4929 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004930 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004931
4932 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4933 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4934 var TrxcMessage ret;
4935
4936 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4937 valueof(ts_TRXC_FAKE_CI(i)));
4938
4939 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4940 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4941 }
4942}
4943
Harald Welte883340c2018-02-28 18:59:29 +01004944/* Send PAGING via RSL, expect it to shw up on PCU socket */
4945testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004946 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004947
4948 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004949 var MobileIdentityLV mi_lv;
4950 var octetstring mi_lv_enc;
4951 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004952 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004953
Harald Welte883340c2018-02-28 18:59:29 +01004954 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004955 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004956 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004957 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004958 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004959
4960 /* Fancy encoding for PCUIF */
4961 mi_lv := valueof(ts_MI_LV(mi));
4962 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4963 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004964
4965 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004966 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004967 T.start;
4968 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004969 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004970 }
4971 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004973 }
4974 [] PCU.receive { repeat; }
4975 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004977 }
4978 }
4979 }
4980 setverdict(pass);
4981}
4982
Harald Welted66c9b82019-05-25 09:03:15 +02004983/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4984testcase TC_pcu_time_ind() runs on test_CT {
4985 var PCUIF_send_data pcu_sd;
4986 var integer num_time_ind := 0;
4987 var integer first_fn, last_fn;
4988 var float test_duration := 5.0;
4989 timer T;
4990
4991 f_init_pcu_test();
4992 f_TC_pcu_act_req(0, 0, 7, true);
4993
4994 PCU.clear;
4995 T.start(test_duration);
4996 alt {
4997 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4998 num_time_ind := num_time_ind + 1;
4999 if (not isbound(first_fn)) {
5000 first_fn := pcu_sd.data.u.time_ind.fn;
5001 }
5002 last_fn := pcu_sd.data.u.time_ind.fn;
5003 repeat;
5004 }
5005 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5006 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5007 repeat;
5008 }
5009 [] PCU.receive {
5010 repeat;
5011 }
5012 [] T.timeout {}
5013 }
5014 var integer fn_expired := last_fn - first_fn;
5015 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5016
5017 /* verify the number of frames expired matches our expectation */
5018 const float c_GSM_FN_DURATION_MS := 4.61538;
5019 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005020 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005021 if (not match(fn_expired, t_fn_expected)) {
5022 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5023 }
5024
5025 /* There are three TIME.ind in every fn MOD 13 */
5026 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5027 /* Add some tolerance */
5028 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5029 if (not match(num_time_ind, t_time_ind_exp)) {
5030 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5031 }
5032
5033 setverdict(pass);
5034}
5035
Harald Welte4832c862019-05-25 14:57:18 +02005036/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5037testcase TC_pcu_rts_req() runs on test_CT {
5038 var PCUIF_send_data pcu_sd;
5039 var integer first_fn, last_fn;
5040 var integer num_rts_pdtch := 0;
5041 var integer num_rts_ptcch := 0;
5042 var float test_duration := 5.0;
5043 timer T;
5044
5045 f_init_pcu_test();
5046 f_TC_pcu_act_req(0, 0, 7, true);
5047
5048 PCU.clear;
5049 T.start(test_duration);
5050 alt {
5051 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5052 -> value pcu_sd {
5053 num_rts_pdtch := num_rts_pdtch + 1;
5054 if (not isbound(first_fn)) {
5055 first_fn := pcu_sd.data.u.rts_req.fn;
5056 }
5057 last_fn := pcu_sd.data.u.rts_req.fn;
5058 repeat;
5059 }
5060 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5061 -> value pcu_sd {
5062 num_rts_ptcch := num_rts_ptcch + 1;
5063 if (not isbound(first_fn)) {
5064 first_fn := pcu_sd.data.u.rts_req.fn;
5065 }
5066 last_fn := pcu_sd.data.u.rts_req.fn;
5067 repeat;
5068 }
5069 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5070 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5071 repeat;
5072 }
5073 [] PCU.receive {
5074 repeat;
5075 }
5076 [] T.timeout {}
5077 }
5078 var integer fn_expired := last_fn - first_fn;
5079 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5080 ", num_rts_ptcch=", num_rts_ptcch);
5081
5082 /* verify the number of frames expired matches our expectation */
5083 const float c_GSM_FN_DURATION_MS := 4.61538;
5084 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005085 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005086 if (not match(fn_expired, t_fn_expected)) {
5087 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5088 }
5089
5090 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5091 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5092 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5093 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5094 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5095 t_ptcch_exp);
5096 }
5097
5098 /* We have 12 PDTCH blocks every 52-multiframe */
5099 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5100 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5101 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5102 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5103 t_pdtch_exp);
5104 }
5105
5106 setverdict(pass);
5107}
5108
Harald Welte07bd2d22019-05-25 11:03:30 +02005109/* test for generating Abis side OML ALERT from the PCU */
5110testcase TC_pcu_oml_alert() runs on test_CT {
5111 var PCUIF_send_data pcu_sd;
5112 var integer num_time_ind := 0;
5113 var integer first_fn, last_fn;
5114 var float test_duration := 5.0;
5115 timer T;
5116
5117 f_init_pcu_test();
5118 f_TC_pcu_act_req(0, 0, 7, true);
5119
5120 /* re-connect CTRL port from BTS to BSC */
5121 f_ipa_ctrl_stop();
5122 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5123
5124 /* Send that OML Alert */
5125 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5126
5127 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5128 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5129 setverdict(pass);
5130}
5131
Harald Welteeaa9a862019-05-26 23:01:08 +02005132/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5133private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5134 var PCUIF_Message first_info;
5135 var integer pcu_conn_id := -1;
5136 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5137 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5138 var OCT4 tlli := '01020304'O;
5139 var OCT1 cause := '23'O;
5140 timer T := 5.0;
5141
5142 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5143
5144 f_l1_tune(L1CTL);
5145 RSL.clear;
5146
5147 f_est_dchan();
5148 L1CTL.clear;
5149
5150 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5151
5152 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5153 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5154 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5155
5156 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5157 T.start;
5158 alt {
5159 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5160 setverdict(pass);
5161 }
5162 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5163 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5164 }
5165 [] PCU.receive {
5166 repeat;
5167 }
5168 [] T.timeout {
5169 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5170 }
5171 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005172
5173 /* release the channel */
5174 f_rsl_chan_deact();
5175 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5176 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005177}
5178testcase TC_pcu_rr_suspend() runs on test_CT {
5179 var ConnHdlrPars pars;
5180 var ConnHdlr vc_conn;
5181
5182 f_init();
5183
5184 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5185 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5186 vc_conn.done;
5187}
Harald Welte07bd2d22019-05-25 11:03:30 +02005188
Harald Weltea2e0e942019-05-27 18:12:53 +02005189/* Ensure that PCUIF socket can accept only a single connection */
5190testcase TC_pcu_socket_connect_multi() runs on test_CT {
5191 timer T := 5.0;
5192
5193 /* this (among other things) establishes the first connection to the PCUIF socket */
5194 f_init();
5195
5196 /* try to establish a second connection, expect it to fail */
5197 PCU.send(UD_connect:{mp_pcu_socket, -1});
5198 T.start;
5199 alt {
5200 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5201 setverdict(pass);
5202 }
5203 [] PCU.receive(UD_connect_result:?) {
5204 setverdict(fail, "Unexpected unix domain connect result");
5205 }
5206 [] T.timeout {
5207 setverdict(pass);
5208 }
5209 }
5210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5211}
5212
Harald Weltec8effb72019-05-27 18:23:04 +02005213/* Ensure that PCUIF socket can disconnect + reconnect */
5214testcase TC_pcu_socket_reconnect() runs on test_CT {
5215 /* this (among other things) establishes the first connection to the PCUIF socket */
5216 f_init();
5217
5218 f_sleep(1.0);
5219
5220 f_pcuif_close(PCU, g_pcu_conn_id);
5221 g_pcu_conn_id := -1;
5222
5223 f_sleep(1.0);
5224
5225 /* re-connect */
5226 PCU.clear;
5227 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5228 setverdict(pass);
5229
5230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5231}
5232
Harald Weltebe030482019-05-27 22:29:35 +02005233/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005234private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5235runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005236 var L1ctlDlMessage l1_dl;
5237 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005238 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005239 timer T := 5.0;
5240 T.start;
5241 alt {
5242 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005243 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5244 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005245 repeat;
5246 }
5247 }
5248 [] pt.receive {
5249 repeat;
5250 }
5251 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5253 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005254 }
5255 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005256 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005257}
5258
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005259/* Check if GPRS Indicator is present in RR System Information of a given type */
5260private function f_si_has_gprs_indicator(RrMessageType si_type)
5261runs on test_CT return boolean {
5262 var SystemInformation si := f_get_si(L1CTL, si_type);
5263
5264 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005265 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005266 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005267 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005268 }
5269
5270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5271 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005272}
5273
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005274/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5275private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5276runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005277 /* don't call f_init() as this would connect PCU socket */
5278 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005279
5280 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005281 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005282 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005283
5284 f_init_l1ctl();
5285 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005286 f_sleep(2.0);
5287 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005288
5289 if (f_si_has_gprs_indicator(si_type)) {
5290 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005291 } else {
5292 setverdict(pass);
5293 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005294
Harald Weltebe030482019-05-27 22:29:35 +02005295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5296}
5297
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005298testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5299 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5300}
Harald Weltebe030482019-05-27 22:29:35 +02005301
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005302testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5303 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5304}
5305
5306/* Ensure that GPRS capability is advertised after PCU socket connect */
5307private function f_TC_pcu_socket_connect(RrMessageType si_type)
5308runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005309 /* this (among other things) establishes the first connection to the PCUIF socket */
5310 f_init();
5311 f_init_l1ctl();
5312 f_l1_tune(L1CTL);
5313
5314 f_sleep(2.0);
5315 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005316
5317 if (not f_si_has_gprs_indicator(si_type)) {
5318 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005319 } else {
5320 setverdict(pass);
5321 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005322
Harald Weltebe030482019-05-27 22:29:35 +02005323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5324}
5325
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005326testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5327 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5328}
Harald Weltebe030482019-05-27 22:29:35 +02005329
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005330testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5331 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5332}
5333
5334/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5335private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5336runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005337 /* this (among other things) establishes the first connection to the PCUIF socket */
5338 f_init();
5339 f_init_l1ctl();
5340 f_l1_tune(L1CTL);
5341
5342 f_pcuif_close(PCU, g_pcu_conn_id);
5343 g_pcu_conn_id := -1;
5344
5345 f_sleep(1.0);
5346
5347 /* re-connect */
5348 PCU.clear;
5349 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5350
5351 f_sleep(2.0);
5352 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005353
5354 if (f_si_has_gprs_indicator(si_type)) {
5355 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005356 } else {
5357 setverdict(pass);
5358 }
5359
5360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5361}
5362
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005363testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5364 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5365}
5366
5367testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5368 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5369}
5370
Oliver Smithf5239c72019-08-28 10:01:25 +02005371/* 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) */
5372testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5373 var SystemInformation si3 := valueof(ts_SI3_default);
5374
5375 f_init();
5376
5377 /* Verify cell_id */
5378 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5379 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5380 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005381 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5382 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5383 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005384 }
5385
5386 /* Verify LAC */
5387 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5388 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5389 if (lac_si3 != lac_pcu) {
5390 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5391 }
5392
5393 setverdict(pass);
5394}
Harald Welted66c9b82019-05-25 09:03:15 +02005395
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005396/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5397testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5398 var PCUIF_info_ind info_ind;
5399 var ConnHdlrPars pars;
5400
5401 f_init();
5402
5403 info_ind := g_pcu_last_info.u.info_ind;
5404
5405 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5406 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5407 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5408 /* Skip inactive timeslots */
5409 continue;
5410 }
5411
5412 pars := valueof(t_Pars(t_RslChanNr_PDCH(tn), ts_RSL_ChanMode_SIGN));
5413 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
5414 { f_resolve_fh_params(pars); }
5415
5416 var template PCUIF_InfoTrxTs tr_ts;
5417 if (ispresent(pars.maio_hsn)) {
5418 tr_ts := tr_PCUIF_InfoTrxTsH1(
5419 hsn := pars.maio_hsn.hsn,
5420 maio := pars.maio_hsn.maio,
5421 ma := f_pad_bit(pars.ma_map.ma, 64, '0'B));
5422 } else {
5423 tr_ts := tr_PCUIF_InfoTrxTsH0;
5424 }
5425
5426 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5427 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5428 if (not match(ts, tr_ts)) {
5429 setverdict(fail, "Hopping parameters do not match: ",
5430 "received ", ts, " vs expected ", tr_ts);
5431 } else {
5432 setverdict(pass);
5433 }
5434 }
5435 }
5436}
5437
Harald Welte3d04ae62018-04-04 20:29:05 +02005438/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005439 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005440 ***********************************************************************/
5441
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005442private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5443 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005444runs on ConnHdlr {
5445 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005446
5447 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005448 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005449 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5450 repeat;
5451 }
5452 }
5453}
5454
5455private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5456runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005457 /* Expect BTS to immediately acknowledge activation as PDCH */
5458 PCU.clear;
5459 f_rsl_chan_act(g_pars.chan_mode);
5460 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005461 timer T_wait := 2.0;
5462 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005463 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005464 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005465 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005466 [] T_wait.timeout {
5467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5468 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5469 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005470 }
5471 /* try to activate this PDCH from the PCU point of view */
5472 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5473 /* FIXME: is there a response? */
5474}
5475
5476private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5477runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005478 /* Send RSL CHAN REL (deactivate) */
5479 PCU.clear;
5480 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5481 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005482 timer T_wait := 2.0;
5483 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005484 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005485 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005486 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005487 [] T_wait.timeout {
5488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5489 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5490 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005491 }
5492 /* Emulate PCU asking BTS to deactivate PDCH */
5493 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5494 alt {
5495 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5496 setverdict(pass);
5497 }
5498 [] RSL.receive { repeat; }
5499 }
5500}
5501
5502/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005503private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005504 var PCUIF_Message first_info;
5505 var integer ts_nr := g_chan_nr.tn;
5506 var integer trx_nr := 0;
5507 var integer bts_nr := 0;
5508 var integer pcu_conn_id := -1;
5509
5510 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5511
5512 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5513 f_sleep(3.0);
5514 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5515 setverdict(pass);
5516}
5517testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5518 var ConnHdlrPars pars;
5519 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005520 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005521
5522 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5523 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5524 vc_conn.done;
5525}
5526
5527/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005528private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005529 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005530 var integer pcu_conn_id := -1;
5531
5532 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5533
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005534 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5535 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5536 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005537 setverdict(pass);
5538}
5539testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5540 var ConnHdlrPars pars;
5541 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005542 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005543
5544 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5545 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5546 vc_conn.done;
5547}
5548
5549/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005550private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005551 var PCUIF_Message first_info;
5552 var integer ts_nr := g_chan_nr.tn;
5553 var integer trx_nr := 0;
5554 var integer bts_nr := 0;
5555 var integer pcu_conn_id := -1;
5556
5557 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5558
5559 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005560 /* Send a second Chan Activ and expect it to be NACKed */
5561 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5562 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005563 setverdict(pass);
5564}
5565testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5566 var ConnHdlrPars pars;
5567 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005568 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005569
5570 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5571 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5572 vc_conn.done;
5573}
5574
5575/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005576private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005577 var PCUIF_Message first_info;
5578 var integer ts_nr := g_chan_nr.tn;
5579 var integer trx_nr := 0;
5580 var integer bts_nr := 0;
5581 var integer pcu_conn_id := -1;
5582 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5583
5584 /* register for the TCH/F channel number */
5585 f_rslem_register(0, chan_nr);
5586
5587 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5588
5589 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5590 "RSL CHAN ACT");
5591 setverdict(pass);
5592}
5593testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5594 var ConnHdlrPars pars;
5595 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005596 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005597
5598 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5599 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5600 vc_conn.done;
5601}
5602
5603/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005604private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005605 var PCUIF_Message first_info;
5606 var integer ts_nr := g_chan_nr.tn;
5607 var integer trx_nr := 0;
5608 var integer bts_nr := 0;
5609 var integer pcu_conn_id := -1;
5610 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5611 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5612
5613 /* register for the TCH/H channel numbers */
5614 f_rslem_register(0, chan_nr[0]);
5615 f_rslem_register(0, chan_nr[1]);
5616
5617 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5618
5619 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5620 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5621 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5622 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5623 setverdict(pass);
5624}
5625testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5626 var ConnHdlrPars pars;
5627 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005628 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005629
5630 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5631 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5632 vc_conn.done;
5633}
5634
Harald Welte9bbbfb52018-04-05 09:33:19 +02005635/***********************************************************************
5636 * IPA Style Dynamic Timeslot Support
5637 ***********************************************************************/
5638
5639private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5640runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005641 /* Expect BTS to immediately acknowledge activation as PDCH */
5642 PCU.clear;
5643 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5644 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005645 timer T_wait := 2.0;
5646 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005647 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005648 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005649 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005650 [] T_wait.timeout {
5651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5652 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5653 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005654 }
5655 /* try to activate this PDCH from the PCU point of view */
5656 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5657 /* FIXME: is there a response? */
5658
5659 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5660}
5661
5662private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5663runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005664 /* Send RSL CHAN REL (deactivate) */
5665 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5666 PCU.clear;
5667 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005668 timer T_wait := 2.0;
5669 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005670 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005671 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005672 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005673 [] T_wait.timeout {
5674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5675 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5676 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005677 }
5678 /* Emulate PCU asking BTS to deactivate PDCH */
5679 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5680 alt {
5681 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5682 setverdict(pass);
5683 }
5684 [] RSL.receive { repeat; }
5685 }
5686}
5687
5688/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005689private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005690 var PCUIF_Message first_info;
5691 var integer ts_nr := g_chan_nr.tn;
5692 var integer trx_nr := 0;
5693 var integer bts_nr := 0;
5694 var integer pcu_conn_id := -1;
5695
5696 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5697
5698 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5699 f_sleep(3.0);
5700 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5701
5702 setverdict(pass);
5703
5704}
5705testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5706 var ConnHdlrPars pars;
5707 var ConnHdlr vc_conn;
5708 f_init();
5709
5710 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5711 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5712 vc_conn.done;
5713}
5714
5715/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005716private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005717 var PCUIF_Message first_info;
5718 var integer ts_nr := g_chan_nr.tn;
5719 var integer trx_nr := 0;
5720 var integer bts_nr := 0;
5721 var integer pcu_conn_id := -1;
5722
5723 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5724
5725 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5726 "RSL CHAN ACT");
5727 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5728 "RF CHAN REL", true);
5729 setverdict(pass);
5730}
5731testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5732 var ConnHdlrPars pars;
5733 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005734 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005735
5736 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5737 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5738 vc_conn.done;
5739}
5740
5741/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005742private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005743 var PCUIF_Message first_info;
5744 var integer ts_nr := g_chan_nr.tn;
5745 var integer trx_nr := 0;
5746 var integer bts_nr := 0;
5747 var integer pcu_conn_id := -1;
5748
5749 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5750
5751 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5752 "RSL CHAN ACT");
5753
5754 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5755 alt {
5756 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5757 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005759 }
5760 [] RSL.receive { repeat; }
5761 }
5762
5763 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5764 "RF CHAN REL", true);
5765 setverdict(pass);
5766}
5767testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5768 var ConnHdlrPars pars;
5769 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005770 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005771
5772 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5773 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5774 vc_conn.done;
5775}
5776
5777/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005778private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005779 var PCUIF_Message first_info;
5780 var integer ts_nr := g_chan_nr.tn;
5781 var integer trx_nr := 0;
5782 var integer bts_nr := 0;
5783 var integer pcu_conn_id := -1;
5784
5785 /* register for the TCH/F channel number */
5786 f_rslem_register(0, g_chan_nr);
5787
5788 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5789
5790 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5791
5792 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5793 "RSL CHAN ACT");
5794
5795 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5796
5797 setverdict(pass);
5798}
5799testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5800 var ConnHdlrPars pars;
5801 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005802 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005803
5804 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5805 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5806 vc_conn.done;
5807}
5808
5809
Harald Welte0472ab42018-03-12 15:02:26 +01005810/***********************************************************************
5811 * LAPDm / RLL related
5812 ***********************************************************************/
5813
5814private function f_tx_lapdm(template (value) LapdmFrame l,
5815 template (value) RslLinkId link_id) runs on ConnHdlr {
5816 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005817 var template (value) SacchL1Header l1h;
5818
5819 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005820 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005821 /* Compose dummy L1 header */
5822 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5823 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 +02005824 } else {
5825 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005826 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 +01005827 }
Harald Welte0472ab42018-03-12 15:02:26 +01005828}
5829
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005830private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005831 uint3_t sapi,
5832 RslLinkId link_id,
5833 octetstring l3,
5834 boolean exp
5835}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005836private type record of RllTestCase RllTestCases;
5837private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5838 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005839 sapi := sapi,
5840 link_id := id,
5841 l3 := l3,
5842 exp := exp
5843}
5844
5845/* execute the same callback function with a set of different parameters (tcs) on a
5846 * variety of logical channels */
5847private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5848 var ConnHdlrPars pars;
5849 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005850 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005851
5852 /* test on each of the channels we have */
5853 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5854 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5855
5856 /* test each of the test cases on the current channel */
5857 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5858 pars.spec.rll := tcs[j];
5859 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5860 vc_conn := f_start_handler(fn, pars);
5861 vc_conn.done;
5862 }
5863 }
5864
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005866}
5867
5868/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5869private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5870 var RllTestCase tc := g_pars.spec.rll;
5871 timer T := 3.0;
5872
5873 f_l1_tune(L1CTL);
5874 RSL.clear;
5875
5876 /* activate the logical channel */
5877 f_est_dchan();
5878 L1CTL.clear;
5879
5880 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5881 T.start;
5882 alt {
5883 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5884 if (tc.exp) {
5885 setverdict(pass);
5886 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005888 }
5889 }
5890 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5891 if (tc.exp) {
5892 setverdict(pass);
5893 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005895 }
5896 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005897 /* We also expect to receive the measurements */
5898 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005899 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005901 }
5902 [not tc.exp] T.timeout {
5903 setverdict(pass);
5904 }
5905 }
5906
5907 f_rsl_chan_deact();
5908 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5909 f_rslem_unregister(0, g_chan_nr);
5910}
5911testcase TC_rll_est_ind() runs on test_CT {
5912 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005913 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005914 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005915 /* normal SAPI0 establishment */
5916 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005917 /* SAPI 3 doesn't support contention resolution */
5918 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5919 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5920 /* normal SAPI3 establishment on main DCCH */
5921 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5922 /* normal SAPI3 establishment on SACCH */
5923 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5924 };
5925 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5926}
5927
5928/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5929private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5930 var RllTestCase tc := g_pars.spec.rll;
5931 var L1ctlDlMessage dl;
5932 timer T := 3.0;
5933
5934 f_l1_tune(L1CTL);
5935 RSL.clear;
5936
5937 /* activate the logical channel */
5938 f_est_dchan();
5939 L1CTL.clear;
5940
5941 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5942 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5943 T.start;
5944 alt {
5945 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5946 var LapdmFrame lapdm;
5947 var octetstring l2 := dl.payload.data_ind.payload;
5948 if (dl.dl_info.link_id.c == SACCH) {
5949 /* remove L1 header */
5950 l2 := substr(l2, 2, lengthof(l2)-2);
5951 }
5952 lapdm.ab := dec_LapdmFrameAB(l2);
5953 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5954 setverdict(pass);
5955 } else {
5956 repeat;
5957 }
5958 }
5959 [] L1CTL.receive { repeat; }
5960 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005962 }
5963 }
5964
5965 f_rsl_chan_deact();
5966 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5967 f_rslem_unregister(0, g_chan_nr);
5968}
5969testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5970 var RllTestCases tcs := {
5971 /* normal SAPI3 establishment on main DCCH */
5972 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5973 };
5974 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5975}
5976testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5977 var RllTestCases tcs := {
5978 /* normal SAPI3 establishment on SACCH */
5979 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5980 }
5981 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5982}
5983
5984/* altstep to receive a LAPDm frame matching the given template */
5985private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5986 var L1ctlDlMessage dl;
5987 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5988 var LapdmFrame lapdm;
5989 var octetstring l2 := dl.payload.data_ind.payload;
5990 if (dl.dl_info.link_id.c == SACCH) {
5991 /* remove L1 header */
5992 l2 := substr(l2, 2, lengthof(l2)-2);
5993 }
5994 if (ischosen(exp.ab)) {
5995 lapdm.ab := dec_LapdmFrameAB(l2);
5996 } else if (ischosen(exp.b4)) {
5997 lapdm.b4 := dec_LapdmFrameB4(l2);
5998 } else if (ischosen(exp.bbis)) {
5999 lapdm.bbis := dec_LapdmFrameBbis(l2);
6000 }
6001 log("Rx LAPDm ", lapdm);
6002 if (match(lapdm, exp)) {
6003 setverdict(pass);
6004 } else {
6005 repeat;
6006 }
6007 }
6008 [] L1CTL.receive { repeat; }
6009}
6010private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6011 timer T := t;
6012 T.start;
6013 alt {
6014 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006016 }
6017 [] as_l1_exp_lapdm(exp);
6018 }
6019}
6020
6021/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6022private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6023 /* send SABM from MS -> BTS */
6024 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6025 /* expect RLL EST IND on Abis */
6026 alt {
6027 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6028 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6029 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006031 }
6032 [] RSL.receive { repeat; }
6033 }
6034 /* expect UA from BTS -> MS */
6035 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6036}
6037
6038/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6039private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6040 var RllTestCase tc := g_pars.spec.rll;
6041
6042 f_l1_tune(L1CTL);
6043 RSL.clear;
6044
6045 /* activate the logical channel */
6046 f_est_dchan();
6047 L1CTL.clear;
6048
6049 /* first establish the link-layer */
6050 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6051
6052 /* then send the DISC */
6053 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6054 /* ... and expect the REL IND on the RSL side */
6055 alt {
6056 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6057 setverdict(pass);
6058 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006059 /* We also expect to receive the measurements */
6060 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006061 }
6062
6063 /* release the channel */
6064 f_rsl_chan_deact();
6065 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6066 f_rslem_unregister(0, g_chan_nr);
6067}
6068testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6069 var RllTestCases tcs := {
6070 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6071 };
6072 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6073}
6074
6075testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6076 var RllTestCases tcs := {
6077 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6078 };
6079 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6080}
6081testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6082 var RllTestCases tcs := {
6083 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6084 };
6085 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6086}
6087testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6088 var RllTestCases tcs := {
6089 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6090 };
6091 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6092}
6093
6094/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6095private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6096 var RllTestCase tc := g_pars.spec.rll;
6097 f_l1_tune(L1CTL);
6098 RSL.clear;
6099
6100 /* activate the logical channel */
6101 f_est_dchan();
6102 L1CTL.clear;
6103
6104 /* first establish the link-layer */
6105 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6106
6107 /* then send the REL REQ via RSL */
6108 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6109 /* ... and expect the DISC on the Um side */
6110 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006111 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006112 /* FIXME: send a UA in resposne to the DISC */
6113 }
6114 }
6115
6116 /* release the channel */
6117 f_rsl_chan_deact();
6118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6119 f_rslem_unregister(0, g_chan_nr);
6120}
6121testcase TC_rll_rel_req() runs on test_CT {
6122 var RllTestCases tcs := {
6123 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6124 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6125 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6126 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6127 };
6128 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6129}
6130
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006131/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006132testcase TC_rll_data_req() runs on test_CT {
6133}
6134
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006135/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006136testcase TC_rll_data_ind() runs on test_CT {
6137}
6138
6139/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6140private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6141 var RllTestCase tc := g_pars.spec.rll;
6142
6143 f_l1_tune(L1CTL);
6144 RSL.clear;
6145
6146 f_est_dchan();
6147 L1CTL.clear;
6148
6149 /* Send UNITDATA REQ on RSL side */
6150 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6151 /* Expect it to arrive on the other side */
6152 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006153 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006154 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006155 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006156 }
6157
6158 /* release the channel */
6159 f_rsl_chan_deact();
6160 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6161 f_rslem_unregister(0, g_chan_nr);
6162}
6163testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6164 var octetstring l3 := f_rnd_octstring(15);
6165 var RllTestCases tcs := {
6166 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6167 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6168 };
6169 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6170}
6171testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6172 var octetstring l3 := f_rnd_octstring(19);
6173 var RllTestCases tcs := {
6174 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6175 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6176 };
6177 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6178}
6179
6180/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6181private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6182 var RllTestCase tc := g_pars.spec.rll;
6183
6184 f_l1_tune(L1CTL);
6185 RSL.clear;
6186
6187 f_est_dchan();
6188 L1CTL.clear;
6189
6190 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006191 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006192 /* Expdct RLL UNITDATA IND on RSL side */
6193 alt {
6194 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6195 setverdict(pass);
6196 }
6197 [] RSL.receive { repeat; }
6198 }
6199
6200 /* release the channel */
6201 f_rsl_chan_deact();
6202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6203 f_rslem_unregister(0, g_chan_nr);
6204}
6205testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006206 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006207 var RllTestCases tcs := {
6208 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6209 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6210 };
6211 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6212}
6213testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6214 var octetstring l3 := f_rnd_octstring(18);
6215 var RllTestCases tcs := {
6216 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6217 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6218 };
6219 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6220}
6221
Harald Weltee613f962018-04-18 22:38:16 +02006222/***********************************************************************
6223 * Encryption Related
6224 ***********************************************************************/
6225
6226/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006227private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006228 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6229 if (link_id.c == SACCH) {
6230 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6231 } else {
6232 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6233 }
6234}
6235
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006236/* Expect (or not expect) other kinds of messages */
6237private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6238 [exp_any] RSL.receive { repeat; }
6239 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006241 }
6242}
6243
Harald Weltee613f962018-04-18 22:38:16 +02006244/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006245private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006246 RslLinkId link_id,
6247 octetstring l3,
6248 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006249 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006250) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006251 timer T := 3.0;
6252 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6253 T.start;
6254 /* Expect RLL UNITDATA IND on RSL side */
6255 alt {
6256 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6257 setverdict(pass);
6258 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006259 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006260 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006261 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006263 }
Harald Weltee613f962018-04-18 22:38:16 +02006264 }
6265}
6266
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006267/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6268private function f_data_mo(
6269 RslLinkId link_id,
6270 boolean p, uint3_t nr, uint3_t ns,
6271 octetstring l3,
6272 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006273 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006274) runs on ConnHdlr {
6275 timer T := 3.0;
6276 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6277 T.start;
6278 /* Expect RLL DATA IND on RSL side */
6279 alt {
6280 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6281 setverdict(pass);
6282 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006283 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006284 [] as_rsl_any_ind(exp_any);
6285 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006287 }
6288 }
6289}
6290
Harald Weltee613f962018-04-18 22:38:16 +02006291/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006292private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006293 f_l1_tune(L1CTL);
6294 f_est_dchan(true);
6295
6296 /* now we actually need to transmit some data both ways to check if the encryption works */
6297 var L1ctlDlMessage dl;
6298
Stefan Sperling603d98e2018-07-25 16:47:28 +02006299 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006300 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6301
6302 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6303 f_unitdata_mt(link_id, l3);
6304
6305 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6306 f_unitdata_mo(link_id, l3);
6307
6308 /* release the channel */
6309 f_rsl_chan_deact();
6310 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6311 f_rslem_unregister(0, g_chan_nr);
6312}
6313testcase TC_chan_act_a51() runs on test_CT {
6314 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6315 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6316 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6317}
6318testcase TC_chan_act_a52() runs on test_CT {
6319 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6320 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6321 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6322}
6323testcase TC_chan_act_a53() runs on test_CT {
6324 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6325 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6326 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6327}
6328
Eric Wildf1827a72019-05-28 17:37:35 +02006329/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6330 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006331private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006332 f_l1_tune(L1CTL);
6333 f_est_dchan(true);
6334
6335 /* now we actually need to transmit some data both ways to check if the encryption works */
6336 var L1ctlDlMessage dl;
6337
6338 var octetstring l3 := f_rnd_octstring(20);
6339 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6340
6341 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6342 f_unitdata_mt(link_id, l3);
6343
6344 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6345 f_unitdata_mo(link_id, l3);
6346
6347 var RSL_Message rsl;
6348 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6349
6350 /* modify key to break proper encryption */
6351 g_pars.encr.key := f_rnd_octstring(8);
6352 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6353 rsl.ies := rsl.ies & { ei };
6354 RSL.send(rsl);
6355
6356 timer T0 := 1.0;
6357 T0.start;
6358 /* Expect RSL MODIFY ACK */
6359 alt {
6360 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6361 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6363 }
6364 [] T0.timeout {
6365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6366 }
6367 }
6368
6369 var octetstring l3msg := f_rnd_octstring(15);
6370 timer T1 := 3.0;
6371 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6372 due to broken encryption */
6373 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6374 T1.start;
6375 alt {
6376 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6378 }
6379 [] T1.timeout {
6380 setverdict(pass);
6381 }
6382 }
6383
6384 /* release the channel */
6385 f_rsl_chan_deact();
6386 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6387 f_rslem_unregister(0, g_chan_nr);
6388}
6389testcase TC_rsl_modify_encr() runs on test_CT {
6390 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6391 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6392 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6393}
Harald Weltee613f962018-04-18 22:38:16 +02006394
6395/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006396private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006397 /* L3 payload doesn't matter, as it is passed transparently */
6398 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6399 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6400 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6401
6402 f_l1_tune(L1CTL);
6403
6404 /* first establish a dedicated channel in the clear */
6405 f_est_dchan(false);
6406
6407 /* Establish ABM */
6408 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6409
6410 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6411 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6412 /* expect the L3 to arrive still unencrypted on the MS side */
6413 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6414
6415 /* configure L1 to apply ciphering */
6416 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6417 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6418
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006419 /* send first ciphered I-frame in response and expect it on RSL */
6420 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006421
6422 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6423 * and hence enable encryption also on the downlink */
6424
6425 /* expect bi-directional communication work in encrypted mode */
6426 f_unitdata_mo(link_id, f_rnd_octstring(15));
6427 f_unitdata_mt(link_id, f_rnd_octstring(15));
6428
6429 /* release the channel */
6430 f_rsl_chan_deact();
6431 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6432 f_rslem_unregister(0, g_chan_nr);
6433}
6434testcase TC_encr_cmd_a51() runs on test_CT {
6435 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6436 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6437 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6438}
6439testcase TC_encr_cmd_a52() runs on test_CT {
6440 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6441 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6442 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6443}
6444testcase TC_encr_cmd_a53() runs on test_CT {
6445 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6446 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6447 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6448}
6449
6450private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6451 var LapdmFrame lf;
6452 var octetstring reenc;
6453
6454 /* decode the LAPDm frame */
6455 if (ischosen(exp_match.ab)) {
6456 lf.ab := dec_LapdmFrameAB(enc);
6457 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006459 }
6460
6461 /* check if decoder result matches expectation */
6462 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006464 } else {
6465 log(name, ": matched");
6466 setverdict(pass);
6467 }
6468
6469 /* test if re-encoded frame equals original input */
6470 reenc := enc_LapdmFrame(lf);
6471 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006473 } else {
6474 setverdict(pass);
6475 }
6476}
6477
6478testcase TC_lapdm_selftest() runs on test_CT {
6479 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6480 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6481 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6482 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6483 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6484 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6485 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6486}
6487
Stefan Sperling4880be42018-08-07 18:12:59 +02006488/***********************************************************************
6489 * DTX Related (see GSM 05.08, section 8.3)
6490 ***********************************************************************/
6491
6492/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006493private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006494 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6495 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6496 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6497 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6498}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006499private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006500 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6501 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6502}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006503private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006504 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6505 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6506 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6507 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6508}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006509private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006510 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6511 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6512 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6513 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6514 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6515 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6516 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6517 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6518}
6519
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006520private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006521 var L1ctlDlMessage dl;
6522 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6523 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6524 var GsmFrameNumber first_fn;
6525 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006526 var integer nfill_frames_sacch := 0;
6527 var integer nfill_frames_nonsacch := 0;
6528 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006529 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6530 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006531 const integer frame_dtx_tchf_mod := 104;
6532 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6533 * which operates in terms of blocks rather than frames. */
6534 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6535 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006536 timer T := 5.0;
6537
6538 f_l1_tune(L1CTL);
6539 RSL.clear;
6540 L1CTL.clear;
6541
6542 /* activate TCHF signalling channel */
6543 f_est_dchan(false);
6544
6545 T.start;
6546 alt {
6547 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6548 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6549 var octetstring l2 := dl.payload.data_ind.payload;
6550
6551 if (is_first_frame) {
6552 is_first_frame := false;
6553 first_fn := dl.dl_info.frame_nr;
6554 }
6555
6556 if (dl.dl_info.link_id.c == SACCH) {
6557 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6558 if (not match(l2_fill_frame_sacch, l2)) {
6559 repeat;
6560 }
6561 } else if (not match(l2_fill_frame, l2)) {
6562 repeat;
6563 }
6564
6565 if (dtxd) {
6566 if (not f_g_chan_is_tchf()) {
6567 T.stop;
6568 f_rsl_chan_deact();
6569 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006570 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 +02006571 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006572 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006573 T.stop;
6574 f_rsl_chan_deact();
6575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006576
6577 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6578 * 2 SACCH, 1 TCH/F */
6579 expected_fill_frames := 3;
6580
6581 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6582 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6583 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006585 } else {
6586 setverdict(pass);
6587 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006588 } else {
6589 if (dl.dl_info.link_id.c == SACCH) {
6590 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006591 repeat;
6592 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006593 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6594 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6595 * we should only see the subset of frames numbers which correspond to a block boundary.
6596 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6597 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6598 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6599 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6600 repeat;
6601 }
6602 }
6603 log("Received DTX TCH fill frame with bad frame number: ", fn,
6604 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6605 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6606 f_rsl_chan_deact();
6607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006609 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006610 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006611 if (dl.dl_info.link_id.c == SACCH) {
6612 nfill_frames_sacch := nfill_frames_sacch + 1;
6613 } else {
6614 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6615 }
6616 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006617 T.stop;
6618 if (f_g_chan_is_tchf()) {
6619 /* Without DTX we can expect 25 fill frames for every 104 frames.
6620 * (24 FACCH + 1 SACCH filling) */
6621 expected_fill_frames := 25;
6622 } else if (f_g_chan_is_tchh()) {
6623 /* We can expect 2 fill frames for every 104 frames. */
6624 expected_fill_frames := 2;
6625 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6626 /* We can expect 5 fill frames for every 104 frames. */
6627 expected_fill_frames := 5;
6628 } else {
6629 f_rsl_chan_deact();
6630 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006632 }
6633
6634 f_rsl_chan_deact();
6635 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006636
6637 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006638 setverdict(pass);
6639 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006640 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6641 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006643 }
6644 } else {
6645 repeat;
6646 }
6647 }
6648 }
6649 [] L1CTL.receive { repeat; }
6650 [] T.timeout {
6651 f_rsl_chan_deact();
6652 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006654 }
6655 }
6656}
6657
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006658private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006659 f_test_l2_fill_frames(false);
6660}
6661
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006662private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006663 f_test_l2_fill_frames(true);
6664}
6665
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006666private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006667 var ConnHdlr vc_conn;
6668 var ConnHdlrPars pars;
6669 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006670 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006671 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6672 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6673 if (dtxd) {
6674 if (i >= 4) { /* DTX is only allowed on TCH/F */
6675 break;
6676 }
6677 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6678 } else {
6679 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6680 }
6681 vc_conn.done;
6682 }
6683}
6684
6685/* Verify that L2 fill frames are sent on TCH in signaling mode if
6686 * there is nothing to transmit while DTX is disabled on downlink. */
6687testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6688 f_tch_sign_l2_fill_frame(false);
6689}
6690
6691/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6692 * there is nothing to transmit while DTX is enabled on downlink. */
6693testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6694 f_tch_sign_l2_fill_frame(true);
6695}
Harald Welte0472ab42018-03-12 15:02:26 +01006696
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006697testcase TC_chopped_ipa_ping() runs on test_CT {
6698 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6699}
6700
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006701testcase TC_chopped_ipa_payload() runs on test_CT {
6702 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6703}
6704
Harald Welte0472ab42018-03-12 15:02:26 +01006705/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6706/* protocol error as per 44.006 */
6707/* link layer failure (repetition of I-frame N200 times without ACK */
6708/* repetition of SABM or DISC N200 times without ACK */
6709/* receptiom of SABM in multi-frame established state */
6710
6711
Harald Welte68e495b2018-02-25 00:05:57 +01006712/* TODO Areas:
6713
6714* channel activation
6715** with BS_Power / MS_Power, bypassing power control loop
6716** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006717** with timing advance from initial activation on
6718* mode modify
6719** encryption
6720** multirate
6721* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006722** unsupported algorithm
6723* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006724* BS Power Control
6725* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006726* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006727* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006728** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006729* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006730** DATA_IND from BTS->PCU
6731** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006732
6733*/
Harald Welte70767382018-02-21 12:16:40 +01006734
6735control {
6736 execute( TC_chan_act_stress() );
6737 execute( TC_chan_act_react() );
6738 execute( TC_chan_deact_not_active() );
6739 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006740 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006741 execute( TC_sacch_filling() );
6742 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006743 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006744 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006745 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006746 execute( TC_sacch_chan_act_ho_async() );
6747 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006748 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006749 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006750 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006751 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006752 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006753 execute( TC_rach_load_idle_thresh0() );
6754 execute( TC_rach_load_idle_below_thresh() );
6755 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006756 execute( TC_meas_res_sign_tchf() );
6757 execute( TC_meas_res_sign_tchh() );
6758 execute( TC_meas_res_sign_sdcch4() );
6759 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006760 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006761 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006762 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006763 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006764 execute( TC_rsl_bs_pwr_static_ass() );
6765 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006766 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006767 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006768 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006769 execute( TC_rsl_ms_pwr_dyn_up() );
6770 execute( TC_rsl_ms_pwr_dyn_down() );
6771 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6772 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006773 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006774 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006775 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006776 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006777 execute( TC_paging_imsi_80percent() );
6778 execute( TC_paging_tmsi_80percent() );
6779 execute( TC_paging_imsi_200percent() );
6780 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006781 execute( TC_rsl_protocol_error() );
6782 execute( TC_rsl_mand_ie_error() );
6783 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006784 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006785 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006786 execute( TC_si_sched_2bis() );
6787 execute( TC_si_sched_2ter() );
6788 execute( TC_si_sched_2ter_2bis() );
6789 execute( TC_si_sched_2quater() );
6790 execute( TC_si_sched_13() );
6791 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006792 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006793 execute( TC_ipa_crcx_twice_not_active() );
6794 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006795 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006796 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006797
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006798 if (mp_pcu_socket != "") {
6799 execute( TC_pcu_act_req() );
6800 execute( TC_pcu_act_req_wrong_ts() );
6801 execute( TC_pcu_act_req_wrong_bts() );
6802 execute( TC_pcu_act_req_wrong_trx() );
6803 execute( TC_pcu_deact_req() );
6804 execute( TC_pcu_deact_req_wrong_ts() );
6805 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006806 if (mp_l1_supports_gprs) {
6807 execute( TC_pcu_data_req_pdtch() );
6808 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006809 execute( TC_pcu_data_req_wrong_bts() );
6810 execute( TC_pcu_data_req_wrong_trx() );
6811 execute( TC_pcu_data_req_wrong_ts() );
6812 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006813 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006814 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006815 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006816 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006817 execute( TC_pcu_data_req_imm_ass_pch() );
6818 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006819 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006820 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006821 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006822 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006823 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006824 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006825 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006826 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006827 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006828 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006829 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006830 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006831 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006832 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006833 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006834 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006835 execute( TC_dyn_osmo_pdch_act_deact() );
6836 execute( TC_dyn_osmo_pdch_double_act() );
6837 execute( TC_dyn_ipa_pdch_act_deact() );
6838 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6839
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006840 if (PCUIF_Types.mp_pcuif_version >= 10) {
6841 execute( TC_pcu_info_ind_fh_params() );
6842 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006843 } else {
6844 log("PCU socket path not available, skipping PCU tests");
6845 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006846
Harald Welte3d04ae62018-04-04 20:29:05 +02006847 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006848 execute( TC_dyn_osmo_pdch_tchf_act() );
6849 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006850 execute( TC_dyn_ipa_pdch_tchf_act() );
6851 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006852
6853 execute( TC_rll_est_ind() );
6854 execute( TC_rll_est_req_DCCH_3() );
6855 execute( TC_rll_est_req_ACCH_3() );
6856 execute( TC_rll_rel_ind_DCCH_0() );
6857 execute( TC_rll_rel_ind_DCCH_3() );
6858 execute( TC_rll_rel_ind_ACCH_0() );
6859 execute( TC_rll_rel_ind_ACCH_3() );
6860 execute( TC_rll_rel_req() );
6861 execute( TC_rll_unit_data_req_DCCH() );
6862 execute( TC_rll_unit_data_req_ACCH() );
6863 execute( TC_rll_unit_data_ind_DCCH() );
6864 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006865
6866 execute( TC_chan_act_a51() );
6867 execute( TC_chan_act_a52() );
6868 execute( TC_chan_act_a53() );
6869 execute( TC_encr_cmd_a51() );
6870 execute( TC_encr_cmd_a52() );
6871 execute( TC_encr_cmd_a53() );
6872
Harald Welteee25aae2019-05-19 14:32:37 +02006873 execute( TC_err_rep_wrong_mdisc() );
6874 execute( TC_err_rep_wrong_msg_type() );
6875 execute( TC_err_rep_wrong_sequence() );
6876
Harald Weltee613f962018-04-18 22:38:16 +02006877 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006878
6879 execute( TC_tch_sign_l2_fill_frame() );
6880 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006881
6882 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006883 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006884}
6885
6886
6887}