blob: 34fd7028293c10b8eb417cd7f46bbbc5b411793e [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/* like L1SAP_IS_PACKET_RACH */
1352private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001353 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001354 return true;
1355 }
1356 return false;
1357}
1358
Philipp Maier16ade782020-07-08 21:36:00 +02001359private function ra_is_emerg(OCT1 ra) return boolean {
1360 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1361 if ((ra and4b 'E0'O == 'A0'O) and (ra and4b '1F'O != '1F'O)) {
1362 return true;
1363 }
1364 return false;
1365}
1366
Harald Welte8c24c2b2018-02-26 08:31:31 +01001367/* generate a random RACH for circuit-switched */
1368private function f_rnd_ra_cs() return OCT1 {
1369 var OCT1 ra;
1370 do {
1371 ra := f_rnd_octstring(1);
1372 } while (ra_is_ps(ra));
1373 return ra;
1374}
1375
Philipp Maier16ade782020-07-08 21:36:00 +02001376/* generate a random RACH for emergency */
1377private function f_rnd_ra_emerg() return OCT1 {
1378 var OCT1 ra;
1379 do {
1380 ra := f_rnd_octstring(1);
1381 } while (not ra_is_emerg(ra));
1382 return ra;
1383}
1384
Harald Welte883340c2018-02-28 18:59:29 +01001385/* generate a random RACH for packet-switched */
1386private function f_rnd_ra_ps() return OCT1 {
1387 var OCT1 ra;
1388 do {
1389 ra := f_rnd_octstring(1);
1390 } while (not ra_is_ps(ra));
1391 return ra;
1392}
1393
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001394/* generate a random 11-bit RA (packet-switched only) */
1395private function f_rnd_ra11_ps() return BIT11 {
1396 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1397 return int2bit(ra11, 11);
1398}
1399
Harald Welte8c24c2b2018-02-26 08:31:31 +01001400/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001401private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001402 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001403 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001404 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001405
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001407 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001409 var OCT1 ra := f_rnd_ra_emerg();
1410 if (emerg == true) {
1411 ra := f_rnd_ra_emerg();
1412 } else {
1413 ra := f_rnd_ra_cs();
1414 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001415 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 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001422 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001423 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001424 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001425 T.stop;
1426 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001427 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001429 }
1430 [] RSL_CCHAN.receive { repeat; }
1431 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001432 test_failed := true;
1433 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001434 }
1435 }
1436 }
Maxba06feb2019-03-05 10:52:46 +01001437 if (test_failed) {
1438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001439 }
Maxba06feb2019-03-05 10:52:46 +01001440 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001442}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001443
Philipp Maier16ade782020-07-08 21:36:00 +02001444/* Normal variant */
1445testcase TC_rach_content() runs on test_CT {
1446 f_TC_rach_content(emerg := false);
1447}
1448
1449/* Emergency call variant */
1450testcase TC_rach_content_emerg() runs on test_CT {
1451 f_TC_rach_content(emerg := true);
1452}
1453
Harald Welte8c24c2b2018-02-26 08:31:31 +01001454/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1455testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001456 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001457 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001458 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 f_l1_tune(L1CTL);
1460
1461 var GsmFrameNumber fn_last := 0;
1462 for (var integer i := 0; i < 1000; i := i+1) {
1463 var OCT1 ra := f_rnd_ra_cs();
1464 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1465 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001467 }
1468 fn_last := fn;
1469 }
1470 var integer rsl_chrqd := 0;
1471 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001472 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001473 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001474 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001475 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001476 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001477 repeat;
1478 }
1479 [] RSL_CCHAN.receive { repeat; }
1480 [] T.timeout { }
1481 }
1482 if (rsl_chrqd == 1000) {
1483 setverdict(pass);
1484 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001486 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001488}
1489
Harald Welte3453ab42019-05-24 21:19:58 +02001490private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1491 var charstring bts_str := "bts " & int2str(bts_nr);
1492 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1493}
1494
1495/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1496private template integer tr_rach_slots_per_interval := (90 .. 130);
1497
1498/* Expect 0 RACH load on an idle BTS that has just started up */
1499testcase TC_rach_load_idle_thresh0() runs on test_CT {
1500 var ASP_RSL_Unitdata rx_ud;
1501
1502 f_init_vty_bsc();
1503 /* send load indications even at 0% load */
1504 f_vty_load_ind_thresh(0);
1505 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1506 f_sleep(2.0);
1507
1508 f_init();
1509
1510 timer T := 5.0;
1511 T.start;
1512 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001513 [] 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 +02001514 setverdict(pass);
1515 repeat;
1516 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001517 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001518 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1519 repeat;
1520 }
1521 [] RSL_CCHAN.receive {
1522 repeat;
1523 }
1524 [] T.timeout { }
1525 }
1526
1527 f_vty_load_ind_thresh(10);
1528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1529}
1530
1531/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1532testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1533 var ASP_RSL_Unitdata rx_ud;
1534
1535 f_init_vty_bsc();
1536 f_init();
1537
1538 timer T := 5.0;
1539 T.start;
1540 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001541 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001542 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1543 repeat;
1544 }
1545 [] RSL_CCHAN.receive {
1546 repeat;
1547 }
1548 [] T.timeout {
1549 setverdict(pass);
1550 }
1551 }
1552
1553 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1554}
1555
1556/* Expect 0 RACH load on an idle BTS that has just started up */
1557testcase TC_rach_load_count() runs on test_CT {
1558 var ASP_RSL_Unitdata rx_ud;
1559 var integer load_access_count := 0;
1560
1561 f_init_vty_bsc();
1562 /* send load indications even at 0% load */
1563 f_vty_load_ind_thresh(0);
1564 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1565 f_sleep(2.0);
1566 f_init();
1567
1568 f_init_l1ctl();
1569 f_sleep(1.0);
1570 f_l1_tune(L1CTL);
1571
1572 var GsmFrameNumber fn_last := 0;
1573 for (var integer i := 0; i < 1000; i := i+1) {
1574 var OCT1 ra := f_rnd_ra_cs();
1575 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1576 if (fn == fn_last) {
1577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1578 }
1579 fn_last := fn;
1580 }
1581
1582 timer T := 5.0;
1583 T.start;
1584 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001585 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001586 -> value rx_ud {
1587 var RSL_IE_Body ie;
1588 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1589 load_access_count := load_access_count + ie.rach_load.access_count;
1590 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1591 setverdict(fail, "Access count cannot be < Busy count");
1592 }
1593 repeat;
1594 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001595 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001596 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1597 repeat;
1598 }
1599 [] RSL_CCHAN.receive {
1600 repeat;
1601 }
1602 [] T.timeout { }
1603 }
1604 if (load_access_count == 1000) {
1605 setverdict(pass);
1606 } else {
1607 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1608 }
1609
1610 f_vty_load_ind_thresh(10);
1611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1612}
1613
Harald Welte54a2a2d2018-02-26 09:14:05 +01001614private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001615 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001616 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001617 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001618 f_sleep(0.5);
1619
1620 /* Transmit RACH request + wait for confirmation */
1621 var OCT1 ra := f_rnd_ra_cs();
1622 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1623
1624 /* Check for expected result */
1625 timer T := 1.5;
1626 T.start;
1627 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001628 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001629 setverdict(pass);
1630 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001631 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001633 }
1634 [] RSL_CCHAN.receive { repeat; }
1635 [not expect_pass] T.timeout {
1636 setverdict(pass);
1637 }
1638 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001640 }
1641 }
1642}
1643
1644/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1645testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001646 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001647 f_init_l1ctl();
1648 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001649 f_sleep(1.0);
1650
1651 /* default max-ta is 63 (full range of GSM timing advance */
1652
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001653 /* We allow early arrival up to 2 symbols */
1654 f_rach_toffs(-1*256, true);
1655 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001656 f_rach_toffs(-10*256, false);
1657
1658 /* 0 / 32 / 63 bits is legal / permitted */
1659 f_rach_toffs(0, true);
1660 f_rach_toffs(32*256, true);
1661 f_rach_toffs(63*256, true);
1662
1663 /* more than 63 bits is not legal / permitted */
1664 f_rach_toffs(64*256, false);
1665 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001667}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001668
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001669private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001670 var GsmFrameNumber fn;
1671 var RSL_Message rm;
1672
1673 f_l1_tune(L1CTL);
1674 RSL.clear;
1675
1676 /* Generate a random Handover Reference */
1677 var integer ho_ref := oct2int(f_rnd_octstring(1));
1678
1679 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1680 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1681 RSL_IE_Body:{ handover_ref := ho_ref }));
1682
1683 /* Activate a channel on the BTS side (no encryption) */
1684 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1685 act_type := t_RSL_IE_ActType_HO_SYNC);
1686
1687 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1688 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001689 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001690
1691 /* Send handover Access Burst */
1692 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1693
1694 /* TODO: test mismatching Handover Reference, and missing IE */
1695
1696 /* Wait for handover detection */
1697 timer T := 3.0;
1698 T.start;
1699 alt {
1700 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1701 log("Handover RACH has been detected: ", rm);
1702 setverdict(pass);
1703 }
1704 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1706 log2str("RSL_CHAN_RQD was not expected: ", rm));
1707 }
1708 [] RSL.receive { repeat; }
1709 [] T.timeout {
1710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1711 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1712 }
1713 }
1714
1715 /* Release the channel */
1716 f_rsl_chan_deact();
1717 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1718}
1719
1720/* Test handover RACH detection */
1721testcase TC_ho_rach() runs on test_CT {
1722 var ConnHdlrPars pars;
1723 var ConnHdlr vc_conn;
1724
1725 f_init();
1726
1727 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1728 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1729 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1730 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1731 vc_conn.done;
1732 }
1733
1734 /* TODO: do the above in parallel, rather than sequentially? */
1735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1736}
1737
Harald Welte93640c62018-02-25 16:59:33 +01001738/***********************************************************************
1739 * Measurement Processing / Reporting
1740 ***********************************************************************/
1741
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001742private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001743 spare := '0'B,
1744 lpd := 0,
1745 sapi := sapi,
1746 c_r := c_r,
1747 ea := true
1748}
1749
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001750private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001751 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001752 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001753 len := 0, /* overwritten */
1754 m := false,
1755 el := 1,
1756 payload := pl
1757}
1758
1759/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001760private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001761 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001762 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001763 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001764 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 +01001765 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001766 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001767
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001768 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1769 g_pars.l1_pars.ms_power_level, false,
1770 g_pars.l1_pars.ms_actual_ta);
1771
1772 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1773 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1774
1775 log("Sending Measurement Report: ", l1h, l2);
1776 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001777 repeat;
1778 }
1779}
1780
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001781private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001782 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001783 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001784 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1785 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001786 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1787 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001788 repeat;
1789 }
1790}
1791
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001792private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001793 uint6_t rxlev,
1794 uint3_t rxqual
1795}
1796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001797private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001798 MeasElem full,
1799 MeasElem sub
1800}
1801
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001802private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001803 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001804 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001805 MeasElemFS meas_ul,
1806 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001807 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001808 uint5_t ms_power_level,
1809 uint8_t ms_actual_ta
1810}
1811
1812/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1813private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1814 return 63 + (toffs256s/256);
1815}
1816
Harald Welted5684392018-03-10 18:22:04 +01001817private function f_max(integer a, integer b) return integer {
1818 if (a > b) {
1819 return a;
1820 } else {
1821 return b;
1822 }
1823}
1824
1825private function f_min(integer a, integer b) return integer {
1826 if (a < b) {
1827 return a;
1828 } else {
1829 return b;
1830 }
1831}
1832
1833/* compute negative tolerance val-tolerance, ensure >= min */
1834private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1835 val := val - tolerance;
1836 return f_max(val, min);
1837}
1838
1839/* compute positive tolerance val+tolerance, ensure <= max */
1840private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1841 val := val + tolerance;
1842 return f_min(val, max);
1843}
1844
1845/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1846private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1847return template integer {
1848 var template integer ret;
1849 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1850 return ret;
1851}
1852
1853
Harald Welte70767382018-02-21 12:16:40 +01001854/* build a template for matching measurement results against */
1855private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1856 var ConnL1Pars l1p := g_pars.l1_pars;
1857 var template RSL_IE_UplinkMeas ul_meas := {
1858 len := 3,
1859 rfu := '0'B,
1860 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001861 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001862 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001863 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001864 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001865 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1866 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001867 supp_meas_info := omit
1868 };
Harald Welte685d5982018-02-27 20:42:05 +01001869 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001870 ul_meas.len := (3+8);
1871 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001872 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001873 toa256_min := ?,
1874 toa256_max := ?,
1875 toa256_std_dev := ?
1876 }
Harald Welte685d5982018-02-27 20:42:05 +01001877 }
Harald Welte70767382018-02-21 12:16:40 +01001878 var template RSL_IE_BS_Power bs_power := {
1879 reserved := 0,
1880 epc := false,
1881 fpc := false,
1882 power_level := l1p.bs_power_level
1883 };
1884 var template RSL_IE_L1Info l1_info := {
1885 ms_power_lvl := l1p.ms_power_level,
1886 fpc := false,
1887 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001888 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001889 };
1890 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001891 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001892 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1893 ?, t_toffs);
1894}
1895
Philipp Maierdd841d32019-12-17 14:44:54 +01001896/* build a template for matching measurement results that do not contain any
1897 * MS related measurement (l1_info, l3_info and ms timing offset). */
1898private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1899 var ConnL1Pars l1p := g_pars.l1_pars;
1900 var template RSL_IE_UplinkMeas ul_meas := {
1901 len := 3,
1902 rfu := '0'B,
1903 dtx_d := l1p.dtx_enabled,
1904 rxlev_f_u := ?,
1905 reserved1 := '00'B,
1906 rxlev_s_u := ?,
1907 reserved2 := '00'B,
1908 rxq_f_u := ?,
1909 rxq_s_u := ?,
1910 supp_meas_info := omit
1911 };
1912 if (l1p.toa256_enabled) {
1913 ul_meas.len := (3+8);
1914 ul_meas.supp_meas_info := {
1915 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1916 toa256_min := ?,
1917 toa256_max := ?,
1918 toa256_std_dev := ?
1919 }
1920 }
1921 var template RSL_IE_BS_Power bs_power := {
1922 reserved := 0,
1923 epc := false,
1924 fpc := false,
1925 power_level := l1p.bs_power_level
1926 };
1927
1928 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1929}
1930
Harald Welte70767382018-02-21 12:16:40 +01001931/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001932private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001933 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001934 var boolean chan_est := false;
1935
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001936 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001937
1938 /* Receive osmocom specific measurement reports. This is the normal
1939 * case. Here we verify that the measurement reports we sent are
1940 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001941 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1942 /* increment counter of next to-be-expected meas rep */
1943 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1944 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001945 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001946
1947 /* The following two cases may only happen in the beginning
1948 * of the channel establishment phase. Once we have received
1949 * the "our" measurement report the first time, the channel
1950 * is established and empty or hardcoded TRXCON reports must
1951 * not occur anymore. */
1952 chan_est := true;
1953
1954 repeat;
1955 }
1956
1957 /* When the BTS has established the channel, the MS might need slightly
1958 * more time to establish the channel and actually start sending. The
1959 * result is then a measurement report that just lacks the measurement
1960 * information of the MS. This is normal and we tolerate this behavior. */
1961 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1962 /* increment counter of next to-be-expected meas rep */
1963 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1964 /* Re-start the timer expecting the next MEAS RES */
1965 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001966 repeat;
1967 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001968
1969 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1970 * measurements if the TTCN3 side does not supply measurement input in
1971 * time. In those cases TRXCON will either use a cached measurement
1972 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1973 * report the templates above will not match. We tolerate this
1974 * behavior, but only once. */
1975 [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 +01001976 /* increment counter of next to-be-expected meas rep */
1977 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1978 if (g_first_meas_res) {
1979 g_first_meas_res := false;
1980 repeat;
1981 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001983 }
Harald Welte70767382018-02-21 12:16:40 +01001984 }
1985 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001987 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001988 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001990 }
1991}
1992
Harald Weltee613f962018-04-18 22:38:16 +02001993private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1994 select (rsl_alg_id) {
1995 case (RSL_ALG_ID_A5_0) { return 0; }
1996 case (RSL_ALG_ID_A5_1) { return 1; }
1997 case (RSL_ALG_ID_A5_2) { return 2; }
1998 case (RSL_ALG_ID_A5_3) { return 3; }
1999 case (RSL_ALG_ID_A5_4) { return 4; }
2000 case (RSL_ALG_ID_A5_5) { return 5; }
2001 case (RSL_ALG_ID_A5_6) { return 6; }
2002 case (RSL_ALG_ID_A5_7) { return 7; }
2003 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2005 /* Make compiler happy by calling mtc.stop here. It is already
2006 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002007 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002008 }
2009 }
2010}
2011
2012private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2013 select (rsl_alg_id) {
2014 case (RSL_ALG_ID_A5_1) { return '000'B; }
2015 case (RSL_ALG_ID_A5_2) { return '001'B; }
2016 case (RSL_ALG_ID_A5_3) { return '010'B; }
2017 case (RSL_ALG_ID_A5_4) { return '011'B; }
2018 case (RSL_ALG_ID_A5_5) { return '100'B; }
2019 case (RSL_ALG_ID_A5_6) { return '101'B; }
2020 case (RSL_ALG_ID_A5_7) { return '110'B; }
2021 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2023 /* Make compiler happy by calling mtc.stop here. It is already
2024 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002025 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002026 }
2027 }
2028}
2029
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002030/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2031private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2032 var GsmFrameNumber fn;
2033 timer T := 8.0;
2034
2035 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2036 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2037
2038 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2039 /* Send the actual RACH */
2040 fn := f_L1CTL_RACH(L1CTL, ra);
2041
2042 T.start;
2043 alt {
2044 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2045 [] T.timeout {
2046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2047 }
2048 }
2049 T.stop
2050 return fn;
2051}
Harald Weltee613f962018-04-18 22:38:16 +02002052
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002053/* Tune to a dedicated channel: L1CTL only */
2054private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
2055 if (not ispresent(pars.maio_hsn)) {
2056 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2057 7 /* TODO: mp_tsc */,
2058 mp_trx0_arfcn));
2059 } else {
2060 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2061 7 /* TODO: mp_tsc */,
2062 pars.maio_hsn.hsn,
2063 pars.maio_hsn.maio,
2064 pars.ma));
2065 }
2066}
2067
Harald Welte70767382018-02-21 12:16:40 +01002068/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002069private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002070 var GsmFrameNumber fn;
2071 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002072 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002073 var integer ra := 23;
2074
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002075 /* Send RACH request and wait for ChanReq */
2076 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002077
2078 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002079 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002080
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002081 /* Craft channel description (with or without frequency hopping parameters) */
2082 if (ispresent(g_pars.maio_hsn)) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002083 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002084 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002085 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002086 }
2087
Harald Welte70767382018-02-21 12:16:40 +01002088 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002089 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002090 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2091
2092 /* receive IMM.ASS on MS side */
2093 var ImmediateAssignment ia_um;
2094 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002095
2096 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2097 if (ch_desc.h != ia_um.chan_desc.h) {
2098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2099 }
2100
Harald Welte70767382018-02-21 12:16:40 +01002101 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002102 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002103 /* enable encryption, if requested */
2104 if (encr_enable) {
2105 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2106 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2107 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002108
2109 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002110}
2111
2112/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002113private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002114 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002115 RSL.clear;
2116
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002117 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002118 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002119 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002120 }
Harald Welte70767382018-02-21 12:16:40 +01002121
2122 f_est_dchan();
2123
2124 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2125 * RSL measurement reports on Abis side */
2126 timer T := 8.0;
2127 T.start;
2128 alt {
2129 [] as_l1_sacch();
2130 [] as_meas_res();
2131 [] as_l1_dcch();
2132 [] L1CTL.receive { repeat; }
2133 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002134 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002135 * of any earlier errors, so if we reach this timeout, we're good */
2136 setverdict(pass);
2137 }
2138 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002140 }
2141 }
2142 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002143 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002144}
Harald Welte0472ab42018-03-12 15:02:26 +01002145
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002146/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2147private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002148 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002149 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2150 timer Tup := 10.0;
2151 Tup.start;
2152 alt {
2153 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2154 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2155 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002156
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002157 if (rx_lvl != max_rx_lvl) {
2158 repeat;
2159 }
2160 Tup.stop;
2161 }
2162 [] L1CTL.receive { repeat; }
2163 [] Tup.timeout {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 log2str("Didn't reach full power ", max_rx_lvl));
2166 }
2167 }
2168 return max_rx_lvl;
2169}
2170
2171/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2172private function f_verify_ramp_up() runs on ConnHdlr {
2173 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002174 var integer initial_rx_lvl := -1;
2175 var integer last_rx_lvl := -1;
2176 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2177
2178 timer T := 2.0;
2179 alt {
2180 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2181 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2182 log("Received rx_level=", rx_lvl);
2183 if (initial_rx_lvl == -1) {
2184 initial_rx_lvl := rx_lvl;
2185 last_rx_lvl := rx_lvl;
2186
2187 /* Expect a somehow low value during first received messages */
2188 if (initial_rx_lvl >= max_rx_lvl / 2) {
2189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2190 log2str("Detected high initial tx power during ramp up: ",
2191 initial_rx_lvl , ", full power is", max_rx_lvl));
2192 }
2193 }
2194
2195 /* received Rx level bigger than maximum allowed power by CN */
2196 if (rx_lvl > max_rx_lvl) {
2197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2198 log2str("Detected Tx power higher than full power: ",
2199 rx_lvl , " > ", max_rx_lvl));
2200 }
2201
2202 /* Make sure it never decreases, since we are rumping up */
2203 if (last_rx_lvl > rx_lvl) {
2204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2205 log2str("Detected Tx power decrease during ramp up: ",
2206 last_rx_lvl , " -> ", rx_lvl));
2207 }
2208
2209 if (rx_lvl == max_rx_lvl and not T.running) {
2210 /* We reached the maximum power, start timer and receive
2211 /* a few more to make sure we don't surpass it */
2212 log("Reached full power, wating a bit more until success");
2213 T.start;
2214 }
2215
2216 last_rx_lvl := rx_lvl;
2217 repeat;
2218 }
2219 [] L1CTL.receive { repeat; }
2220 [] T.timeout { }
2221 }
2222
2223 /* We didn't increase tx power during ramp up */
2224 if (initial_rx_lvl < last_rx_lvl) {
2225 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2226 } else {
2227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2228 log2str("No Tx power increase during whole ramp up: ",
2229 initial_rx_lvl , " -> ", last_rx_lvl));
2230 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002231}
2232
2233/* verify BTS ramps power down to rx_level 0 */
2234private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2235 var L1ctlDlMessage l1_dl;
2236 var integer last_rx_lvl := max_rx_lvl;
2237
2238 timer Tdown := 5.0;
2239 Tdown.start;
2240 alt {
2241 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2242 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2243 log("Received rx_level=", rx_lvl);
2244
2245 /* received Rx level bigger than maximum allowed power by CN */
2246 if (rx_lvl > max_rx_lvl) {
2247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2248 log2str("Detected Tx power higher than full power: ",
2249 rx_lvl , " > ", max_rx_lvl));
2250 }
2251
2252 /* Make sure it never increases, since we are rumping down */
2253 if (last_rx_lvl < rx_lvl) {
2254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2255 log2str("Detected Tx power increase during ramp up: ",
2256 last_rx_lvl , " -> ", rx_lvl));
2257 }
2258
2259 last_rx_lvl := rx_lvl;
2260 if (last_rx_lvl != 0) {
2261 repeat;
2262 }
2263 /* we reached power level 0, we are done */
2264 Tdown.stop;
2265 }
2266 [] L1CTL.receive { repeat; }
2267 [] Tdown.timeout { }
2268 }
2269
2270 /* We didn't increase tx power during ramp down */
2271 if (max_rx_lvl > last_rx_lvl) {
2272 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2273 } else {
2274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2275 log2str("No Tx power decrease during whole ramp down: ",
2276 max_rx_lvl , " -> ", last_rx_lvl));
2277 }
2278}
2279
2280/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002281private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002282 f_l1_tune(L1CTL);
2283 RSL.clear;
2284
2285 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002286
2287 setverdict(pass);
2288}
2289testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2290 var ConnHdlr vc_conn;
2291 var ConnHdlrPars pars;
2292 f_init();
2293 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2294 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2295 pcu_comp := false, trxc_comp := true);
2296 vc_conn.done;
2297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2298}
2299
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002300/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002301private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002302 f_connhdlr_init_vty_bsc();
2303
2304 f_l1_tune(L1CTL);
2305 RSL.clear;
2306
2307 /* Wait until BTS is started and at full power */
2308 var integer max_rx_lvl := f_wait_ramp_up();
2309 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2310
2311 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2312 f_verify_ramp_down(max_rx_lvl);
2313
2314 setverdict(pass);
2315}
2316testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2317 var ConnHdlr vc_conn;
2318 var ConnHdlrPars pars;
2319 f_init();
2320 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2321 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2322 pcu_comp := false, trxc_comp := true);
2323 vc_conn.done;
2324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2325}
2326
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002327/* Verify Tx power:
2328 * + ramping down during ADM state UNLOCKED->LOCKED
2329 * + ramping up during ADM state LOCKED->UNLOCKED
2330 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002331private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002332 var L1ctlDlMessage l1_dl;
2333 var integer last_rx_lvl;
2334
2335 f_connhdlr_init_vty_bsc();
2336
2337 f_l1_tune(L1CTL);
2338 RSL.clear;
2339
2340 /* Wait until BTS is started and at full power */
2341 var integer max_rx_lvl := f_wait_ramp_up();
2342 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2343
2344 log("ADM STATE UNLOCKED->LOCKED");
2345 f_vty_enter_cfg_trx(BSCVTY);
2346 f_vty_transceive(BSCVTY, "rf_locked 1");
2347 last_rx_lvl := max_rx_lvl;
2348 f_verify_ramp_down(max_rx_lvl);
2349
2350 /* Let some time after we received 0dBm, then check we don't receive BCCH
2351 * anymore because scheduler has stopped after ramping down */
2352 f_sleep(2.0);
2353 L1CTL.clear;
2354 timer Tlocked := 2.0;
2355 Tlocked.start;
2356 alt {
2357 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2359 log2str("Received data_ind during rf_locked: ", l1_dl));
2360 }
2361 [] L1CTL.receive { repeat; }
2362 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2363 }
2364
2365 log("ADM STATE LOCKED->UNLOCKED");
2366 f_vty_transceive(BSCVTY, "rf_locked 0");
2367 f_verify_ramp_up();
2368 setverdict(pass);
2369}
2370testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2371 var ConnHdlr vc_conn;
2372 var ConnHdlrPars pars;
2373 f_init();
2374 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2375 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2376 pcu_comp := false, trxc_comp := true);
2377 vc_conn.done;
2378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2379}
2380
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002381private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002382 timer T := 8.0;
2383 T.start;
2384 var RSL_Message rsl;
2385 alt {
2386 [] as_l1_sacch();
2387 [] L1CTL.receive { repeat; }
2388 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2389 if (rsl.ies[3].body.bs_power.power_level == level) {
2390 setverdict(pass)
2391 } else {
2392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2393 }
2394 }
2395 [] T.timeout {
2396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2397 }
2398 }
2399}
2400
2401/* see if the rsl meas res contains our expeced bs power level
2402bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002403private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002404 f_l1_tune(L1CTL);
2405 RSL.clear;
2406
2407 if (mp_bts_trxc_port != -1) {
2408 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2409 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2410 }
2411
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002412 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002413 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2414 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2415
2416 f_est_dchan(more_ies :={valueof(pwr)});
2417
2418 f_check_meas_bs_power_level(pwr_var);
2419
2420 f_rsl_chan_deact();
2421 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2422}
2423
2424/* see if the rsl meas res contains our expeced bs power level
2425bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002426private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002427 f_l1_tune(L1CTL);
2428 RSL.clear;
2429
2430 if (mp_bts_trxc_port != -1) {
2431 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2432 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2433 }
2434
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002435 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002436 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2437
2438 f_est_dchan();
2439
2440 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2441
2442 f_check_meas_bs_power_level(pwr_var);
2443
2444 f_rsl_chan_deact();
2445 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2446}
2447
2448testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2449 var ConnHdlr vc_conn;
2450 var ConnHdlrPars pars;
2451 f_init();
2452 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2453 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2454 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2455 pcu_comp := false, trxc_comp := true);
2456 vc_conn.done;
2457 }
2458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2459}
2460
2461testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2462 var ConnHdlr vc_conn;
2463 var ConnHdlrPars pars;
2464 f_init();
2465 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2466 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2467 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2468 pcu_comp := false, trxc_comp := true);
2469 vc_conn.done;
2470 }
2471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2472}
2473
Eric Wild61edb7e2019-06-03 12:38:31 +02002474/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2475second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2476These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002477private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002478 var uint5_t pwr_var := 7;
2479 var L1ctlDlMessage l1_dl;
2480
2481 f_trxc_fake_rssi(rxlev2dbm(10));
2482 f_l1_tune(L1CTL);
2483 RSL.clear;
2484
2485 var RSL_IE_List addl_ies;
2486 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2487
2488 addl_ies := {
2489 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2490 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2491 };
2492
2493 /* establish with power parameters */
2494 f_est_dchan(more_ies := addl_ies);
2495
2496 /* set a high value to ensure L1 power control level increases */
2497 f_trxc_fake_rssi(rxlev2dbm(20));
2498
2499 timer T2 := 6.0;
2500 T2.start;
2501 alt {
2502 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002503 /* Update sent MS power to follow what BTS requests */
2504 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2505 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002506 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002507 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002508 T2.stop;
2509 }
2510 [] L1CTL.receive { repeat; }
2511 [] T2.timeout {
2512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2513 "Power Level in L1 header has not increased sufficiently");
2514 }
2515 }
2516
2517 /* set a low value to ensure L1 power control level decreases */
2518 f_trxc_fake_rssi(rxlev2dbm(0));
2519
2520 timer T4 := 6.0;
2521 T4.start;
2522 alt {
2523 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002524 /* Update sent MS power to follow what BTS requests */
2525 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2526 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002527 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002528 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002529 T4.stop;
2530 setverdict(pass, "Power level in L1 decreased/increased as expected");
2531 }
2532 [] L1CTL.receive { repeat; }
2533 [] T4.timeout {
2534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2535 "Power Level in L1 header has not decreased sufficiently");
2536 }
2537 }
2538
2539 f_rsl_chan_deact();
2540 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2541
2542}
2543
2544/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002545private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002546 var uint5_t pwr_var := 7;
2547 var L1ctlDlMessage l1_dl;
2548
2549 /* set a low value to ensure power increases */
2550 f_trxc_fake_rssi(rxlev2dbm(10));
2551 f_l1_tune(L1CTL);
2552 RSL.clear;
2553
2554 var RSL_IE_List addl_ies;
2555 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2556
2557 addl_ies := {
2558 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2559 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2560 };
2561
2562 /* establish with power parameters */
2563 f_est_dchan(more_ies := addl_ies);
2564
2565 timer T1 := 10.0;
2566 T1.start;
2567 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002568 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2569 /* Update sent MS power to follow what BTS requests */
2570 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2571 repeat;
2572 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002573 [] L1CTL.receive { repeat; }
2574 [] T1.timeout {
2575 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2576 setverdict(fail, "Power level in L1 header should not have changed");
2577 }
2578 }
2579 }
2580
2581 f_rsl_chan_deact();
2582 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2583
2584}
2585
2586/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002587private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002588 var L1ctlDlMessage l1_dl;
2589 var uint5_t pwr_var := 15;
2590 var uint5_t pwr_max_var := f_get_max_power_from_band();
2591
2592 /* set a low value to ensure power increases */
2593 f_trxc_fake_rssi(rxlev2dbm(10));
2594 f_l1_tune(L1CTL);
2595 RSL.clear;
2596
2597 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2598 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2599
2600 /* establish with fixed power level */
2601 f_est_dchan(more_ies :={valueof(pwr)});
2602
2603 /* check our initial power level */
2604 f_wait_for_l1_power_level(pwr_var);
2605
2606 /* update power param to enable power loop
2607 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2608 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2609
2610 /* wait, then check that our power level was reduced */
2611 timer T1 := 10.0;
2612 T1.start;
2613 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002614 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2615 /* Update sent MS power to follow what BTS requests */
2616 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2617 repeat;
2618 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002619 [] L1CTL.receive { repeat; }
2620 [] T1.timeout {
2621 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2622 if( f_power_level_is_highest_dbm(rcv) ){
2623 setverdict(pass, "Power level in L1 header reduced as expected");
2624 } else {
2625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2626 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2627 }
2628 }
2629 }
2630
2631 f_rsl_chan_deact();
2632 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2633
2634}
2635
2636/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002637private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002638 var L1ctlDlMessage l1_dl;
2639
2640 /* set a high value to ensure power decreases */
2641 f_trxc_fake_rssi(rxlev2dbm(50));
2642 f_l1_tune(L1CTL);
2643 RSL.clear;
2644
2645 var uint5_t pwr_var := 5;
2646 var uint5_t pwr_target_val := 15;
2647
2648 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2649 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2650
2651 /* establish with fixed power level */
2652 f_est_dchan(more_ies :={valueof(pwr)});
2653
2654 /* check our initial power level */
2655 f_wait_for_l1_power_level(pwr_var);
2656
2657 /* update power param to enable power loop
2658 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002659 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002660
2661 /* wait, then check that our power level was increased */
2662 timer T1 := 10.0;
2663 T1.start;
2664 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002665 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2666 /* Update sent MS power to follow what BTS requests */
2667 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2668 repeat;
2669 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002670 [] L1CTL.receive { repeat; }
2671 [] T1.timeout {
2672 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2673 setverdict(pass, "Power level in L1 header increased to lowest power value");
2674 } else {
2675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2676 "Power level in L1 header NOT increased to lowest power value");
2677 }
2678 }
2679 }
2680
2681 f_rsl_chan_deact();
2682 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2683
2684}
2685
Eric Wild095024b2019-06-17 15:08:57 +02002686/* see if we change the power level without receiving power parameters, which should not happen
2687rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002688private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002689 var L1ctlDlMessage l1_dl;
2690
2691 /* set a high value to ensure power decreases */
2692 f_trxc_fake_rssi(rxlev2dbm(50));
2693 f_l1_tune(L1CTL);
2694 RSL.clear;
2695
2696 var uint5_t pwr_var := 5;
2697
2698 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2699 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2700
2701 /* establish with fixed power level */
2702 f_est_dchan(more_ies :={valueof(pwr)});
2703
2704 /* check our initial power level */
2705 f_wait_for_l1_power_level(pwr_var);
2706
2707 /* wait, then check that our power level did not change */
2708 timer T1 := 10.0;
2709 T1.start;
2710 alt {
2711 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2712 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2714 "BS power control should not be active unless we receive a power parameters IE!");
2715 }
2716 repeat;
2717 }
2718 [] L1CTL.receive { repeat; }
2719 [] T1.timeout { setverdict(pass); }
2720 }
2721
2722 f_rsl_chan_deact();
2723 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2724
2725}
2726
Eric Wild095024b2019-06-17 15:08:57 +02002727/* see if we change the power level without receiving power parameters, which should not happen
2728ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002729private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002730 var L1ctlDlMessage l1_dl;
2731
2732 /* set a high value to ensure power decreases */
2733 f_trxc_fake_rssi(rxlev2dbm(50));
2734 f_l1_tune(L1CTL);
2735 RSL.clear;
2736
2737 var uint5_t pwr_var := 5;
2738
2739 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2740 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2741
2742 /* establish with fixed power level */
2743 f_est_dchan(more_ies :={valueof(pwr)});
2744
2745 /* check our initial power level */
2746 f_wait_for_l1_power_level(pwr_var);
2747
2748 /* pwr control without power params IE, should NOT activate MS power control*/
2749 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2750
2751 /* wait, then check that our power level did not change */
2752 timer T1 := 10.0;
2753 T1.start;
2754 alt {
2755 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2756 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2758 "BS power control should not be active unless we receive a power parameters IE!");
2759 }
2760 repeat;
2761 }
2762 [] L1CTL.receive { repeat; }
2763 [] T1.timeout { setverdict(pass); }
2764 }
2765
2766 f_rsl_chan_deact();
2767 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2768
2769}
2770
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002771private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002772 var L1ctlDlMessage l1_dl;
2773 timer T0 := 10.0;
2774 T0.start;
2775 alt {
2776 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2777 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2779 "Power level in L1 header != signaled (RSL) power level.");
2780 }
2781 }
2782 [] L1CTL.receive { repeat; }
2783 [] T0.timeout {
2784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2785 "Timeout waiting for initial power level");
2786 }
2787 }
2788 T0.stop;
2789}
2790
2791private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2792 var IntegerRecord min_dbm_level;
2793 var IntegerRecord max_dbm_level;
2794 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2795
2796 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2797 if (min_dbm_level[i] == level) {
2798 return true;
2799 }
2800 }
2801 return false;
2802}
2803
2804private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2805 var IntegerRecord min_dbm_level;
2806 var IntegerRecord max_dbm_level;
2807 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2808
2809 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2810 if (max_dbm_level[i] == level) {
2811 return true;
2812 }
2813 }
2814 return false;
2815}
2816
2817private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2818 var IntegerRecord min_dbm_level;
2819 var IntegerRecord max_dbm_level;
2820 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2821 return max_dbm_level[0];
2822}
2823
2824type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002825private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002826private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2827 // 45.005 4.1.1
2828 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2829 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2830 2, 1, 0};
2831 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2832 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2833 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2834 var IntegerRecord rv;
2835
2836 select(band){
2837 case (BtsBand_allGSM){
2838 rv := gsm_power;
2839 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2840 max_dbm_level := {2, 1, 0};
2841 }
2842 case("DCS1800"){
2843 rv := dcs_power;
2844 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2845 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2846 }
2847 case("PCS1900"){
2848 rv := pcs_power;
2849 min_dbm_level := {15};
2850 max_dbm_level := {30};
2851 }
2852 }
2853
2854 return rv;
2855}
2856
2857private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2858 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2859}
2860
2861testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2862 var ConnHdlr vc_conn;
2863 var ConnHdlrPars pars;
2864 f_init();
2865 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2866 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2867 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2868 pars.bts0_band := f_vty_get_bts0_band();
2869 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2870 vc_conn.done;
2871 }
2872 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2874}
2875
2876testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2877 var ConnHdlr vc_conn;
2878 var ConnHdlrPars pars;
2879 f_init();
2880 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2881 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2882 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2883 pars.bts0_band := f_vty_get_bts0_band();
2884 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2885 vc_conn.done;
2886 }
2887 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2889}
2890
2891testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2892 var ConnHdlr vc_conn;
2893 var ConnHdlrPars pars;
2894 f_init();
2895 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2896 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2897 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2898 pars.bts0_band := f_vty_get_bts0_band();
2899 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2900 vc_conn.done;
2901 }
2902 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2904}
2905
2906testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2907 var ConnHdlr vc_conn;
2908 var ConnHdlrPars pars;
2909 f_init();
2910 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2911 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2912 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2913 pars.bts0_band := f_vty_get_bts0_band();
2914 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2915 vc_conn.done;
2916 }
2917 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2919}
2920
Eric Wild280ccb82019-06-17 11:11:52 +02002921testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2922 var ConnHdlr vc_conn;
2923 var ConnHdlrPars pars;
2924 f_init();
2925 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2926 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2927 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2928 pars.bts0_band := f_vty_get_bts0_band();
2929 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2930 vc_conn.done;
2931 }
2932 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2934}
2935
Eric Wild095024b2019-06-17 15:08:57 +02002936testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2937 var ConnHdlr vc_conn;
2938 var ConnHdlrPars pars;
2939 f_init();
2940 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2941 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2942 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2943 pars.bts0_band := f_vty_get_bts0_band();
2944 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2945 vc_conn.done;
2946 }
2947 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2949}
2950
Harald Welte70767382018-02-21 12:16:40 +01002951testcase TC_meas_res_sign_tchf() runs on test_CT {
2952 var ConnHdlr vc_conn;
2953 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002954 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002955 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2956 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002957 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2958 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002959 vc_conn.done;
2960 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002962}
2963testcase TC_meas_res_sign_tchh() runs on test_CT {
2964 var ConnHdlr vc_conn;
2965 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002966 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002967 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2968 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002969 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2970 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002971 vc_conn.done;
2972 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002974}
2975testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2976 var ConnHdlr vc_conn;
2977 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002978 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002979 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2980 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002981 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2982 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002983 vc_conn.done;
2984 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002986}
2987testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2988 var ConnHdlr vc_conn;
2989 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002990 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002991 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2992 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002993 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2994 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002995 vc_conn.done;
2996 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002998}
Harald Welte685d5982018-02-27 20:42:05 +01002999testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3000 var ConnHdlr vc_conn;
3001 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003002 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003003 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3004 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3005 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3006 pars.l1_pars.toa256_enabled := true;
3007 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3008 vc_conn.done;
3009 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003011}
3012
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003013/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3014 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003015private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003016 var L1ctlDlMessage l1_dl;
3017 var RSL_IE_MS_Power ms_power;
3018 var RSL_Message rsl;
3019 var uint5_t power_level := 0;
3020
3021 f_l1_tune(L1CTL);
3022 RSL.clear;
3023
3024 f_est_dchan();
3025
3026 ms_power.reserved := 0;
3027 ms_power.fpc_epc := false;
3028
3029 /* Send the first power control command. This will disable any BTS/TRX
3030 * internal power control and switch the MS (which is not in scope of
3031 * this test) to a constant power level. We start with a power level
3032 * of 0 */
3033 ms_power.power_level := power_level;
3034 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3035 RSL.send(rsl);
3036
3037 alt {
3038
3039 /* Pick all SACCH blocks for checking */
3040 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3041
3042 /* The first byte of the L1 header contains the power level.
3043 * The reserved bits and the fpc bit is set to 0, so we may
3044 * compare directly. */
3045 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3046 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3047 }
3048
3049 /* Signal a new power level via RSL for the next turn. */
3050 if (power_level < 31) {
3051 power_level := power_level + 1;
3052 ms_power.power_level := power_level;
3053 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3054 RSL.send(rsl);
3055 repeat;
3056 }
3057
3058 }
3059
3060 /* Ignore all other blocks */
3061 [] L1CTL.receive { repeat; }
3062
3063 }
3064
3065 f_rsl_chan_deact();
3066 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3067
3068 setverdict(pass);
3069}
3070
3071testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3072 var ConnHdlr vc_conn;
3073 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003074 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003075
3076 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3077 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3078 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3079 vc_conn.done;
3080 }
3081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3082}
Harald Welte70767382018-02-21 12:16:40 +01003083
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003084/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003085TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003086private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003087 var L1ctlDlMessage l1_dl;
3088 var uint5_t ta_to_test := 16;
3089
3090
3091 f_l1_tune(L1CTL);
3092 RSL.clear;
3093
3094 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003095 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003096
3097 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3098
3099
3100 alt {
3101
3102 /* Pick all SACCH blocks for checking */
3103 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3104
3105 /* The second byte of the L1 header contains the TA. */
3106 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3107 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3108 }
3109
3110 }
3111
3112 /* Ignore all other blocks */
3113 [] L1CTL.receive { repeat; }
3114
3115 }
3116
3117 f_rsl_chan_deact();
3118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3119
3120 setverdict(pass);
3121}
3122
3123testcase TC_rsl_chan_initial_ta() runs on test_CT {
3124 var ConnHdlr vc_conn;
3125 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003126 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003127 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003128 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3129 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003130 vc_conn.done;
3131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3132}
3133
Eric Wilde57e1a62019-05-28 13:30:55 +02003134/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003135private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003136 var L1ctlDlMessage l1_dl;
3137 var uint5_t ms_power_level := 7;
3138
3139 var RSL_IE_MS_Power ms_power;
3140 ms_power.reserved := 0;
3141 ms_power.fpc_epc := false;
3142 ms_power.power_level := ms_power_level;
3143
3144 f_l1_tune(L1CTL);
3145 RSL.clear;
3146
3147 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3148
3149 timer T := 1.0;
3150 T.start;
3151 alt {
3152 /* Pick all SACCH blocks for checking */
3153 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3154 /* The first byte of the L1 header contains the power level.. */
3155 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3156 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3157 }
3158 }
3159 /* Ignore all other blocks */
3160 [] L1CTL.receive { repeat; }
3161 [] T.timeout {
3162 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3163 }
3164 }
3165
3166 f_rsl_chan_deact();
3167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3168 setverdict(pass);
3169}
3170
3171testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3172 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3173 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3174}
3175
Harald Welte0472ab42018-03-12 15:02:26 +01003176/* 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 +01003177private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003178 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003179 RSL.clear;
3180
3181 f_est_dchan();
3182 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003183 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003184
3185 timer T := 40.0;
3186 T.start;
3187 alt {
3188 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3189 setverdict(pass)
3190 }
3191 [] RSL.receive { repeat };
3192 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003194 }
3195 }
3196 f_rsl_chan_deact();
3197}
3198testcase TC_conn_fail_crit() runs on test_CT {
3199 var ConnHdlr vc_conn;
3200 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003201 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003202 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3203 pars.t_guard := 60.0;
3204 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3205 vc_conn.done;
3206}
3207
Harald Welte93640c62018-02-25 16:59:33 +01003208/***********************************************************************
3209 * Paging
3210 ***********************************************************************/
3211
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003212private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003213 if (tmsi == 'FFFFFFFF'O) {
3214 return true;
3215 } else {
3216 return false;
3217 }
3218}
Harald Welte70767382018-02-21 12:16:40 +01003219
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003220private type record allowedFn { integer frame_nr }
3221private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3222private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3223private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3224private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3225private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3226private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3227private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3228private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3229private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003230{
3231 var integer frame_nr_51;
3232 frame_nr_51 := frame_nr mod 51
3233
3234 var allowedFn fn_check;
3235 fn_check.frame_nr := frame_nr_51;
3236
3237 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003239 return;
3240 }
3241
3242 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3243 return;
3244 }
3245 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3246 return;
3247 }
3248 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3249 return;
3250 }
3251 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3252 return;
3253 }
3254 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3255 return;
3256 }
3257 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3258 return;
3259 }
3260 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3261 return;
3262 }
3263 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3264 return;
3265 }
3266
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003268 return;
3269}
3270
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003271private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3272 inout integer num_paging_rcv_ids,
3273 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003274runs on test_CT {
3275 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003276 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003277 repeat;
3278 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003279 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003280 var octetstring without_plen :=
3281 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3282 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003283
3284 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3285
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003286 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3287 /* Ignore empty RR Paging Request (PCH filling) messages.
3288 * TODO: does it make sense to count them? */
3289 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003290 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3291 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003292 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003293 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3294 }
3295 } else if (match(rr, tr_PAGING_REQ2)) {
3296 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3297 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3298 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3299 }
3300 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3301 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3302 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003303 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003304 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3305 }
3306 } else if (match(rr, tr_PAGING_REQ3)) {
3307 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3308 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3309 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3310 }
3311 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3312 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3313 }
3314 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3315 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3316 }
3317 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3318 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3319 }
3320 }
3321 repeat;
3322 }
3323}
3324
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003325private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003326 boolean combined_ccch,
3327 integer bs_ag_blks_res,
3328 float load_factor,
3329 boolean exp_load_ind,
3330 boolean exp_overload,
3331 boolean use_tmsi
3332}
3333
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003334private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003335 integer num_paging_sent,
3336 integer num_paging_rcv_msgs,
3337 integer num_paging_rcv_ids,
3338 integer num_overload
3339}
3340
Harald Welte68e495b2018-02-25 00:05:57 +01003341/* Helper function for paging related testing */
3342private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003343 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003344 f_init_l1ctl();
3345 f_l1_tune(L1CTL);
3346
3347 var PagingTestState st := {
3348 num_paging_sent := 0,
3349 num_paging_rcv_msgs := 0,
3350 num_paging_rcv_ids := 0,
3351 num_overload := 0
3352 };
3353
3354 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3355 var float max_pch_imsi_per_sec;
3356 if (cfg.use_tmsi) {
3357 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3358 } else {
3359 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3360 }
3361 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3362 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003363 var float time_total := 20.0;
3364 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3365 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003366
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003367 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3368 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003369
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003370 timer T_itv := 0.0;
3371 T_itv.start;
3372 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003373 alt {
3374 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003375 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003376 st.num_overload := st.num_overload + 1;
3377 repeat;
3378 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003379 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003381 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003382 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003383 log("Rx LOAD_IND");
3384 /* FIXME: analyze/verify interval + contents */
3385 repeat;
3386 }
3387 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003388 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003389 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003390 [] T_itv.timeout {
3391 /* Send paging cmds based on elapsed time */
3392 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3393 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003394 var MobileIdentityV mi;
3395
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003396 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003397 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003398 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003399 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003400 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003401 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003402
3403 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003404 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 +02003405
3406 st.num_paging_sent := st.num_paging_sent + 1;
3407 }
3408 if (st.num_paging_sent < pkt_total) {
3409 /* Wait for interval to next PAGING COMMAND */
3410 var float time_now := T_total.read;
3411 var float next_sched := int2float(st.num_paging_sent)*interval;
3412 if (next_sched > time_now) {
3413 T_itv.start(next_sched - time_now);
3414 } else {
3415 T_itv.start(0.0);
3416 }
3417 } else {
3418 /* We are done, no need to keep counting */
3419 T_total.stop;
3420 }
3421 }
3422 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003423 }
3424 }
3425
3426 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3427 timer T_wait := 18.0;
3428 T_wait.start;
3429 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003430 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003431 [] L1CTL.receive { repeat; }
3432 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003433 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3434 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003435 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003437 }
Harald Welte68e495b2018-02-25 00:05:57 +01003438 }
3439
3440 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3441 " rcvd_ids=", st.num_paging_rcv_ids);
3442 return st;
3443}
3444
3445/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3446 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3447 * - that CCCH LOAD IND (PCH) are being generated
3448 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3449testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003450 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003451 var PagingTestCfg cfg := {
3452 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003453 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003454 load_factor := 0.8,
3455 exp_load_ind := true,
3456 exp_overload := false,
3457 use_tmsi := false
3458 };
3459 var PagingTestState st := f_TC_paging(cfg);
3460 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3462 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003463 } else {
3464 setverdict(pass);
3465 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003467}
3468
3469/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3470 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3471 * - that CCCH LOAD IND (PCH) are being generated
3472 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3473testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003474 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003475 var PagingTestCfg cfg := {
3476 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003477 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003478 load_factor := 0.8,
3479 exp_load_ind := true,
3480 exp_overload := false,
3481 use_tmsi := true
3482 };
3483 var PagingTestState st := f_TC_paging(cfg);
3484 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3486 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003487 } else {
3488 setverdict(pass);
3489 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003491}
3492
3493/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3494 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3495 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3496 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3497testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003498 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003499 var PagingTestCfg cfg := {
3500 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003501 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003502 load_factor := 2.0,
3503 exp_load_ind := true,
3504 exp_overload := true,
3505 use_tmsi := false
3506 };
3507 var PagingTestState st := f_TC_paging(cfg);
3508 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3509 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003510 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003511 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 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 +01003513 } else {
3514 setverdict(pass);
3515 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003517}
3518
3519/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3520 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3521 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3522 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3523testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003524 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003525 var PagingTestCfg cfg := {
3526 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003527 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003528 load_factor := 2.0,
3529 exp_load_ind := true,
3530 exp_overload := true,
3531 use_tmsi := true
3532 };
3533 var PagingTestState st := f_TC_paging(cfg);
3534 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3535 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003536 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003537 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003538 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 +01003539 } else {
3540 setverdict(pass);
3541 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003543}
3544
3545
Harald Welte93640c62018-02-25 16:59:33 +01003546/***********************************************************************
3547 * Immediate Assignment / AGCH
3548 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003549private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003550 len := 0,
3551 ma := ''B
3552}
Harald Welte93640c62018-02-25 16:59:33 +01003553
Harald Weltee8d750e2018-06-10 21:41:35 +02003554private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3555 return int2str(num_tx) & " sent, "
3556 & int2str(num_rx) & " received, "
3557 & int2str(num_del) & " deleted";
3558}
3559
3560private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3561 var L1ctlDlMessage l1_dl;
3562 timer T := 10.0;
3563 var integer num_tx := 0;
3564 var integer num_rx := 0;
3565 var integer num_del := 0;
3566 var charstring res_str;
3567 var float rx_ratio;
3568
Harald Welte10474062019-05-30 16:48:17 +02003569 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003570 f_init_l1ctl();
3571 f_l1_tune(L1CTL);
3572
3573 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003574 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003575 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3576 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003577 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003578 num_tx := num_tx+1;
3579 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003580 }
3581 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003582 T.start;
3583 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003584 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003585 num_del := num_del+1;
3586 repeat;
3587 }
3588 [] RSL_CCHAN.receive {
3589 repeat;
3590 }
3591 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003592 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3593 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3594 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003595 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003596 } else {
3597 num_rx := num_rx+1;
3598 }
3599 repeat;
3600 }
3601 [] L1CTL.receive { repeat; }
3602 [] T.timeout { }
3603 }
3604 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3605 log("AGCH test: " & res_str);
3606 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003608 }
3609 rx_ratio := int2float(num_rx) / int2float(num_tx);
3610 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 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 +02003612 } else {
3613 setverdict(pass);
3614 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003616}
3617
Harald Weltee8d750e2018-06-10 21:41:35 +02003618/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3619testcase TC_imm_ass_1000_20ms() runs on test_CT {
3620 f_TC_imm_ass(1000, 0.02, 0.25);
3621}
3622
3623/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3624testcase TC_imm_ass_200_0ms() runs on test_CT {
3625 f_TC_imm_ass(200, 0.0, 0.05);
3626}
3627
3628/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3629testcase TC_imm_ass_200_76ms() runs on test_CT {
3630 f_TC_imm_ass(150, 0.076, 1.00);
3631}
3632
3633
3634
Harald Welte48494ca2018-02-25 16:59:50 +01003635/***********************************************************************
3636 * BCCH
3637 ***********************************************************************/
3638
3639/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003640private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003641 GsmFrameNumber frame_number,
3642 SystemInformation si
3643}
3644
3645/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003646private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003647
3648/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003649private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003650
3651/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003652private function f_si_vecslot_contains(SystemInformationVector arr,
3653 RrMessageType key,
3654 boolean bcch_ext := false)
3655return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003656 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3657 var integer fn_mod51 := arr[i].frame_number mod 51;
3658 if (not bcch_ext and fn_mod51 == 2 or
3659 bcch_ext and fn_mod51 == 6) {
3660 if (arr[i].si.header.message_type == key) {
3661 return true;
3662 }
3663 }
3664 }
3665 return false;
3666}
3667
3668/* 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 +07003669private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3670 integer tc, RrMessageType key,
3671 boolean ext_bcch := false)
3672{
Harald Welte48494ca2018-02-25 16:59:50 +01003673 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003675 }
3676}
3677
3678/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003679private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3680 RrMessageType key)
3681return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003682 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3683 if (f_si_vecslot_contains(arr[tc], key) or
3684 f_si_vecslot_contains(arr[tc], key, true)) {
3685 return true;
3686 }
3687 }
3688 return false;
3689}
3690
3691/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003692private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3693 RrMessageType key,
3694 boolean bcch_ext := false,
3695 integer n := 1, integer m := 4)
3696return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003697 var integer count := 0;
3698 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003700 }
3701 for (var integer i:= 0; i < m; i := i + 1) {
3702 var integer fn_mod51 := arr[i].frame_number mod 51;
3703 if (not bcch_ext and fn_mod51 == 2 or
3704 bcch_ext and fn_mod51 == 6) {
3705 if (arr[i].si.header.message_type == key) {
3706 count := count + 1;
3707 }
3708 }
3709 }
3710 if (count >= n) {
3711 return true;
3712 } else {
3713 return false;
3714 }
3715}
3716
3717/* 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 +07003718private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3719 integer tc, RrMessageType key,
3720 boolean ext_bcch := false,
3721 integer n, integer m)
3722{
Harald Welte48494ca2018-02-25 16:59:50 +01003723 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003725 }
3726}
3727
3728/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003729private function f_si_vecslot_contains_only(SystemInformationVector arr,
3730 RrMessageType key,
3731 boolean bcch_ext := false)
3732return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003733 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3734 var integer fn_mod51 := arr[i].frame_number mod 51;
3735 if (not bcch_ext and fn_mod51 == 2 or
3736 bcch_ext and fn_mod51 == 6) {
3737 if (arr[i].si.header.message_type != key) {
3738 return false;
3739 }
3740 }
3741 }
3742 return true;
3743}
3744
3745/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003746private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3747 integer tc, RrMessageType key,
3748 boolean ext_bcch := false)
3749{
Harald Welte48494ca2018-02-25 16:59:50 +01003750 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003752 }
3753}
3754
3755/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003756private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003757 boolean bcch_extended,
3758 boolean si1_present,
3759 boolean si2bis_present,
3760 boolean si2ter_present,
3761 boolean si2quater_present,
3762 boolean si7_present,
3763 boolean si8_present,
3764 boolean si9_present,
3765 boolean si13_present,
3766 boolean si13alt_present,
3767 boolean si15_present,
3768 boolean si16_present,
3769 boolean si17_present,
3770 boolean si2n_present,
3771 boolean si21_present,
3772 boolean si22_present
3773}
3774
3775/* 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 +07003776private function f_validate_si_scheduling(SystemInformationConfig cfg,
3777 SystemInformationVectorPerTc si_per_tc)
3778{
Harald Welte48494ca2018-02-25 16:59:50 +01003779 var integer i;
3780 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3781 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003783 }
3784 }
3785 if (cfg.si1_present) {
3786 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3787 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3788 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3789 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3790 /* make sure *ALL* contain SI1 */
3791 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3792 }
3793 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3794 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3795 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3796 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3797 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3798 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3799
3800 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3801 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3802 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3803 * consecutive occurrences of TC = 4. */
3804 if (cfg.si2bis_present and not cfg.si2ter_present) {
3805 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3806 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3807 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3808 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3809 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3810 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3811 }
3812
3813 if (cfg.si7_present or cfg.si8_present) {
3814 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3815 * if System Information type 4 does not contain all information needed for cell
3816 * selection and reselection. */
3817 if (not cfg.bcch_extended) {
3818 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3819 }
3820 if (cfg.si7_present) {
3821 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3822 }
3823 if (cfg.si8_present) {
3824 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3825 }
3826 }
3827
3828 if (cfg.si2quater_present) {
3829 /* iii) System information type 2 quater is sent if needed, as determined by the system
3830 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3831 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3832 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3833 * within any of 4 consecutive occurrences of TC = 5. */
3834 if (not (cfg.bcch_extended)) {
3835 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3836 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3837 } else {
3838 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3839 }
3840 } else {
3841 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3842 }
3843 }
3844 if (cfg.si9_present) {
3845 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3846 * in system information type 3 as defined in 3GPP TS 44.018. */
3847 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3848 }
3849 if (cfg.si13_present) {
3850 /* vii) System Information type 13 is only related to the GPRS service. System Information
3851 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3852 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3853 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3854 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3855 * within any of 4 consecutive occurrences of TC=4. */
3856 if (not cfg.bcch_extended) {
3857 log("not-bccch-extended");
3858 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3859 } else {
3860 log("bccch-extended");
3861 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3862 }
3863 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003865 }
3866 }
3867 if (cfg.si16_present or cfg.si17_present) {
3868 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3869 * should not be sent in a cell where network sharing is used (see rule xv). */
3870 if (cfg.si22_present) {
3871 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3872 }
3873 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003875 }
3876 if (not cfg.bcch_extended) {
3877 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3878 }
3879 if (cfg.si16_present) {
3880 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3881 }
3882 if (cfg.si17_present) {
3883 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3884 }
3885 }
3886
3887 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3888 * broadcast information. The frequency with which they are sent is determined by the
3889 * system operator. System Information type 9 identifies the scheduling of System
3890 * Information type 18 and 20 messages. */
3891
3892 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3893 * Information Type 19 is present, then its scheduling shall be indicated in System
3894 * Information Type 9. */
3895
3896 if (cfg.si15_present) {
3897 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3898 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3899 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3900 * 4 consecutive occurrences of TC = 1. */
3901 if (not cfg.bcch_extended) {
3902 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3903 } else {
3904 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3905 }
3906 }
3907 if (cfg.si13alt_present) {
3908 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3909 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3910 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3911 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3912 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3913 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3914 * of TC = 4. */
3915 if (cfg.si13_present) {
3916 testcase.stop("Error: Cannot have SI13alt and SI13");
3917 }
3918 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003920 }
3921 if (not cfg.bcch_extended) {
3922 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3923 } else {
3924 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3925 }
3926 }
3927 if (cfg.si2n_present) {
3928 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3929 * as determined by the system operator. In the case that the message is sent on the
3930 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3931 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3932 * consecutive occurrences of TC = 4. */
3933 if (not cfg.bcch_extended) {
3934 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3935 } else {
3936 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3937 }
3938 }
3939 if (cfg.si21_present) {
3940 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3941 * determined by the system operator. If Extended Access Barring is in use in the cell
3942 * then this message is sent at least once within any of 4 consecutive occurrences of
3943 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3944 * cell then this message shall only be sent on BCCH Ext. */
3945 if (not cfg.bcch_extended) {
3946 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3947 } else {
3948 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3949 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003951 }
3952 }
3953 }
3954 if (cfg.si22_present) {
3955 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3956 * should not be sent in a cell where SoLSA is used (see rule viii). System
3957 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3958 * =2 and TC=6. */
3959 if (cfg.si16_present or cfg.si17_present) {
3960 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3961 }
3962 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3963 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003965 }
3966 if (not cfg.bcch_extended) {
3967 testcase.stop("Error: SI22 requires BCCH Extd!");
3968 } else {
3969 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3970 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3971 }
3972 }
3973}
3974
3975/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003976private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3977return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003978 timer T := duration;
3979 var SystemInformationVectorPerTc si_per_tc;
3980 var L1ctlDlMessage l1_dl;
3981
3982 /* initialize all per-TC vectors empty */
3983 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3984 si_per_tc[i] := {};
3985 }
3986
3987 /* flush all previous L1 queued msgs */
3988 pt.clear;
3989
3990 T.start;
3991 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003992 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003993 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3994 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3995 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003996 repeat;
3997 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003998
Harald Welte48494ca2018-02-25 16:59:50 +01003999 var integer tc := f_gsm_compute_tc(sig.frame_number);
4000 log("SI received at TC=", tc, ": ", sig.si);
4001 /* append to the per-TC bucket */
4002 si_per_tc[tc] := si_per_tc[tc] & { sig };
4003 repeat;
4004 }
4005 [] pt.receive { repeat; }
4006 [] T.timeout { }
4007 }
4008
4009 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4010 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4011 }
4012 log("si_per_tc=", si_per_tc);
4013 return si_per_tc;
4014}
4015
4016/* helper function: Set given SI via RSL + validate scheduling.
4017 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004018private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004019 var SystemInformationVectorPerTc si_per_tc;
4020 f_init_l1ctl();
4021 f_l1_tune(L1CTL);
4022
4023 /* Sample + Validate Scheduling */
4024 si_per_tc := f_l1_sample_si(L1CTL);
4025 f_validate_si_scheduling(si_cfg, si_per_tc);
4026
4027 setverdict(pass);
4028}
4029
4030testcase TC_si_sched_default() runs on test_CT {
4031 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004032 /* 2+3+4 are mandatory and set in f_init() */
4033 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004035}
4036
4037testcase TC_si_sched_1() runs on test_CT {
4038 f_init();
4039 si_cfg.si1_present := true;
4040 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004041 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004043}
4044
4045testcase TC_si_sched_2bis() runs on test_CT {
4046 f_init();
4047 si_cfg.si2bis_present := true;
4048 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4049 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004051}
4052
4053testcase TC_si_sched_2ter() runs on test_CT {
4054 f_init();
4055 si_cfg.si2ter_present := true;
4056 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4057 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004059}
4060
4061testcase TC_si_sched_2ter_2bis() runs on test_CT {
4062 f_init();
4063 si_cfg.si2bis_present := true;
4064 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4065 si_cfg.si2ter_present := true;
4066 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4067 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004069}
4070
4071testcase TC_si_sched_2quater() runs on test_CT {
4072 f_init();
4073 si_cfg.si2quater_present := true;
4074 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4075 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004077}
4078
4079testcase TC_si_sched_13() runs on test_CT {
4080 f_init();
4081 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004082 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004083 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004085}
4086
4087testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4088 f_init();
4089 si_cfg.si2bis_present := true;
4090 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4091 si_cfg.si2ter_present := true;
4092 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4093 si_cfg.si2quater_present := true;
4094 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4095 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004096 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004097 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004099}
4100
4101
Harald Welte68e495b2018-02-25 00:05:57 +01004102testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004103 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004104 /* FIXME: enable / disable individual BCCH info */
4105 //ts_RSL_BCCH_INFO(si_type, info);
4106 /* expect no ERROR REPORT after either of them *
4107 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004109}
4110
Harald Welte93640c62018-02-25 16:59:33 +01004111/***********************************************************************
4112 * Low-Level Protocol Errors / ERROR REPORT
4113 ***********************************************************************/
4114
Harald Welte01d982c2018-02-25 01:31:40 +01004115private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4116 timer T := 5.0;
4117 T.start;
4118 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004119 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004120 setverdict(pass);
4121 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004122 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004124 }
4125 [] RSL_CCHAN.receive {
4126 repeat;
4127 }
4128 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004130 }
4131 }
4132}
4133
4134/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4135testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004136 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004137 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4138 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004139 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004140
4141 f_exp_err_rep(RSL_ERR_PROTO);
4142}
4143
4144/* Provoke a mandatory IE error and match on ERROR REPORT */
4145testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004146 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004147
4148 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4149 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004150 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004151
4152 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4153}
4154
4155/* Provoke an IE content error and match on ERROR REPORT */
4156testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004157 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004158 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4159 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004160 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004161
4162 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4163}
4164
Harald Welteee25aae2019-05-19 14:32:37 +02004165/* attempt to activate channel with wrong RSL Message Discriminator IE */
4166function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4167 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4168 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4169 RSL.send(rsl);
4170 f_rslem_unregister(0, g_chan_nr);
4171}
4172testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4173 var ConnHdlr vc_conn;
4174 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4175
Harald Welte10474062019-05-30 16:48:17 +02004176 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004177
4178 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4179 vc_conn.done;
4180 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4181
4182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4183}
4184
4185/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004186private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004187 var template (value) RSL_Message rsl_tx;
4188 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4189 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4190 RSL.send(rsl_tx);
4191 f_rslem_unregister(0, g_chan_nr);
4192}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004193private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004194 var template (value) RSL_Message rsl_tx;
4195 /* we first have to activate the dedicated channel */
4196 f_rsl_chan_act(g_pars.chan_mode);
4197 /* ... to then send an invalid RLL message */
4198 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4199 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4200 RSL.send(rsl_tx);
4201 f_rslem_unregister(0, g_chan_nr);
4202}
4203testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4204 var ConnHdlr vc_conn;
4205 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4206 var template (value) RSL_Message rsl_tx;
4207
Harald Welte10474062019-05-30 16:48:17 +02004208 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004209
4210 /* Common Channel with wrong message type */
4211 RSL_CCHAN.clear;
4212 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4213 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004214 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004215 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4216
4217 /* TRX Management */
4218 RSL_CCHAN.clear;
4219 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4220 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004221 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004222 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4223
4224 /* Dedicated Channel */
4225 RSL_CCHAN.clear;
4226 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4227 vc_conn.done;
4228 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4229
4230 /* RLL */
4231 RSL_CCHAN.clear;
4232 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4233 vc_conn.done;
4234 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4235}
4236
4237/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004238private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004239 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4240 f_rslem_unregister(0, g_chan_nr);
4241}
4242testcase TC_err_rep_wrong_sequence() runs on test_CT {
4243 var ConnHdlr vc_conn;
4244 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4245
Harald Welte10474062019-05-30 16:48:17 +02004246 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004247
4248 RSL_CCHAN.clear;
4249 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4250 vc_conn.done;
4251 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4252}
4253
Harald Welte93640c62018-02-25 16:59:33 +01004254/***********************************************************************
4255 * IPA CRCX/MDCX/DLCS media stream handling
4256 ***********************************************************************/
4257
Harald Weltea871a382018-02-25 02:03:14 +01004258/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004259private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004260 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4261 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004262}
4263testcase TC_ipa_dlcx_not_active() runs on test_CT {
4264 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004265 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004266 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4267 vc_conn.done;
4268}
Harald Welte68e495b2018-02-25 00:05:57 +01004269
Harald Weltea3f1df92018-02-25 12:49:55 +01004270/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004271private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004272 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4273 "IPA CRCX ACK");
4274 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4275 "IPA CRCX NACK");
4276}
4277testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4278 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004279 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004280 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4281 vc_conn.done;
4282}
4283
4284/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004285private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004286 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4287 "IPA CRCX ACK");
4288 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4289 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4290 var uint7_t rtp_pt2 := f_rnd_int(127);
4291 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4292 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4293 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4294 "IPA MDCX ACK");
4295 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4296 "IPA DLCX ACK");
4297}
4298testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4299 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004300 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004301 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4302 vc_conn.done;
4303}
4304
Harald Welte3ae11da2018-02-25 13:36:06 +01004305/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004306private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004307 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4308 "IPA CRCX ACK");
4309 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4310 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4311 var uint7_t rtp_pt2 := f_rnd_int(127);
4312 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4313 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4314 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4315 "IPA MDCX ACK");
4316 /* Second MDCX */
4317 remote_ip := f_rnd_int(c_UINT32_MAX);
4318 remote_port := f_rnd_int(c_UINT16_MAX);
4319 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4320 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4321 "IPA MDCX ACK");
4322 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4323 "IPA DLCX ACK");
4324}
4325testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4326 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004327 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004328 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4329 vc_conn.done;
4330}
4331
Harald Welte9912eb52018-02-25 13:30:15 +01004332/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004333private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004334 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4335 "IPA CRCX NACK");
4336}
4337testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4338 var ConnHdlrPars pars;
4339 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004340 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004341
4342 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4343 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4344 vc_conn.done;
4345
4346 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4347 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4348 vc_conn.done;
4349}
4350
Harald Weltea3f1df92018-02-25 12:49:55 +01004351
Harald Welte883340c2018-02-28 18:59:29 +01004352/***********************************************************************
4353 * PCU Socket related tests
4354 ***********************************************************************/
4355
Harald Welte07bd2d22019-05-25 11:03:30 +02004356/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004357friend 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 +01004358runs on test_CT {
4359 timer T := 3.0;
4360
4361 /* we don't expect any RTS.req before PDCH are active */
4362 T.start;
4363 alt {
4364 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004366 }
4367 [] PCU.receive { repeat; }
4368 [] T.timeout { }
4369 }
4370
4371 /* Send PDCH activate request for known PDCH timeslot */
4372 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4373
4374 /* we now expect RTS.req for this timeslot (only) */
4375 T.start;
4376 alt {
4377 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4378 setverdict(pass);
4379 }
4380 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4381 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004383 }
4384 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004386 }
4387 [] PCU.receive { repeat; }
4388 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004390 }
4391 [not exp_success] T.timeout {
4392 setverdict(pass);
4393 }
4394 }
4395}
4396
Harald Welte07bd2d22019-05-25 11:03:30 +02004397/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004398friend 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 +01004399runs on test_CT {
4400 timer T := 3.0;
4401
4402 /* Send PDCH activate request for known PDCH timeslot */
4403 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4404
4405 PCU.clear;
4406 /* we now expect no RTS.req for this timeslot */
4407 T.start;
4408 alt {
4409 [] 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 +02004410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004411 }
4412 [] PCU.receive { repeat; }
4413 [] T.timeout {
4414 setverdict(pass);
4415 }
4416 }
4417}
4418
Harald Weltead033dc2019-05-25 17:28:16 +02004419friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004420 f_init();
4421 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4422}
4423
Harald Welte883340c2018-02-28 18:59:29 +01004424/* PDCH activation via PCU socket; check for presence of RTS.req */
4425testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004426 f_init_pcu_test();
4427
Harald Welte883340c2018-02-28 18:59:29 +01004428 f_TC_pcu_act_req(0, 0, 7, true);
4429}
4430
4431/* PDCH activation via PCU socket on non-PDCU timeslot */
4432testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004433 f_init_pcu_test();
4434
Harald Welte883340c2018-02-28 18:59:29 +01004435 f_TC_pcu_act_req(0, 0, 1, false);
4436}
4437
4438/* PDCH activation via PCU socket on wrong BTS */
4439testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004440 f_init_pcu_test();
4441
Harald Welte883340c2018-02-28 18:59:29 +01004442 f_TC_pcu_act_req(23, 0, 7, false);
4443}
4444
4445/* PDCH activation via PCU socket on wrong TRX */
4446testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004447 f_init_pcu_test();
4448
Harald Welte883340c2018-02-28 18:59:29 +01004449 f_TC_pcu_act_req(0, 23, 7, false);
4450}
4451
4452/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4453testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004454 f_init_pcu_test();
4455
Harald Welte883340c2018-02-28 18:59:29 +01004456 /* Activate PDCH */
4457 f_TC_pcu_act_req(0, 0, 7, true);
4458 f_sleep(1.0);
4459 /* and De-Activate again */
4460 f_TC_pcu_deact_req(0, 0, 7);
4461}
4462
4463/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4464testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004465 f_init_pcu_test();
4466
Harald Welte883340c2018-02-28 18:59:29 +01004467 f_TC_pcu_deact_req(0, 0, 1);
4468}
4469
4470/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4471testcase TC_pcu_ver_si13() runs on test_CT {
4472 const octetstring si13 := '00010203040506070909'O;
4473 var PCUIF_send_data sd;
4474 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004475 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004476
4477 /* Set SI13 via RSL */
4478 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004479
Harald Welte883340c2018-02-28 18:59:29 +01004480 T.start;
4481 alt {
4482 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4483 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4484 setverdict(pass);
4485 } else {
4486 repeat;
4487 }
4488 }
4489 [] PCU.receive { repeat; }
4490 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004492 }
4493 }
4494}
4495
4496private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4497
4498/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004499friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004500 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4501runs on test_CT
4502{
4503 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4504 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4505}
4506
4507/* 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 +02004508friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4509 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004510runs on test_CT
4511{
4512 var PCUIF_send_data sd;
4513
4514 timer T := 3.0;
4515 T.start;
4516 alt {
4517 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4518 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4519 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4520 sd.data.u.rts_req.fn, sapi, data);
4521 }
4522 [] PCU.receive { repeat; }
4523 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004525 }
4526 }
4527}
4528
4529/* Send DATA.req on invalid BTS */
4530testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004531 var TfiUsfArr tua := f_TfiUsfArrInit();
4532 var octetstring data := '0000'O & f_rnd_octstring(21);
4533
4534 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004535
Harald Welte883340c2018-02-28 18:59:29 +01004536 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004537 f_TfiUsfArrSet(tua, 7, 0);
4538 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4539 f_sleep(1.0);
4540
4541 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004542}
4543
4544/* Send DATA.req on invalid TRX */
4545testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004546 var TfiUsfArr tua := f_TfiUsfArrInit();
4547 var octetstring data := '0000'O & f_rnd_octstring(21);
4548
4549 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004550
Harald Welte883340c2018-02-28 18:59:29 +01004551 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004552 f_TfiUsfArrSet(tua, 7, 0);
4553 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4554 f_sleep(1.0);
4555
4556 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004557}
4558
4559/* Send DATA.req on invalid timeslot */
4560testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004561 var TfiUsfArr tua := f_TfiUsfArrInit();
4562 var octetstring data := '0000'O & f_rnd_octstring(21);
4563
4564 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004565
Harald Welte883340c2018-02-28 18:59:29 +01004566 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004567 f_TfiUsfArrSet(tua, 7, 0);
4568 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4569 f_sleep(1.0);
4570
4571 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004572}
4573
4574/* Send DATA.req on timeslot that hasn't been activated */
4575testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004576 var TfiUsfArr tua := f_TfiUsfArrInit();
4577 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004578
Harald Welte7162a612019-05-26 12:56:09 +02004579 f_virtphy_common();
4580
4581 f_TfiUsfArrSet(tua, 7, 0);
4582 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4583 f_sleep(1.0);
4584
4585 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004586}
4587
Harald Weltead033dc2019-05-25 17:28:16 +02004588private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004589 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4590 boolean wait_rts := true)
4591runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004592 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004593 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004594
4595 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004596 if (wait_rts) {
4597 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4598 } else {
4599 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4600 }
Harald Weltead033dc2019-05-25 17:28:16 +02004601
4602 T.start;
4603 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004604 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004605 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4606 setverdict(pass);
4607 }
Harald Welte7162a612019-05-26 12:56:09 +02004608 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4609 setverdict(fail, "Received unexpected ", rx_dl);
4610 }
Harald Weltead033dc2019-05-25 17:28:16 +02004611 [] L1CTL.receive {
4612 repeat;
4613 }
Harald Welte7162a612019-05-26 12:56:09 +02004614 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004615 setverdict(fail, "Timeout waiting for ", data);
4616 }
Harald Welte7162a612019-05-26 12:56:09 +02004617 [not expect_data] T.timeout {
4618 setverdict(pass);
4619 }
Harald Weltead033dc2019-05-25 17:28:16 +02004620 }
4621}
4622
4623private function f_disable_dynamic_ts() runs on test_CT
4624{
4625 f_init_vty_bsc();
4626 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4627 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4628 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4629 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004630 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004631}
4632
4633private function f_virtphy_common() runs on test_CT {
4634 f_disable_dynamic_ts();
4635 f_init_l1ctl();
4636 f_l1_tune(L1CTL);
4637}
4638
4639testcase TC_pcu_data_req_pdtch() runs on test_CT {
4640 var TfiUsfArr tua := f_TfiUsfArrInit();
4641 var octetstring data := '0000'O & f_rnd_octstring(21);
4642
4643 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004644
Harald Welte883340c2018-02-28 18:59:29 +01004645 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004646 f_TfiUsfArrSet(tua, 7, 0);
4647 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4648 f_sleep(1.0);
4649
4650 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004651}
4652
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004653/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004654testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004655 var TfiUsfArr tua := f_TfiUsfArrInit();
4656 var octetstring data := '0000'O & f_rnd_octstring(21);
4657
4658 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004659
Harald Welte883340c2018-02-28 18:59:29 +01004660 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004661 f_TfiUsfArrSet(tua, 7, 0);
4662 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4663 f_sleep(1.0);
4664
4665 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004666}
4667
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004668private function f_TC_pcu_ptcch_ul(uint16_t ra)
4669runs on test_CT {
4670 var template PCUIF_Message pcu_rach_ind;
4671 var PCUIF_send_data sd;
4672 var GsmFrameNumber fn;
4673 timer T;
4674
4675 /* Send an Access Burst on PTCCH/U over the Um-interface */
4676 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4677 chan_nr := ts_RslChanNr_PDCH(7),
4678 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4679
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004680 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4681 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004682
4683 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4684 T.start(52.0 * 4.615 / 1000.0);
4685 alt {
4686 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4687 log("Rx an Access Burst on the PCU interface: ", sd.data);
4688 setverdict(pass);
4689 T.stop;
4690 }
4691 [] PCU.receive { repeat; }
4692 [] T.timeout {
4693 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4694 /* Keep going, that's not the end of the world */
4695 }
4696 }
4697}
4698
4699testcase TC_pcu_ptcch() runs on test_CT {
4700 var L1ctlDlMessage dl;
4701 var octetstring data;
4702 timer T;
4703
4704 f_init_pcu_test();
4705 f_init_l1ctl();
4706 f_l1_tune(L1CTL);
4707
4708 /* Activate PDCH channel on TS7 */
4709 f_TC_pcu_act_req(0, 0, 7, true);
4710
4711 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004712 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004713 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4714 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004715 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004716
4717 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4718 for (var integer i := 0; i < 16; i := i + 1) {
4719 log("Sending an Access Burst towards the L1CTL interface");
4720 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4721 }
4722
4723 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4724 data := f_rnd_octstring(23);
4725
4726 /* Verify PTCCH/D: send a random data block, make sure it's received */
4727 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4728 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4729
4730 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4731 * let's give it more time in case if we miss the beginning. */
4732 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4733 alt {
4734 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4735 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4736 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4737 frame := data)) -> value dl {
4738 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4739 setverdict(pass);
4740 T.stop;
4741 }
4742 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4743 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4744 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4745 l2_data := data)) -> value dl {
4746 log("Rx PTCCH/D data block on L1CTL: ", dl);
4747 setverdict(pass);
4748 T.stop;
4749 }
4750 [] L1CTL.receive { repeat; }
4751 [] T.timeout {
4752 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4753 }
4754 }
4755}
4756
Harald Welte883340c2018-02-28 18:59:29 +01004757/* Send AGCH from PCU; check it appears on Um side */
4758testcase TC_pcu_data_req_agch() runs on test_CT {
4759 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004760 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004761 f_init_l1ctl();
4762 f_l1_tune(L1CTL);
4763
4764 f_TC_pcu_act_req(0, 0, 7, true);
4765 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4766
4767 T.start;
4768 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004769 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004770 setverdict(pass);
4771 }
4772 [] L1CTL.receive { repeat; }
4773 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004775 }
4776 }
4777}
4778
Harald Welte928622b2019-05-26 13:22:59 +02004779/* Send AGCH from PCU; check it appears on Um side */
4780testcase TC_pcu_data_req_pch() runs on test_CT {
4781 timer T := 3.0;
4782 f_init_pcu_test();
4783 f_init_l1ctl();
4784 f_l1_tune(L1CTL);
4785
4786 f_TC_pcu_act_req(0, 0, 7, true);
4787 /* three characters prefix: last 3 digits of IMSI as ASCII */
4788 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4789
4790 T.start;
4791 alt {
4792 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4793 setverdict(pass);
4794 }
4795 [] L1CTL.receive { repeat; }
4796 [] T.timeout {
4797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4798 }
4799 }
4800}
4801
Harald Welte883340c2018-02-28 18:59:29 +01004802/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4803testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4804 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004805 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004806 f_init_l1ctl();
4807 f_l1_tune(L1CTL);
4808
4809 /* append 3 last imsi digits so BTS can compute pagng group */
4810 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4811
4812 timer T := 0.5;
4813 T.start;
4814 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004815 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004816 /* TODO: verify paging group */
4817 setverdict(pass);
4818 }
4819 [] L1CTL.receive { repeat; }
4820 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004822 }
4823 }
4824}
4825
4826/* Send RACH from Um side, expect it to show up on PCU socket */
4827testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004828 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004829 f_init_l1ctl();
4830 f_l1_tune(L1CTL);
4831
4832 var GsmFrameNumber fn_last := 0;
4833 for (var integer i := 0; i < 1000; i := i+1) {
4834 var OCT1 ra := f_rnd_ra_ps();
4835 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4836 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004838 }
4839 fn_last := fn;
4840
4841 timer T := 2.0;
4842 T.start;
4843 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004844 [] 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 +01004845 T.stop;
4846 }
4847 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004849 }
4850 [] PCU.receive { repeat; }
4851 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004853 }
4854 }
4855 }
4856 setverdict(pass);
4857}
4858
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004859/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4860 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4861testcase TC_pcu_ext_rach_content() runs on test_CT {
4862 var template PCUIF_Message pcu_rach_ind;
4863 var GsmFrameNumber fn_last := 0;
4864 var L1ctlRachSynchSeq synch_seq;
4865 var PCUIF_BurstType pcu_bt;
4866 var GsmFrameNumber fn;
4867 var BIT11 ra11;
4868
4869 f_init_pcu_test();
4870 f_init_l1ctl();
4871 f_l1_tune(L1CTL);
4872
4873 for (var integer i := 0; i < 1000; i := i+1) {
4874 /* We need to test both TS1 & TS2 */
4875 if (i rem 2 == 0) {
4876 synch_seq := RACH_SYNCH_SEQ_TS1;
4877 pcu_bt := BURST_TYPE_1;
4878 } else {
4879 synch_seq := RACH_SYNCH_SEQ_TS2;
4880 pcu_bt := BURST_TYPE_2;
4881 }
4882
4883 ra11 := f_rnd_ra11_ps();
4884 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4885 if (fn == fn_last) {
4886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4887 "Two RACH in same FN?!?");
4888 }
4889 fn_last := fn;
4890
4891 /* Compose the expected message */
4892 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004893 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004894 ra := bit2int(ra11),
4895 is_11bit := 1,
4896 burst_type := pcu_bt,
4897 fn := fn);
4898
4899 timer T := 2.0;
4900 T.start;
4901 alt {
4902 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4903 T.stop;
4904 }
4905 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4907 }
4908 [] PCU.receive { repeat; }
4909 [] T.timeout {
4910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4911 }
4912 }
4913 }
4914 setverdict(pass);
4915}
4916
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004917private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4918runs on test_CT {
4919 var template PCUIF_send_data sdt;
4920 var PCUIF_send_data sd;
4921 var int16_t lqual_cb;
4922 timer T := 1.0;
4923
4924 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4925 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4926
4927 /* Send a random PDTCH frame over Um */
4928 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4929 '0000'O & f_rnd_octstring(21)));
4930
4931 T.start;
4932 alt {
4933 /* If expected link quality is above the threshold */
4934 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4935 lqual_cb := sd.data.u.data_ind.lqual_cb;
4936 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4937
4938 /* Make sure the actual link quality matches the expected value */
4939 if (not match(lqual_cb, lqual_cb_exp)) {
4940 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4941 "expected value ", lqual_cb_exp));
4942 } else {
4943 setverdict(pass);
4944 }
4945 }
4946 /* If expected link quality is below the threshold */
4947 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4949 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4950 }
4951 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4952 [] PCU.receive { repeat; }
4953 [lqual_cb_exp < thresh] T.timeout {
4954 log("Rx nothing, as expected");
4955 setverdict(pass);
4956 }
4957 [lqual_cb_exp >= thresh] T.timeout {
4958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4959 "Timeout waiting for PCUIF_DATA.ind");
4960 }
4961 }
4962}
4963
4964/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4965testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4966 f_init_pcu_test();
4967 PCU.clear;
4968
4969 f_init_l1ctl();
4970 f_l1_tune(L1CTL);
4971
4972 /* Activate a PDCH channel on TS7 */
4973 f_TC_pcu_act_req(0, 0, 7, true);
4974
4975 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004976 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004977 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4978 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004979 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004980
4981 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4982 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4983 var TrxcMessage ret;
4984
4985 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4986 valueof(ts_TRXC_FAKE_CI(i)));
4987
4988 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4989 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4990 }
4991}
4992
Harald Welte883340c2018-02-28 18:59:29 +01004993/* Send PAGING via RSL, expect it to shw up on PCU socket */
4994testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004995 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004996
4997 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004998 var MobileIdentityLV mi_lv;
4999 var octetstring mi_lv_enc;
5000 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005001 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005002
Harald Welte883340c2018-02-28 18:59:29 +01005003 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005004 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005005 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005006 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005007 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005008
5009 /* Fancy encoding for PCUIF */
5010 mi_lv := valueof(ts_MI_LV(mi));
5011 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5012 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005013
5014 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005015 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005016 T.start;
5017 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005018 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005019 }
5020 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005022 }
5023 [] PCU.receive { repeat; }
5024 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005026 }
5027 }
5028 }
5029 setverdict(pass);
5030}
5031
Harald Welted66c9b82019-05-25 09:03:15 +02005032/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5033testcase TC_pcu_time_ind() runs on test_CT {
5034 var PCUIF_send_data pcu_sd;
5035 var integer num_time_ind := 0;
5036 var integer first_fn, last_fn;
5037 var float test_duration := 5.0;
5038 timer T;
5039
5040 f_init_pcu_test();
5041 f_TC_pcu_act_req(0, 0, 7, true);
5042
5043 PCU.clear;
5044 T.start(test_duration);
5045 alt {
5046 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5047 num_time_ind := num_time_ind + 1;
5048 if (not isbound(first_fn)) {
5049 first_fn := pcu_sd.data.u.time_ind.fn;
5050 }
5051 last_fn := pcu_sd.data.u.time_ind.fn;
5052 repeat;
5053 }
5054 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5055 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5056 repeat;
5057 }
5058 [] PCU.receive {
5059 repeat;
5060 }
5061 [] T.timeout {}
5062 }
5063 var integer fn_expired := last_fn - first_fn;
5064 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5065
5066 /* verify the number of frames expired matches our expectation */
5067 const float c_GSM_FN_DURATION_MS := 4.61538;
5068 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005069 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005070 if (not match(fn_expired, t_fn_expected)) {
5071 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5072 }
5073
5074 /* There are three TIME.ind in every fn MOD 13 */
5075 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5076 /* Add some tolerance */
5077 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5078 if (not match(num_time_ind, t_time_ind_exp)) {
5079 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5080 }
5081
5082 setverdict(pass);
5083}
5084
Harald Welte4832c862019-05-25 14:57:18 +02005085/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5086testcase TC_pcu_rts_req() runs on test_CT {
5087 var PCUIF_send_data pcu_sd;
5088 var integer first_fn, last_fn;
5089 var integer num_rts_pdtch := 0;
5090 var integer num_rts_ptcch := 0;
5091 var float test_duration := 5.0;
5092 timer T;
5093
5094 f_init_pcu_test();
5095 f_TC_pcu_act_req(0, 0, 7, true);
5096
5097 PCU.clear;
5098 T.start(test_duration);
5099 alt {
5100 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5101 -> value pcu_sd {
5102 num_rts_pdtch := num_rts_pdtch + 1;
5103 if (not isbound(first_fn)) {
5104 first_fn := pcu_sd.data.u.rts_req.fn;
5105 }
5106 last_fn := pcu_sd.data.u.rts_req.fn;
5107 repeat;
5108 }
5109 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5110 -> value pcu_sd {
5111 num_rts_ptcch := num_rts_ptcch + 1;
5112 if (not isbound(first_fn)) {
5113 first_fn := pcu_sd.data.u.rts_req.fn;
5114 }
5115 last_fn := pcu_sd.data.u.rts_req.fn;
5116 repeat;
5117 }
5118 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5119 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5120 repeat;
5121 }
5122 [] PCU.receive {
5123 repeat;
5124 }
5125 [] T.timeout {}
5126 }
5127 var integer fn_expired := last_fn - first_fn;
5128 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5129 ", num_rts_ptcch=", num_rts_ptcch);
5130
5131 /* verify the number of frames expired matches our expectation */
5132 const float c_GSM_FN_DURATION_MS := 4.61538;
5133 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005134 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005135 if (not match(fn_expired, t_fn_expected)) {
5136 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5137 }
5138
5139 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5140 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5141 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5142 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5143 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5144 t_ptcch_exp);
5145 }
5146
5147 /* We have 12 PDTCH blocks every 52-multiframe */
5148 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5149 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5150 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5151 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5152 t_pdtch_exp);
5153 }
5154
5155 setverdict(pass);
5156}
5157
Harald Welte07bd2d22019-05-25 11:03:30 +02005158/* test for generating Abis side OML ALERT from the PCU */
5159testcase TC_pcu_oml_alert() runs on test_CT {
5160 var PCUIF_send_data pcu_sd;
5161 var integer num_time_ind := 0;
5162 var integer first_fn, last_fn;
5163 var float test_duration := 5.0;
5164 timer T;
5165
5166 f_init_pcu_test();
5167 f_TC_pcu_act_req(0, 0, 7, true);
5168
5169 /* re-connect CTRL port from BTS to BSC */
5170 f_ipa_ctrl_stop();
5171 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5172
5173 /* Send that OML Alert */
5174 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5175
5176 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5177 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5178 setverdict(pass);
5179}
5180
Harald Welteeaa9a862019-05-26 23:01:08 +02005181/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5182private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5183 var PCUIF_Message first_info;
5184 var integer pcu_conn_id := -1;
5185 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5186 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5187 var OCT4 tlli := '01020304'O;
5188 var OCT1 cause := '23'O;
5189 timer T := 5.0;
5190
5191 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5192
5193 f_l1_tune(L1CTL);
5194 RSL.clear;
5195
5196 f_est_dchan();
5197 L1CTL.clear;
5198
5199 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5200
5201 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5202 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5203 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5204
5205 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5206 T.start;
5207 alt {
5208 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5209 setverdict(pass);
5210 }
5211 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5212 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5213 }
5214 [] PCU.receive {
5215 repeat;
5216 }
5217 [] T.timeout {
5218 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5219 }
5220 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005221
5222 /* release the channel */
5223 f_rsl_chan_deact();
5224 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5225 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005226}
5227testcase TC_pcu_rr_suspend() runs on test_CT {
5228 var ConnHdlrPars pars;
5229 var ConnHdlr vc_conn;
5230
5231 f_init();
5232
5233 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5234 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5235 vc_conn.done;
5236}
Harald Welte07bd2d22019-05-25 11:03:30 +02005237
Harald Weltea2e0e942019-05-27 18:12:53 +02005238/* Ensure that PCUIF socket can accept only a single connection */
5239testcase TC_pcu_socket_connect_multi() runs on test_CT {
5240 timer T := 5.0;
5241
5242 /* this (among other things) establishes the first connection to the PCUIF socket */
5243 f_init();
5244
5245 /* try to establish a second connection, expect it to fail */
5246 PCU.send(UD_connect:{mp_pcu_socket, -1});
5247 T.start;
5248 alt {
5249 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5250 setverdict(pass);
5251 }
5252 [] PCU.receive(UD_connect_result:?) {
5253 setverdict(fail, "Unexpected unix domain connect result");
5254 }
5255 [] T.timeout {
5256 setverdict(pass);
5257 }
5258 }
5259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5260}
5261
Harald Weltec8effb72019-05-27 18:23:04 +02005262/* Ensure that PCUIF socket can disconnect + reconnect */
5263testcase TC_pcu_socket_reconnect() runs on test_CT {
5264 /* this (among other things) establishes the first connection to the PCUIF socket */
5265 f_init();
5266
5267 f_sleep(1.0);
5268
5269 f_pcuif_close(PCU, g_pcu_conn_id);
5270 g_pcu_conn_id := -1;
5271
5272 f_sleep(1.0);
5273
5274 /* re-connect */
5275 PCU.clear;
5276 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5277 setverdict(pass);
5278
5279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5280}
5281
Harald Weltebe030482019-05-27 22:29:35 +02005282/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005283private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5284runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005285 var L1ctlDlMessage l1_dl;
5286 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005287 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005288 timer T := 5.0;
5289 T.start;
5290 alt {
5291 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005292 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5293 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005294 repeat;
5295 }
5296 }
5297 [] pt.receive {
5298 repeat;
5299 }
5300 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5302 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005303 }
5304 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005305 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005306}
5307
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005308/* Check if GPRS Indicator is present in RR System Information of a given type */
5309private function f_si_has_gprs_indicator(RrMessageType si_type)
5310runs on test_CT return boolean {
5311 var SystemInformation si := f_get_si(L1CTL, si_type);
5312
5313 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005314 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005315 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005316 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005317 }
5318
5319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5320 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005321}
5322
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005323/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5324private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5325runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005326 /* don't call f_init() as this would connect PCU socket */
5327 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005328
5329 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005330 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005331 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005332
5333 f_init_l1ctl();
5334 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005335 f_sleep(2.0);
5336 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005337
5338 if (f_si_has_gprs_indicator(si_type)) {
5339 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005340 } else {
5341 setverdict(pass);
5342 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005343
Harald Weltebe030482019-05-27 22:29:35 +02005344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5345}
5346
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005347testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5348 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5349}
Harald Weltebe030482019-05-27 22:29:35 +02005350
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005351testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5352 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5353}
5354
5355/* Ensure that GPRS capability is advertised after PCU socket connect */
5356private function f_TC_pcu_socket_connect(RrMessageType si_type)
5357runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005358 /* this (among other things) establishes the first connection to the PCUIF socket */
5359 f_init();
5360 f_init_l1ctl();
5361 f_l1_tune(L1CTL);
5362
5363 f_sleep(2.0);
5364 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005365
5366 if (not f_si_has_gprs_indicator(si_type)) {
5367 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005368 } else {
5369 setverdict(pass);
5370 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005371
Harald Weltebe030482019-05-27 22:29:35 +02005372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5373}
5374
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005375testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5376 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5377}
Harald Weltebe030482019-05-27 22:29:35 +02005378
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005379testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5380 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5381}
5382
5383/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5384private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5385runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005386 /* this (among other things) establishes the first connection to the PCUIF socket */
5387 f_init();
5388 f_init_l1ctl();
5389 f_l1_tune(L1CTL);
5390
5391 f_pcuif_close(PCU, g_pcu_conn_id);
5392 g_pcu_conn_id := -1;
5393
5394 f_sleep(1.0);
5395
5396 /* re-connect */
5397 PCU.clear;
5398 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5399
5400 f_sleep(2.0);
5401 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005402
5403 if (f_si_has_gprs_indicator(si_type)) {
5404 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005405 } else {
5406 setverdict(pass);
5407 }
5408
5409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5410}
5411
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005412testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5413 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5414}
5415
5416testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5417 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5418}
5419
Oliver Smithf5239c72019-08-28 10:01:25 +02005420/* 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) */
5421testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5422 var SystemInformation si3 := valueof(ts_SI3_default);
5423
5424 f_init();
5425
5426 /* Verify cell_id */
5427 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5428 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5429 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005430 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5431 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5432 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005433 }
5434
5435 /* Verify LAC */
5436 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5437 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5438 if (lac_si3 != lac_pcu) {
5439 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5440 }
5441
5442 setverdict(pass);
5443}
Harald Welted66c9b82019-05-25 09:03:15 +02005444
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005445/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5446testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5447 var PCUIF_info_ind info_ind;
5448 var ConnHdlrPars pars;
5449
5450 f_init();
5451
5452 info_ind := g_pcu_last_info.u.info_ind;
5453
5454 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5455 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5456 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5457 /* Skip inactive timeslots */
5458 continue;
5459 }
5460
5461 pars := valueof(t_Pars(t_RslChanNr_PDCH(tn), ts_RSL_ChanMode_SIGN));
5462 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
5463 { f_resolve_fh_params(pars); }
5464
5465 var template PCUIF_InfoTrxTs tr_ts;
5466 if (ispresent(pars.maio_hsn)) {
5467 tr_ts := tr_PCUIF_InfoTrxTsH1(
5468 hsn := pars.maio_hsn.hsn,
5469 maio := pars.maio_hsn.maio,
5470 ma := f_pad_bit(pars.ma_map.ma, 64, '0'B));
5471 } else {
5472 tr_ts := tr_PCUIF_InfoTrxTsH0;
5473 }
5474
5475 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5476 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5477 if (not match(ts, tr_ts)) {
5478 setverdict(fail, "Hopping parameters do not match: ",
5479 "received ", ts, " vs expected ", tr_ts);
5480 } else {
5481 setverdict(pass);
5482 }
5483 }
5484 }
5485}
5486
Harald Welte3d04ae62018-04-04 20:29:05 +02005487/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005488 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005489 ***********************************************************************/
5490
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005491private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5492 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005493runs on ConnHdlr {
5494 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005495
5496 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005497 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005498 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5499 repeat;
5500 }
5501 }
5502}
5503
5504private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5505runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005506 /* Expect BTS to immediately acknowledge activation as PDCH */
5507 PCU.clear;
5508 f_rsl_chan_act(g_pars.chan_mode);
5509 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005510 timer T_wait := 2.0;
5511 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005512 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005513 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005514 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005515 [] T_wait.timeout {
5516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5517 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5518 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005519 }
5520 /* try to activate this PDCH from the PCU point of view */
5521 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5522 /* FIXME: is there a response? */
5523}
5524
5525private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5526runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005527 /* Send RSL CHAN REL (deactivate) */
5528 PCU.clear;
5529 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5530 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005531 timer T_wait := 2.0;
5532 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005533 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005534 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005535 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005536 [] T_wait.timeout {
5537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5538 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5539 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005540 }
5541 /* Emulate PCU asking BTS to deactivate PDCH */
5542 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5543 alt {
5544 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5545 setverdict(pass);
5546 }
5547 [] RSL.receive { repeat; }
5548 }
5549}
5550
5551/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005552private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005553 var PCUIF_Message first_info;
5554 var integer ts_nr := g_chan_nr.tn;
5555 var integer trx_nr := 0;
5556 var integer bts_nr := 0;
5557 var integer pcu_conn_id := -1;
5558
5559 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5560
5561 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5562 f_sleep(3.0);
5563 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5564 setverdict(pass);
5565}
5566testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5567 var ConnHdlrPars pars;
5568 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005569 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005570
5571 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5572 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5573 vc_conn.done;
5574}
5575
5576/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005577private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005578 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005579 var integer pcu_conn_id := -1;
5580
5581 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5582
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005583 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5584 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5585 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005586 setverdict(pass);
5587}
5588testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5589 var ConnHdlrPars pars;
5590 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005591 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005592
5593 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5594 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5595 vc_conn.done;
5596}
5597
5598/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005599private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005600 var PCUIF_Message first_info;
5601 var integer ts_nr := g_chan_nr.tn;
5602 var integer trx_nr := 0;
5603 var integer bts_nr := 0;
5604 var integer pcu_conn_id := -1;
5605
5606 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5607
5608 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005609 /* Send a second Chan Activ and expect it to be NACKed */
5610 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5611 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005612 setverdict(pass);
5613}
5614testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5615 var ConnHdlrPars pars;
5616 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005617 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005618
5619 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5620 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5621 vc_conn.done;
5622}
5623
5624/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005625private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005626 var PCUIF_Message first_info;
5627 var integer ts_nr := g_chan_nr.tn;
5628 var integer trx_nr := 0;
5629 var integer bts_nr := 0;
5630 var integer pcu_conn_id := -1;
5631 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5632
5633 /* register for the TCH/F channel number */
5634 f_rslem_register(0, chan_nr);
5635
5636 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5637
5638 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5639 "RSL CHAN ACT");
5640 setverdict(pass);
5641}
5642testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5643 var ConnHdlrPars pars;
5644 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005645 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005646
5647 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5648 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5649 vc_conn.done;
5650}
5651
5652/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005653private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005654 var PCUIF_Message first_info;
5655 var integer ts_nr := g_chan_nr.tn;
5656 var integer trx_nr := 0;
5657 var integer bts_nr := 0;
5658 var integer pcu_conn_id := -1;
5659 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5660 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5661
5662 /* register for the TCH/H channel numbers */
5663 f_rslem_register(0, chan_nr[0]);
5664 f_rslem_register(0, chan_nr[1]);
5665
5666 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5667
5668 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5669 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5670 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5671 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5672 setverdict(pass);
5673}
5674testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5675 var ConnHdlrPars pars;
5676 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005677 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005678
5679 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5680 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5681 vc_conn.done;
5682}
5683
Harald Welte9bbbfb52018-04-05 09:33:19 +02005684/***********************************************************************
5685 * IPA Style Dynamic Timeslot Support
5686 ***********************************************************************/
5687
5688private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5689runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005690 /* Expect BTS to immediately acknowledge activation as PDCH */
5691 PCU.clear;
5692 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5693 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005694 timer T_wait := 2.0;
5695 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005696 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005697 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005698 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005699 [] T_wait.timeout {
5700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5701 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5702 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005703 }
5704 /* try to activate this PDCH from the PCU point of view */
5705 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5706 /* FIXME: is there a response? */
5707
5708 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5709}
5710
5711private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5712runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005713 /* Send RSL CHAN REL (deactivate) */
5714 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5715 PCU.clear;
5716 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005717 timer T_wait := 2.0;
5718 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005719 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005720 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005721 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005722 [] T_wait.timeout {
5723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5724 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5725 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005726 }
5727 /* Emulate PCU asking BTS to deactivate PDCH */
5728 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5729 alt {
5730 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5731 setverdict(pass);
5732 }
5733 [] RSL.receive { repeat; }
5734 }
5735}
5736
5737/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005738private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005739 var PCUIF_Message first_info;
5740 var integer ts_nr := g_chan_nr.tn;
5741 var integer trx_nr := 0;
5742 var integer bts_nr := 0;
5743 var integer pcu_conn_id := -1;
5744
5745 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5746
5747 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5748 f_sleep(3.0);
5749 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5750
5751 setverdict(pass);
5752
5753}
5754testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5755 var ConnHdlrPars pars;
5756 var ConnHdlr vc_conn;
5757 f_init();
5758
5759 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5760 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5761 vc_conn.done;
5762}
5763
5764/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005765private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005766 var PCUIF_Message first_info;
5767 var integer ts_nr := g_chan_nr.tn;
5768 var integer trx_nr := 0;
5769 var integer bts_nr := 0;
5770 var integer pcu_conn_id := -1;
5771
5772 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5773
5774 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5775 "RSL CHAN ACT");
5776 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5777 "RF CHAN REL", true);
5778 setverdict(pass);
5779}
5780testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5781 var ConnHdlrPars pars;
5782 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005783 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005784
5785 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5786 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5787 vc_conn.done;
5788}
5789
5790/* 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 +07005791private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005792 var PCUIF_Message first_info;
5793 var integer ts_nr := g_chan_nr.tn;
5794 var integer trx_nr := 0;
5795 var integer bts_nr := 0;
5796 var integer pcu_conn_id := -1;
5797
5798 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5799
5800 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5801 "RSL CHAN ACT");
5802
5803 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5804 alt {
5805 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5806 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005808 }
5809 [] RSL.receive { repeat; }
5810 }
5811
5812 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5813 "RF CHAN REL", true);
5814 setverdict(pass);
5815}
5816testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5817 var ConnHdlrPars pars;
5818 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005819 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005820
5821 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5822 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5823 vc_conn.done;
5824}
5825
5826/* 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 +07005827private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005828 var PCUIF_Message first_info;
5829 var integer ts_nr := g_chan_nr.tn;
5830 var integer trx_nr := 0;
5831 var integer bts_nr := 0;
5832 var integer pcu_conn_id := -1;
5833
5834 /* register for the TCH/F channel number */
5835 f_rslem_register(0, g_chan_nr);
5836
5837 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5838
5839 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5840
5841 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5842 "RSL CHAN ACT");
5843
5844 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5845
5846 setverdict(pass);
5847}
5848testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5849 var ConnHdlrPars pars;
5850 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005851 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005852
5853 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5854 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5855 vc_conn.done;
5856}
5857
5858
Harald Welte0472ab42018-03-12 15:02:26 +01005859/***********************************************************************
5860 * LAPDm / RLL related
5861 ***********************************************************************/
5862
5863private function f_tx_lapdm(template (value) LapdmFrame l,
5864 template (value) RslLinkId link_id) runs on ConnHdlr {
5865 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005866 var template (value) SacchL1Header l1h;
5867
5868 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005869 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005870 /* Compose dummy L1 header */
5871 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5872 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 +02005873 } else {
5874 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005875 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 +01005876 }
Harald Welte0472ab42018-03-12 15:02:26 +01005877}
5878
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005879private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005880 uint3_t sapi,
5881 RslLinkId link_id,
5882 octetstring l3,
5883 boolean exp
5884}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005885private type record of RllTestCase RllTestCases;
5886private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5887 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005888 sapi := sapi,
5889 link_id := id,
5890 l3 := l3,
5891 exp := exp
5892}
5893
5894/* execute the same callback function with a set of different parameters (tcs) on a
5895 * variety of logical channels */
5896private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5897 var ConnHdlrPars pars;
5898 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005899 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005900
5901 /* test on each of the channels we have */
5902 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5903 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5904
5905 /* test each of the test cases on the current channel */
5906 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5907 pars.spec.rll := tcs[j];
5908 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5909 vc_conn := f_start_handler(fn, pars);
5910 vc_conn.done;
5911 }
5912 }
5913
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005915}
5916
5917/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5918private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5919 var RllTestCase tc := g_pars.spec.rll;
5920 timer T := 3.0;
5921
5922 f_l1_tune(L1CTL);
5923 RSL.clear;
5924
5925 /* activate the logical channel */
5926 f_est_dchan();
5927 L1CTL.clear;
5928
5929 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5930 T.start;
5931 alt {
5932 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5933 if (tc.exp) {
5934 setverdict(pass);
5935 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005937 }
5938 }
5939 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5940 if (tc.exp) {
5941 setverdict(pass);
5942 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005944 }
5945 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005946 /* We also expect to receive the measurements */
5947 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005948 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005950 }
5951 [not tc.exp] T.timeout {
5952 setverdict(pass);
5953 }
5954 }
5955
5956 f_rsl_chan_deact();
5957 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5958 f_rslem_unregister(0, g_chan_nr);
5959}
5960testcase TC_rll_est_ind() runs on test_CT {
5961 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005962 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005963 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005964 /* normal SAPI0 establishment */
5965 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005966 /* SAPI 3 doesn't support contention resolution */
5967 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5968 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5969 /* normal SAPI3 establishment on main DCCH */
5970 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5971 /* normal SAPI3 establishment on SACCH */
5972 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5973 };
5974 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5975}
5976
5977/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5978private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5979 var RllTestCase tc := g_pars.spec.rll;
5980 var L1ctlDlMessage dl;
5981 timer T := 3.0;
5982
5983 f_l1_tune(L1CTL);
5984 RSL.clear;
5985
5986 /* activate the logical channel */
5987 f_est_dchan();
5988 L1CTL.clear;
5989
5990 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5991 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5992 T.start;
5993 alt {
5994 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5995 var LapdmFrame lapdm;
5996 var octetstring l2 := dl.payload.data_ind.payload;
5997 if (dl.dl_info.link_id.c == SACCH) {
5998 /* remove L1 header */
5999 l2 := substr(l2, 2, lengthof(l2)-2);
6000 }
6001 lapdm.ab := dec_LapdmFrameAB(l2);
6002 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6003 setverdict(pass);
6004 } else {
6005 repeat;
6006 }
6007 }
6008 [] L1CTL.receive { repeat; }
6009 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006011 }
6012 }
6013
6014 f_rsl_chan_deact();
6015 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6016 f_rslem_unregister(0, g_chan_nr);
6017}
6018testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6019 var RllTestCases tcs := {
6020 /* normal SAPI3 establishment on main DCCH */
6021 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6022 };
6023 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6024}
6025testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6026 var RllTestCases tcs := {
6027 /* normal SAPI3 establishment on SACCH */
6028 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6029 }
6030 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6031}
6032
6033/* altstep to receive a LAPDm frame matching the given template */
6034private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6035 var L1ctlDlMessage dl;
6036 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6037 var LapdmFrame lapdm;
6038 var octetstring l2 := dl.payload.data_ind.payload;
6039 if (dl.dl_info.link_id.c == SACCH) {
6040 /* remove L1 header */
6041 l2 := substr(l2, 2, lengthof(l2)-2);
6042 }
6043 if (ischosen(exp.ab)) {
6044 lapdm.ab := dec_LapdmFrameAB(l2);
6045 } else if (ischosen(exp.b4)) {
6046 lapdm.b4 := dec_LapdmFrameB4(l2);
6047 } else if (ischosen(exp.bbis)) {
6048 lapdm.bbis := dec_LapdmFrameBbis(l2);
6049 }
6050 log("Rx LAPDm ", lapdm);
6051 if (match(lapdm, exp)) {
6052 setverdict(pass);
6053 } else {
6054 repeat;
6055 }
6056 }
6057 [] L1CTL.receive { repeat; }
6058}
6059private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6060 timer T := t;
6061 T.start;
6062 alt {
6063 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006065 }
6066 [] as_l1_exp_lapdm(exp);
6067 }
6068}
6069
6070/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6071private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6072 /* send SABM from MS -> BTS */
6073 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6074 /* expect RLL EST IND on Abis */
6075 alt {
6076 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6077 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6078 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006080 }
6081 [] RSL.receive { repeat; }
6082 }
6083 /* expect UA from BTS -> MS */
6084 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6085}
6086
6087/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6088private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6089 var RllTestCase tc := g_pars.spec.rll;
6090
6091 f_l1_tune(L1CTL);
6092 RSL.clear;
6093
6094 /* activate the logical channel */
6095 f_est_dchan();
6096 L1CTL.clear;
6097
6098 /* first establish the link-layer */
6099 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6100
6101 /* then send the DISC */
6102 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6103 /* ... and expect the REL IND on the RSL side */
6104 alt {
6105 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6106 setverdict(pass);
6107 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006108 /* We also expect to receive the measurements */
6109 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006110 }
6111
6112 /* release the channel */
6113 f_rsl_chan_deact();
6114 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6115 f_rslem_unregister(0, g_chan_nr);
6116}
6117testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6118 var RllTestCases tcs := {
6119 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6120 };
6121 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6122}
6123
6124testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6125 var RllTestCases tcs := {
6126 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6127 };
6128 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6129}
6130testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6131 var RllTestCases tcs := {
6132 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6133 };
6134 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6135}
6136testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6137 var RllTestCases tcs := {
6138 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6139 };
6140 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6141}
6142
6143/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6144private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6145 var RllTestCase tc := g_pars.spec.rll;
6146 f_l1_tune(L1CTL);
6147 RSL.clear;
6148
6149 /* activate the logical channel */
6150 f_est_dchan();
6151 L1CTL.clear;
6152
6153 /* first establish the link-layer */
6154 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6155
6156 /* then send the REL REQ via RSL */
6157 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6158 /* ... and expect the DISC on the Um side */
6159 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006160 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006161 /* FIXME: send a UA in resposne to the DISC */
6162 }
6163 }
6164
6165 /* release the channel */
6166 f_rsl_chan_deact();
6167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6168 f_rslem_unregister(0, g_chan_nr);
6169}
6170testcase TC_rll_rel_req() runs on test_CT {
6171 var RllTestCases tcs := {
6172 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6173 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6174 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6175 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6176 };
6177 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6178}
6179
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006180/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006181testcase TC_rll_data_req() runs on test_CT {
6182}
6183
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006184/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006185testcase TC_rll_data_ind() runs on test_CT {
6186}
6187
6188/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6189private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6190 var RllTestCase tc := g_pars.spec.rll;
6191
6192 f_l1_tune(L1CTL);
6193 RSL.clear;
6194
6195 f_est_dchan();
6196 L1CTL.clear;
6197
6198 /* Send UNITDATA REQ on RSL side */
6199 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6200 /* Expect it to arrive on the other side */
6201 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006202 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006203 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006204 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006205 }
6206
6207 /* release the channel */
6208 f_rsl_chan_deact();
6209 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6210 f_rslem_unregister(0, g_chan_nr);
6211}
6212testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6213 var octetstring l3 := f_rnd_octstring(15);
6214 var RllTestCases tcs := {
6215 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6216 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6217 };
6218 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6219}
6220testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6221 var octetstring l3 := f_rnd_octstring(19);
6222 var RllTestCases tcs := {
6223 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6224 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6225 };
6226 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6227}
6228
6229/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6230private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6231 var RllTestCase tc := g_pars.spec.rll;
6232
6233 f_l1_tune(L1CTL);
6234 RSL.clear;
6235
6236 f_est_dchan();
6237 L1CTL.clear;
6238
6239 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006240 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006241 /* Expdct RLL UNITDATA IND on RSL side */
6242 alt {
6243 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6244 setverdict(pass);
6245 }
6246 [] RSL.receive { repeat; }
6247 }
6248
6249 /* release the channel */
6250 f_rsl_chan_deact();
6251 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6252 f_rslem_unregister(0, g_chan_nr);
6253}
6254testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006255 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006256 var RllTestCases tcs := {
6257 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6258 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6259 };
6260 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6261}
6262testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6263 var octetstring l3 := f_rnd_octstring(18);
6264 var RllTestCases tcs := {
6265 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6266 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6267 };
6268 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6269}
6270
Harald Weltee613f962018-04-18 22:38:16 +02006271/***********************************************************************
6272 * Encryption Related
6273 ***********************************************************************/
6274
6275/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006276private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006277 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6278 if (link_id.c == SACCH) {
6279 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6280 } else {
6281 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6282 }
6283}
6284
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006285/* Expect (or not expect) other kinds of messages */
6286private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6287 [exp_any] RSL.receive { repeat; }
6288 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006290 }
6291}
6292
Harald Weltee613f962018-04-18 22:38:16 +02006293/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006294private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006295 RslLinkId link_id,
6296 octetstring l3,
6297 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006298 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006299) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006300 timer T := 3.0;
6301 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6302 T.start;
6303 /* Expect RLL UNITDATA IND on RSL side */
6304 alt {
6305 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6306 setverdict(pass);
6307 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006308 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006309 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006310 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006312 }
Harald Weltee613f962018-04-18 22:38:16 +02006313 }
6314}
6315
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006316/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6317private function f_data_mo(
6318 RslLinkId link_id,
6319 boolean p, uint3_t nr, uint3_t ns,
6320 octetstring l3,
6321 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006322 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006323) runs on ConnHdlr {
6324 timer T := 3.0;
6325 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6326 T.start;
6327 /* Expect RLL DATA IND on RSL side */
6328 alt {
6329 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6330 setverdict(pass);
6331 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006332 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006333 [] as_rsl_any_ind(exp_any);
6334 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006336 }
6337 }
6338}
6339
Harald Weltee613f962018-04-18 22:38:16 +02006340/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006341private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006342 f_l1_tune(L1CTL);
6343 f_est_dchan(true);
6344
6345 /* now we actually need to transmit some data both ways to check if the encryption works */
6346 var L1ctlDlMessage dl;
6347
Stefan Sperling603d98e2018-07-25 16:47:28 +02006348 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006349 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6350
6351 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6352 f_unitdata_mt(link_id, l3);
6353
6354 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6355 f_unitdata_mo(link_id, l3);
6356
6357 /* release the channel */
6358 f_rsl_chan_deact();
6359 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6360 f_rslem_unregister(0, g_chan_nr);
6361}
6362testcase TC_chan_act_a51() runs on test_CT {
6363 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6364 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6365 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6366}
6367testcase TC_chan_act_a52() runs on test_CT {
6368 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6369 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6370 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6371}
6372testcase TC_chan_act_a53() runs on test_CT {
6373 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6374 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6375 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6376}
6377
Eric Wildf1827a72019-05-28 17:37:35 +02006378/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6379 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 +07006380private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006381 f_l1_tune(L1CTL);
6382 f_est_dchan(true);
6383
6384 /* now we actually need to transmit some data both ways to check if the encryption works */
6385 var L1ctlDlMessage dl;
6386
6387 var octetstring l3 := f_rnd_octstring(20);
6388 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6389
6390 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6391 f_unitdata_mt(link_id, l3);
6392
6393 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6394 f_unitdata_mo(link_id, l3);
6395
6396 var RSL_Message rsl;
6397 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6398
6399 /* modify key to break proper encryption */
6400 g_pars.encr.key := f_rnd_octstring(8);
6401 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6402 rsl.ies := rsl.ies & { ei };
6403 RSL.send(rsl);
6404
6405 timer T0 := 1.0;
6406 T0.start;
6407 /* Expect RSL MODIFY ACK */
6408 alt {
6409 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6410 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6412 }
6413 [] T0.timeout {
6414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6415 }
6416 }
6417
6418 var octetstring l3msg := f_rnd_octstring(15);
6419 timer T1 := 3.0;
6420 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6421 due to broken encryption */
6422 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6423 T1.start;
6424 alt {
6425 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6427 }
6428 [] T1.timeout {
6429 setverdict(pass);
6430 }
6431 }
6432
6433 /* release the channel */
6434 f_rsl_chan_deact();
6435 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6436 f_rslem_unregister(0, g_chan_nr);
6437}
6438testcase TC_rsl_modify_encr() runs on test_CT {
6439 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6440 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6441 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6442}
Harald Weltee613f962018-04-18 22:38:16 +02006443
6444/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006445private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006446 /* L3 payload doesn't matter, as it is passed transparently */
6447 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6448 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6449 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6450
6451 f_l1_tune(L1CTL);
6452
6453 /* first establish a dedicated channel in the clear */
6454 f_est_dchan(false);
6455
6456 /* Establish ABM */
6457 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6458
6459 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6460 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6461 /* expect the L3 to arrive still unencrypted on the MS side */
6462 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6463
6464 /* configure L1 to apply ciphering */
6465 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6466 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6467
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006468 /* send first ciphered I-frame in response and expect it on RSL */
6469 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006470
6471 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6472 * and hence enable encryption also on the downlink */
6473
6474 /* expect bi-directional communication work in encrypted mode */
6475 f_unitdata_mo(link_id, f_rnd_octstring(15));
6476 f_unitdata_mt(link_id, f_rnd_octstring(15));
6477
6478 /* release the channel */
6479 f_rsl_chan_deact();
6480 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6481 f_rslem_unregister(0, g_chan_nr);
6482}
6483testcase TC_encr_cmd_a51() runs on test_CT {
6484 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6485 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6486 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6487}
6488testcase TC_encr_cmd_a52() runs on test_CT {
6489 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6490 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6491 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6492}
6493testcase TC_encr_cmd_a53() runs on test_CT {
6494 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6495 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6496 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6497}
6498
6499private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6500 var LapdmFrame lf;
6501 var octetstring reenc;
6502
6503 /* decode the LAPDm frame */
6504 if (ischosen(exp_match.ab)) {
6505 lf.ab := dec_LapdmFrameAB(enc);
6506 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006508 }
6509
6510 /* check if decoder result matches expectation */
6511 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006513 } else {
6514 log(name, ": matched");
6515 setverdict(pass);
6516 }
6517
6518 /* test if re-encoded frame equals original input */
6519 reenc := enc_LapdmFrame(lf);
6520 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006522 } else {
6523 setverdict(pass);
6524 }
6525}
6526
6527testcase TC_lapdm_selftest() runs on test_CT {
6528 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6529 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6530 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6531 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6532 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6533 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6534 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6535}
6536
Stefan Sperling4880be42018-08-07 18:12:59 +02006537/***********************************************************************
6538 * DTX Related (see GSM 05.08, section 8.3)
6539 ***********************************************************************/
6540
6541/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006542private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006543 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6544 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6545 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6546 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6547}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006548private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006549 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6550 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6551}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006552private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006553 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6554 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6555 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6556 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6557}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006558private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006559 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6560 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6561 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6562 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6563 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6564 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6565 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6566 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6567}
6568
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006569private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006570 var L1ctlDlMessage dl;
6571 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6572 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6573 var GsmFrameNumber first_fn;
6574 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006575 var integer nfill_frames_sacch := 0;
6576 var integer nfill_frames_nonsacch := 0;
6577 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006578 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6579 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006580 const integer frame_dtx_tchf_mod := 104;
6581 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6582 * which operates in terms of blocks rather than frames. */
6583 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6584 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006585 timer T := 5.0;
6586
6587 f_l1_tune(L1CTL);
6588 RSL.clear;
6589 L1CTL.clear;
6590
6591 /* activate TCHF signalling channel */
6592 f_est_dchan(false);
6593
6594 T.start;
6595 alt {
6596 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6597 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6598 var octetstring l2 := dl.payload.data_ind.payload;
6599
6600 if (is_first_frame) {
6601 is_first_frame := false;
6602 first_fn := dl.dl_info.frame_nr;
6603 }
6604
6605 if (dl.dl_info.link_id.c == SACCH) {
6606 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6607 if (not match(l2_fill_frame_sacch, l2)) {
6608 repeat;
6609 }
6610 } else if (not match(l2_fill_frame, l2)) {
6611 repeat;
6612 }
6613
6614 if (dtxd) {
6615 if (not f_g_chan_is_tchf()) {
6616 T.stop;
6617 f_rsl_chan_deact();
6618 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006619 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 +02006620 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006621 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006622 T.stop;
6623 f_rsl_chan_deact();
6624 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006625
6626 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6627 * 2 SACCH, 1 TCH/F */
6628 expected_fill_frames := 3;
6629
6630 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6631 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6632 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006634 } else {
6635 setverdict(pass);
6636 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006637 } else {
6638 if (dl.dl_info.link_id.c == SACCH) {
6639 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006640 repeat;
6641 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006642 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6643 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6644 * we should only see the subset of frames numbers which correspond to a block boundary.
6645 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6646 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6647 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6648 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6649 repeat;
6650 }
6651 }
6652 log("Received DTX TCH fill frame with bad frame number: ", fn,
6653 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6654 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6655 f_rsl_chan_deact();
6656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006658 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006659 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006660 if (dl.dl_info.link_id.c == SACCH) {
6661 nfill_frames_sacch := nfill_frames_sacch + 1;
6662 } else {
6663 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6664 }
6665 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006666 T.stop;
6667 if (f_g_chan_is_tchf()) {
6668 /* Without DTX we can expect 25 fill frames for every 104 frames.
6669 * (24 FACCH + 1 SACCH filling) */
6670 expected_fill_frames := 25;
6671 } else if (f_g_chan_is_tchh()) {
6672 /* We can expect 2 fill frames for every 104 frames. */
6673 expected_fill_frames := 2;
6674 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6675 /* We can expect 5 fill frames for every 104 frames. */
6676 expected_fill_frames := 5;
6677 } else {
6678 f_rsl_chan_deact();
6679 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006681 }
6682
6683 f_rsl_chan_deact();
6684 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006685
6686 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006687 setverdict(pass);
6688 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006689 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6690 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006692 }
6693 } else {
6694 repeat;
6695 }
6696 }
6697 }
6698 [] L1CTL.receive { repeat; }
6699 [] T.timeout {
6700 f_rsl_chan_deact();
6701 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006703 }
6704 }
6705}
6706
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006707private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006708 f_test_l2_fill_frames(false);
6709}
6710
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006711private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006712 f_test_l2_fill_frames(true);
6713}
6714
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006715private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006716 var ConnHdlr vc_conn;
6717 var ConnHdlrPars pars;
6718 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006719 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006720 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6721 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6722 if (dtxd) {
6723 if (i >= 4) { /* DTX is only allowed on TCH/F */
6724 break;
6725 }
6726 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6727 } else {
6728 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6729 }
6730 vc_conn.done;
6731 }
6732}
6733
6734/* Verify that L2 fill frames are sent on TCH in signaling mode if
6735 * there is nothing to transmit while DTX is disabled on downlink. */
6736testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6737 f_tch_sign_l2_fill_frame(false);
6738}
6739
6740/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6741 * there is nothing to transmit while DTX is enabled on downlink. */
6742testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6743 f_tch_sign_l2_fill_frame(true);
6744}
Harald Welte0472ab42018-03-12 15:02:26 +01006745
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006746testcase TC_chopped_ipa_ping() runs on test_CT {
6747 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6748}
6749
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006750testcase TC_chopped_ipa_payload() runs on test_CT {
6751 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6752}
6753
Harald Welte0472ab42018-03-12 15:02:26 +01006754/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6755/* protocol error as per 44.006 */
6756/* link layer failure (repetition of I-frame N200 times without ACK */
6757/* repetition of SABM or DISC N200 times without ACK */
6758/* receptiom of SABM in multi-frame established state */
6759
6760
Harald Welte68e495b2018-02-25 00:05:57 +01006761/* TODO Areas:
6762
6763* channel activation
6764** with BS_Power / MS_Power, bypassing power control loop
6765** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006766** with timing advance from initial activation on
6767* mode modify
6768** encryption
6769** multirate
6770* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006771** unsupported algorithm
6772* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006773* BS Power Control
6774* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006775* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006776* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006777** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006778* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006779** DATA_IND from BTS->PCU
6780** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006781
6782*/
Harald Welte70767382018-02-21 12:16:40 +01006783
6784control {
6785 execute( TC_chan_act_stress() );
6786 execute( TC_chan_act_react() );
6787 execute( TC_chan_deact_not_active() );
6788 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006789 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006790 execute( TC_sacch_filling() );
6791 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006792 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006793 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006794 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006795 execute( TC_sacch_chan_act_ho_async() );
6796 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006797 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006798 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006799 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006800 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006801 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006802 execute( TC_rach_load_idle_thresh0() );
6803 execute( TC_rach_load_idle_below_thresh() );
6804 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006805 execute( TC_meas_res_sign_tchf() );
6806 execute( TC_meas_res_sign_tchh() );
6807 execute( TC_meas_res_sign_sdcch4() );
6808 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006809 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006810 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006811 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006812 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006813 execute( TC_rsl_bs_pwr_static_ass() );
6814 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006815 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006816 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006817 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006818 execute( TC_rsl_ms_pwr_dyn_up() );
6819 execute( TC_rsl_ms_pwr_dyn_down() );
6820 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6821 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006822 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006823 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006824 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006825 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006826 execute( TC_paging_imsi_80percent() );
6827 execute( TC_paging_tmsi_80percent() );
6828 execute( TC_paging_imsi_200percent() );
6829 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006830 execute( TC_rsl_protocol_error() );
6831 execute( TC_rsl_mand_ie_error() );
6832 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006833 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006834 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006835 execute( TC_si_sched_2bis() );
6836 execute( TC_si_sched_2ter() );
6837 execute( TC_si_sched_2ter_2bis() );
6838 execute( TC_si_sched_2quater() );
6839 execute( TC_si_sched_13() );
6840 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006841 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006842 execute( TC_ipa_crcx_twice_not_active() );
6843 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006844 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006845 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006846
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006847 if (mp_pcu_socket != "") {
6848 execute( TC_pcu_act_req() );
6849 execute( TC_pcu_act_req_wrong_ts() );
6850 execute( TC_pcu_act_req_wrong_bts() );
6851 execute( TC_pcu_act_req_wrong_trx() );
6852 execute( TC_pcu_deact_req() );
6853 execute( TC_pcu_deact_req_wrong_ts() );
6854 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006855 if (mp_l1_supports_gprs) {
6856 execute( TC_pcu_data_req_pdtch() );
6857 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006858 execute( TC_pcu_data_req_wrong_bts() );
6859 execute( TC_pcu_data_req_wrong_trx() );
6860 execute( TC_pcu_data_req_wrong_ts() );
6861 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006862 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006863 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006864 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006865 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006866 execute( TC_pcu_data_req_imm_ass_pch() );
6867 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006868 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006869 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006870 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006871 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006872 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006873 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006874 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006875 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006876 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006877 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006878 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006879 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006880 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006881 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006882 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006883 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006884 execute( TC_dyn_osmo_pdch_act_deact() );
6885 execute( TC_dyn_osmo_pdch_double_act() );
6886 execute( TC_dyn_ipa_pdch_act_deact() );
6887 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6888
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006889 if (PCUIF_Types.mp_pcuif_version >= 10) {
6890 execute( TC_pcu_info_ind_fh_params() );
6891 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006892 } else {
6893 log("PCU socket path not available, skipping PCU tests");
6894 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006895
Harald Welte3d04ae62018-04-04 20:29:05 +02006896 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006897 execute( TC_dyn_osmo_pdch_tchf_act() );
6898 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006899 execute( TC_dyn_ipa_pdch_tchf_act() );
6900 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006901
6902 execute( TC_rll_est_ind() );
6903 execute( TC_rll_est_req_DCCH_3() );
6904 execute( TC_rll_est_req_ACCH_3() );
6905 execute( TC_rll_rel_ind_DCCH_0() );
6906 execute( TC_rll_rel_ind_DCCH_3() );
6907 execute( TC_rll_rel_ind_ACCH_0() );
6908 execute( TC_rll_rel_ind_ACCH_3() );
6909 execute( TC_rll_rel_req() );
6910 execute( TC_rll_unit_data_req_DCCH() );
6911 execute( TC_rll_unit_data_req_ACCH() );
6912 execute( TC_rll_unit_data_ind_DCCH() );
6913 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006914
6915 execute( TC_chan_act_a51() );
6916 execute( TC_chan_act_a52() );
6917 execute( TC_chan_act_a53() );
6918 execute( TC_encr_cmd_a51() );
6919 execute( TC_encr_cmd_a52() );
6920 execute( TC_encr_cmd_a53() );
6921
Harald Welteee25aae2019-05-19 14:32:37 +02006922 execute( TC_err_rep_wrong_mdisc() );
6923 execute( TC_err_rep_wrong_msg_type() );
6924 execute( TC_err_rep_wrong_sequence() );
6925
Harald Weltee613f962018-04-18 22:38:16 +02006926 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006927
6928 execute( TC_tch_sign_l2_fill_frame() );
6929 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006930
6931 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006932 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006933}
6934
6935
6936}