blob: 2b22ac44354625abc20e894d666606fbcb062525 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +01004import from General_Types all;
5import from GSM_Types all;
6import from GSM_RR_Types all;
7import from Osmocom_Types all;
8import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +01009import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010010import from L1CTL_PortType all;
11import from L1CTL_Types all;
12import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020013import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010014import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020015import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010016
17import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010018import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010019import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020020import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010021import from RSL_Emulation all;
22
23import from IPL4asp_Types all;
24import from TRXC_Types all;
25import from TRXC_CodecPort all;
26import from TRXC_CodecPort_CtrlFunct all;
27
Harald Welte883340c2018-02-28 18:59:29 +010028import from PCUIF_Types all;
29import from PCUIF_CodecPort all;
30
Harald Welte7484fc42018-02-24 14:09:45 +010031import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010032import from MobileL3_RRM_Types all;
33import from MobileL3_Types all;
34import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010035
Harald Welte8da48242018-02-27 20:41:32 +010036import from Osmocom_VTY_Functions all;
37import from TELNETasp_PortType all;
38
Harald Welte505cf9b2018-09-15 17:47:23 +030039friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020040friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030041
Harald Welte70767382018-02-21 12:16:40 +010042/* The tests assume a BTS with the following timeslot configuration:
43 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020044 * TS1 : TCH/F
45 * TS2 : TCH/F
46 * TS3 : TCH/F_PDCH (IPA Style)
47 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010048 * TS5 : TCH/H
49 * TS6 : SDCCH/8
50 * TS7 : PDCH
51 */
52
53modulepar {
54 charstring mp_rsl_ip := "127.0.0.2";
55 integer mp_rsl_port := 3003;
56 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070057 charstring mp_bts_trxc_ip := "127.0.0.1";
58 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010059 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020060 charstring mp_ctrl_ip := "127.0.0.1";
61 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020062 charstring mp_bsc_ctrl_ip := "127.0.0.1";
63 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020064 integer mp_tolerance_rxqual := 1;
65 integer mp_tolerance_rxlev := 3;
66 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020067 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020068 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020069 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020070 integer mp_ms_actual_ta_exp := 0;
71 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010072 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020073 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020074 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +020075 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
76 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +010077}
78
Harald Welte629cc6b2018-03-11 17:19:05 +010079type record of RslChannelNr ChannelNrs;
80
Harald Welte70767382018-02-21 12:16:40 +010081type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010082 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010083 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010084 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010085 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010086 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010087 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010088
89 /* L1CTL port (for classic tests) */
90 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010091
Harald Welte54a2a2d2018-02-26 09:14:05 +010092 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070093 port TRXC_CODEC_PT BTS_TRXC;
94 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +010095
Harald Weltef50e3ae2018-09-10 10:27:56 +020096 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010097 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +020098 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +010099
Harald Welte883340c2018-02-28 18:59:29 +0100100 /* PCU Interface of BTS */
101 port PCUIF_CODEC_PT PCU;
102 var integer g_pcu_conn_id;
103 /* Last PCU INFO IND we received */
104 var PCUIF_Message g_pcu_last_info;
105
Harald Welte48494ca2018-02-25 16:59:50 +0100106 /* SI configuration */
107 var SystemInformationConfig si_cfg := {
108 bcch_extended := false,
109 si1_present := false,
110 si2bis_present := false,
111 si2ter_present := false,
112 si2quater_present := false,
113 si7_present := false,
114 si8_present := false,
115 si9_present := false,
116 si13_present := false,
117 si13alt_present := false,
118 si15_present := false,
119 si16_present := false,
120 si17_present := false,
121 si2n_present := false,
122 si21_present := false,
123 si22_present := false
124 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100125
126 /* all logical channels available on the BTS */
127 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100128 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100129}
130
131/* an individual call / channel */
132type component ConnHdlr extends RSL_DchanHdlr {
133 port L1CTL_PT L1CTL;
134
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700135 port TRXC_CODEC_PT BTS_TRXC;
136 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100137
138 timer g_Tguard;
139 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
140
141 var ConnHdlrPars g_pars;
142 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100143 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200144
145 /* PCU Interface of BTS */
146 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100147}
148
149function f_init_rsl(charstring id) runs on test_CT {
150 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
151 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
152
153 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
154 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
155 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
156
157 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
158 vc_RSL.start(RSL_Emulation.main(false));
159}
160
161type record ConnHdlrPars {
162 RslChannelNr chan_nr,
163 RSL_IE_ChannelMode chan_mode,
164 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100165 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200166 TestSpecUnion spec optional,
167 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100168}
169
170/* Test-specific parameters */
171type union TestSpecUnion {
172 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
Harald Welte82ccef72018-02-25 16:17:33 +0100175template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100176 max_retrans := RACH_MAX_RETRANS_7,
177 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100178 cell_barr_access := false,
179 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100180 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100181};
182
Harald Weltef10153f2018-02-25 16:34:05 +0100183template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100184 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200185 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100186 acs := '0'B,
187 neci := true,
188 rxlev_access_min := 0
189}
190
191template (value) LocationAreaIdentification ts_LAI_default := {
192 mcc_mnc := '262F42'H,
193 lac := 42
194}
195
Harald Welte7484fc42018-02-24 14:09:45 +0100196/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100197template (value) SystemInformation ts_SI3_default := {
198 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100199 payload := {
200 si3 := {
201 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100202 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100203 ctrl_chan_desc := {
204 msc_r99 := true,
205 att := true,
206 bs_ag_blks_res := 1,
207 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100208 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100209 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
210 spare := '00'B,
211 bs_pa_mfrms := 0, /* 2 multiframes */
212 t3212 := 1 /* 6 minutes */
213 },
Harald Welte82ccef72018-02-25 16:17:33 +0100214 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100215 dn_ind := false,
216 pwrc := false,
217 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100218 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100219 },
Harald Weltef10153f2018-02-25 16:34:05 +0100220 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100221 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100222 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100223 }
224 }
225}
Harald Welte70767382018-02-21 12:16:40 +0100226
Harald Weltef8df4cb2018-03-10 15:15:08 +0100227template (value) SystemInformation ts_SI2_default := {
228 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100229 payload := {
230 si2 := {
231 bcch_freq_list := '00000000000000000000000000000000'O,
232 ncc_permitted := '11111111'B,
233 rach_control := ts_RachCtrl_default
234 }
235 }
236}
237
Harald Weltef8df4cb2018-03-10 15:15:08 +0100238template (value) SystemInformation ts_SI4_default := {
239 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100240 payload := {
241 si4 := {
242 lai := ts_LAI_default,
243 cell_sel_par := ts_CellSelPar_default,
244 rach_control := ts_RachCtrl_default,
245 cbch_chan_desc := omit,
246 cbch_mobile_alloc := omit,
247 rest_octets := ''O
248 }
249 }
250}
251
252function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
253runs on test_CT {
254 log("Setting ", rsl_si_type, ": ", si_enc);
255 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
256}
257
258function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
259runs on test_CT {
260 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
261 log("Setting ", rsl_si_type, ": ", si_dec);
262 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
263}
264
Harald Welte505cf9b2018-09-15 17:47:23 +0300265friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100266 map(self:BTSVTY, system:BTSVTY);
267 f_vty_set_prompts(BTSVTY);
268 f_vty_transceive(BTSVTY, "enable");
269}
270
Harald Welte505cf9b2018-09-15 17:47:23 +0300271friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200272 map(self:BSCVTY, system:BSCVTY);
273 f_vty_set_prompts(BSCVTY, "OsmoBSC");
274 f_vty_transceive(BSCVTY, "enable");
275}
276
Harald Welte883340c2018-02-28 18:59:29 +0100277/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200278private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
279 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100280 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200281 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
282 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100283 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200284 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100286 }
287}
288
Harald Weltef26de0b2018-04-04 20:28:05 +0200289private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
290 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100291 timer T := 2.0;
292 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100293 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200294 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100295 return;
296 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200297 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100298
299 T.start;
300 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200301 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100302 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100304 }
305 }
306}
307
Harald Welte70767382018-02-21 12:16:40 +0100308/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100309function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100310 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100311 g_AllChannels := {
312 /* TS 1..4: TCH/F */
313 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
314 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
315 /* TS 5: TCH/H */
316 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
317 /* TS 0: SDCCH/4 */
318 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
319 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
320 /* TS 6: SDCCH/8 */
321 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
322 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
323 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
324 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
325 };
326
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200327 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700328 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200329 g_AllChanTypes := {
330 /* TS 1..4: TCH/F */
331 valueof(ts_RslChanNr_Bm(1)),
332 /* TS 5: TCH/H */
333 valueof(ts_RslChanNr_Lm(5,1)),
334 /* TS 0: SDCCH/4 */
335 valueof(ts_RslChanNr_SDCCH4(0,2)),
336 /* TS 6: SDCCH/8 */
337 valueof(ts_RslChanNr_SDCCH8(6,4))
338 };
339 } else {
340 g_AllChanTypes := {
341 /* TS 1..4: TCH/F */
342 valueof(ts_RslChanNr_Bm(1)),
343 /* TS 0: SDCCH/4 */
344 valueof(ts_RslChanNr_SDCCH4(0,2)),
345 /* TS 6: SDCCH/8 */
346 valueof(ts_RslChanNr_SDCCH8(6,4))
347 };
348 }
Harald Welte70767382018-02-21 12:16:40 +0100349 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200350 T.start;
351 alt {
352 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
353 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200355 }
356 }
Harald Welte2d142592018-02-25 13:19:44 +0100357 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100358 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200359 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100360
361 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100362 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
363 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
364 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
365 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100366
Harald Weltef26de0b2018-04-04 20:28:05 +0200367 map(self:PCU, system:PCU);
368 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100369
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700370 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100371 var TrxcMessage ret;
372 /* start with a default moderate timing offset equalling TA=2 */
373 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700374 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte84271622018-03-10 17:21:03 +0100375 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200376
377 /* Wait some extra time to make sure the BTS emits a stable carrier.
378 * (this is only relevant when running the tests with a physical BTS.) */
379 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100380}
381
Harald Welte68e495b2018-02-25 00:05:57 +0100382/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
383function f_init_l1ctl() runs on test_CT {
384 map(self:L1CTL, system:L1CTL);
385 f_connect_reset(L1CTL);
386}
387
Harald Welte70767382018-02-21 12:16:40 +0100388type function void_fn(charstring id) runs on ConnHdlr;
389
390/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200391function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100392runs on test_CT return ConnHdlr {
393 var charstring id := testcasename();
394 var ConnHdlr vc_conn;
395
396 vc_conn := ConnHdlr.create(id);
397 /* connect to RSL Emulation main component */
398 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
399 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200400 if (pcu_comp) {
401 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
402 * it from the test_CT and connect it to the component. This obviously only
403 * works for one component, i.e. no concurrency */
404 unmap(self:PCU, system:PCU);
405 map(vc_conn:PCU, system:PCU);
406 }
Harald Welte70767382018-02-21 12:16:40 +0100407
408 vc_conn.start(f_handler_init(fn, id, pars));
409 return vc_conn;
410}
411
Harald Welte7484fc42018-02-24 14:09:45 +0100412template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
413 streamId := sid,
414 rsl := rsl
415}
416
417template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
418 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
419 streamId := sid,
420 rsl := rsl
421}
422
Harald Welte70767382018-02-21 12:16:40 +0100423private altstep as_Tguard() runs on ConnHdlr {
424 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100426 }
427}
428
Harald Welte505cf9b2018-09-15 17:47:23 +0300429friend function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200430 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100431}
432
433private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700434 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100435 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700436 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100437 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200438 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +0200440 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700441 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100442}
443
444private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100445 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700446 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100447}
448
449private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100450 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700451 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100452}
453
454/* first function started in ConnHdlr component */
455private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
456runs on ConnHdlr {
457 g_pars := pars;
458 g_chan_nr := pars.chan_nr;
459
460 map(self:L1CTL, system:L1CTL);
461 f_connect_reset(L1CTL);
462
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700463 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100464 f_trxc_connect();
465 }
Harald Welte70767382018-02-21 12:16:40 +0100466
467 g_Tguard.start(pars.t_guard);
468 activate(as_Tguard());
469
470 f_rslem_register(0, pars.chan_nr);
471
472 /* call the user-supplied test case function */
473 fn.apply(id);
474}
475
Harald Welteb1726c92018-03-30 11:56:38 +0200476function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
477 boolean ignore_other := false)
478runs on ConnHdlr return RSL_Message {
479 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100480 timer T := 3.0;
481 RSL.send(tx);
482 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100483 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200484 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100485 T.stop;
486 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100487 }
Harald Welte1eba3742018-02-25 12:48:14 +0100488 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100490 }
Harald Welte21240e62018-03-11 21:43:35 +0100491 [not ignore_other] as_l1_sacch();
492 [not ignore_other] as_meas_res();
493 [not ignore_other] as_l1_dcch();
494 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100496 }
Harald Welte21240e62018-03-11 21:43:35 +0100497 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100498 }
Harald Welteb1726c92018-03-30 11:56:38 +0200499 return rx;
500}
501
502function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
503 boolean ignore_other := false)
504runs on ConnHdlr {
505 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100506}
507
Harald Welte8b01c792019-05-19 22:51:25 +0200508function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
509 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
510 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200511 if (encr_enable) {
512 /* append encryption related IEs, if requested */
513 var RSL_IE_EncryptionInfo encr_info;
514 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
515 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
516encr_info})) };
517 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200518 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200519 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100520}
521
Harald Welte70767382018-02-21 12:16:40 +0100522function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100523 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 +0100524 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100525}
526
Harald Welte70767382018-02-21 12:16:40 +0100527private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
528 template RSL_IE_ChannelMode chan_mode,
529 float t_guard := 20.0) := {
530 chan_nr := valueof(chan_nr),
531 chan_mode := valueof(chan_mode),
532 t_guard := t_guard,
533 l1_pars := {
534 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100535 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100536 meas_ul := {
537 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200538 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100539 rxqual := 0
540 },
541 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200542 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100543 rxqual := 0
544 }
545 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200546 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100547 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200548 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200549 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100550 },
Harald Weltee613f962018-04-18 22:38:16 +0200551 spec := omit,
552 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100553}
554
Harald Welte93640c62018-02-25 16:59:33 +0100555/***********************************************************************
556 * Channel Activation / Deactivation
557 ***********************************************************************/
558
Harald Welte70767382018-02-21 12:16:40 +0100559/* Stress test: Do 500 channel activations/deactivations in rapid succession */
560function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
561 for (var integer i := 0; i < 500; i := i+1) {
562 f_rsl_chan_act(g_pars.chan_mode);
563 f_rsl_chan_deact();
564 }
565 setverdict(pass);
566}
567testcase TC_chan_act_stress() runs on test_CT {
568 var ConnHdlr vc_conn;
569 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
570 f_init(testcasename());
571 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
572 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100574}
575
576/* Test if re-activation of an already active channel fails as expected */
577function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
578 f_rsl_chan_act(g_pars.chan_mode);
579 /* attempt to activate the same lchan again -> expect reject */
580 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
581 alt {
582 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100584 }
585 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
586 setverdict(pass);
587 }
588 }
589 f_rsl_chan_deact();
590}
591testcase TC_chan_act_react() runs on test_CT {
592 var ConnHdlr vc_conn;
593 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100594 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100595 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
596 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
600/* Attempt to de-activate a channel that's not active */
601function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
602 timer T := 3.0;
603 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
604 T.start;
605 alt {
606 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
607 setverdict(pass);
608 }
609 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100611 }
612 }
613}
614testcase TC_chan_deact_not_active() runs on test_CT {
615 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100616 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100617 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
618 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100620}
621
622/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
623function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
624 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
625 alt {
626 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100628 }
629 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
630 setverdict(pass);
631 }
632 }
633}
634private type record WrongChanNrCase {
635 RslChannelNr chan_nr,
636 charstring description
637}
638private type record of WrongChanNrCase WrongChanNrCases;
639private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
640 chan_nr := chan_nr,
641 description := desc
642}
643
644testcase TC_chan_act_wrong_nr() runs on test_CT {
645 var ConnHdlr vc_conn;
646 var ConnHdlrPars pars;
647
Harald Welte294b0a22018-03-10 23:26:48 +0100648 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100649
650 var WrongChanNrCases wrong := {
651 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
652 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
653 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
654 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
655 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
656 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
657 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
658 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
659 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
660 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
661 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
662 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
663 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
664 };
665
666 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
667 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
668 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
669 vc_conn.done;
670 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100672}
673
Harald Weltee613f962018-04-18 22:38:16 +0200674/* execute the same callback function on a variety of logical channels */
675private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
676 var ConnHdlr vc_conn;
677 f_init(testcasename());
678
679 /* test on each of the channels we have */
680 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
681 pars.chan_nr := valueof(g_AllChanTypes[i]);
682
683 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
684 vc_conn := f_start_handler(fn, pars);
685 vc_conn.done;
686 }
687
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200689}
690
Harald Welte93640c62018-02-25 16:59:33 +0100691/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100692 * SACCH handling
693 ***********************************************************************/
694
695private function f_exp_sacch(boolean exp) runs on ConnHdlr {
696 timer T_sacch := 3.0;
697 T_sacch.start;
698 alt {
699 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100701 }
702 [not exp] T_sacch.timeout {
703 setverdict(pass);
704 }
705 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
706 setverdict(pass);
707 }
708 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100710 }
711 [] L1CTL.receive { repeat; }
712 [] RSL.receive { repeat; }
713 }
714}
715
716/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
717private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
718 f_l1_tune(L1CTL);
719 RSL.clear;
720
721 /* activate the logical channel */
722 f_est_dchan();
723 L1CTL.clear;
724
725 /* check that SACCH actually are received as expected */
726 f_exp_sacch(true);
727
728 /* deactivate SACCH on the logical channel */
729 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
730 f_sleep(1.0);
731 L1CTL.clear;
732
733 /* check that no SACCH are received anymore */
734 f_exp_sacch(false);
735
736 /* release the channel */
737 f_rsl_chan_deact();
738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
739}
740testcase TC_deact_sacch() runs on test_CT {
741 var ConnHdlr vc_conn;
742 var ConnHdlrPars pars;
743 f_init();
744 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
745 //for (var integer i := 0; i < 1; i := i+1) {
746 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
747 log(testcasename(), ": Starting for ", g_AllChannels[i]);
748 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
749 vc_conn.done;
750 }
751 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100753}
754
Harald Welte55700662018-03-12 13:15:43 +0100755/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100756private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
757 var L1ctlDlMessage dl;
758 /* check that the specified SI5 value is actually sent */
759 timer T_sacch := 3.0;
760 L1CTL.clear;
761 T_sacch.start;
762 alt {
763 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
764 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
765 if (match(l3, l3_exp)) {
766 setverdict(pass);
767 } else {
768 repeat;
769 }
770 }
771 [] L1CTL.receive { repeat; }
772 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100774 }
775 }
776}
777
Harald Welte55700662018-03-12 13:15:43 +0100778/* verify that given SACCH payload is not present */
779private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
780 var L1ctlDlMessage dl;
781 /* check that the specified SI5 value is actually sent */
782 timer T_sacch := 3.0;
783 L1CTL.clear;
784 T_sacch.start;
785 alt {
786 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
787 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
788 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100790 } else {
791 repeat;
792 }
793 }
794 [] L1CTL.receive { repeat; }
795 [] T_sacch.timeout {
796 setverdict(pass);
797 }
798 }
799}
800
Harald Welte629cc6b2018-03-11 17:19:05 +0100801/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100802private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
803 /* Set a known default SACCH filling for SI5 */
804 var octetstring si5 := f_rnd_octstring(19);
805 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
806
807 f_l1_tune(L1CTL);
808 RSL.clear;
809
810 /* activate the logical channel */
811 f_est_dchan();
812
813 /* check that the specified SI5 value is actually sent */
814 f_sacch_present(si5);
815
816 /* release the channel */
817 RSL.clear;
818 f_rsl_chan_deact();
819 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
820}
821testcase TC_sacch_filling() runs on test_CT {
822 var ConnHdlr vc_conn;
823 var ConnHdlrPars pars;
824 f_init();
825 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
826 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
827 log(testcasename(), ": Starting for ", g_AllChannels[i]);
828 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
829 vc_conn.done;
830 }
831 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100833}
834
Harald Welte629cc6b2018-03-11 17:19:05 +0100835/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100836private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
837 /* Set a known default SACCH filling for SI5 */
838 var octetstring si5 := f_rnd_octstring(19);
839 var octetstring si5_diff := f_rnd_octstring(19);
840 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
841
842 f_l1_tune(L1CTL);
843 RSL.clear;
844
845 log("Activating channel, expecting standard SI5");
846 /* activate the logical channel */
847 f_est_dchan();
848 /* check that the specified SI5 value is actually sent */
849 f_sacch_present(si5);
850
851 /* set channel-specific different SI5 */
852 log("Setting channel specific SACCH INFO, expecting it");
853 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
854 /* check that the specified lchan-specific value is now used */
855 f_sacch_present(si5_diff);
856
857 /* deactivate the channel and re-activate it, this should result in default SI5 */
858 log("De-activating and re-activating channel, expecting standard SI5");
859 f_rsl_chan_deact();
860 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
861 /* Verify that the TRX-wide default SACCH filling is present again */
862 f_sacch_present(si5);
863
864 /* release the channel */
865 RSL.clear;
866 f_rsl_chan_deact();
867 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
868}
869testcase TC_sacch_info_mod() runs on test_CT {
870 var ConnHdlr vc_conn;
871 var ConnHdlrPars pars;
872 f_init();
873 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
874 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
875 log(testcasename(), ": Starting for ", g_AllChannels[i]);
876 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
877 vc_conn.done;
878 }
879 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100881}
882
Harald Welte075d84c2018-03-12 13:07:24 +0100883/* Test SACCH scheduling of multiple different SI message types */
884private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
885 var octetstring si5 := f_rnd_octstring(19);
886 var octetstring si5bis := f_rnd_octstring(19);
887 var octetstring si5ter := f_rnd_octstring(19);
888 var octetstring si6 := f_rnd_octstring(19);
889
890 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
891 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
892 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
893 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
894
895 f_l1_tune(L1CTL);
896 RSL.clear;
897
898 /* activate the logical channel */
899 f_est_dchan();
900 L1CTL.clear;
901
902 /* check that SACCH actually are received as expected */
903 f_sacch_present(si5);
904 f_sacch_present(si5bis);
905 f_sacch_present(si5ter);
906 f_sacch_present(si6);
907
908 /* release the channel */
909 f_rsl_chan_deact();
910 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
911}
912testcase TC_sacch_multi() runs on test_CT {
913 var ConnHdlr vc_conn;
914 var ConnHdlrPars pars;
915 f_init();
916 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
917 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
918 log(testcasename(), ": Starting for ", g_AllChannels[i]);
919 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
920 vc_conn.done;
921 }
922 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100924}
925
Harald Welte55700662018-03-12 13:15:43 +0100926/* Test if SACH information is modified as expected */
927private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
928 var octetstring si5 := f_rnd_octstring(19);
929 var octetstring si6 := f_rnd_octstring(19);
930
931 /* First, configure both SI5 and SI6 to be transmitted */
932 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
933 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
934
935 f_l1_tune(L1CTL);
936 RSL.clear;
937
938 /* activate the logical channel */
939 f_est_dchan();
940 L1CTL.clear;
941
942 /* check that SACCH actually are received as expected */
943 f_sacch_present(si5);
944 f_sacch_present(si6);
945
946 /* disable SI6 */
947 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
948
949 /* check that SI5 is still transmitted */
950 f_sacch_present(si5);
951 /* check if SI6 is now gone */
952 f_sacch_missing(si6);
953
954 /* release the channel */
955 f_rsl_chan_deact();
956 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
957}
958testcase TC_sacch_multi_chg() runs on test_CT {
959 var ConnHdlr vc_conn;
960 var ConnHdlrPars pars;
961 f_init();
962 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
963 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
964 log(testcasename(), ": Starting for ", g_AllChannels[i]);
965 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
966 vc_conn.done;
967 }
968 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100970}
971
Harald Weltec8d363c2019-05-19 20:36:48 +0200972/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
973private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
974 var octetstring si5 := f_rnd_octstring(19);
975 var octetstring si6 := f_rnd_octstring(19);
976 var octetstring si5_specific := f_rnd_octstring(19);
977 var octetstring si6_specific := f_rnd_octstring(19);
978
979 /* First, configure both SI5 and SI6 to be transmitted */
980 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
981 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
982
983 f_l1_tune(L1CTL);
984 RSL.clear;
985
986 /* activate channel with different SACCH filling */
987 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
988 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
989 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
990 }));
991 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
992 RSL_IE_Body:{sacch_info := sacch_info})) };
993 f_est_dchan(more_ies := addl_ies);
994
995 /* check that SACCH actually are received as expected */
996 f_sacch_present(si5_specific);
997 f_sacch_present(si6_specific);
998
999 /* release the channel */
1000 f_rsl_chan_deact();
1001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1002}
1003testcase TC_sacch_chan_act() runs on test_CT {
1004 var ConnHdlr vc_conn;
1005 var ConnHdlrPars pars;
1006 f_init();
1007
1008 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1009 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1010 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1011 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1012 vc_conn.done;
1013 }
1014 /* TODO: do the above in parallel, rather than sequentially? */
1015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1016}
1017
Harald Welte8b01c792019-05-19 22:51:25 +02001018/* verify that SACCH DL transmission is started only if MS power IE present
1019 * see section 4.1.3 of 3GPP TS 48.058 */
1020private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1021 var octetstring si5 := f_rnd_octstring(19);
1022
1023 f_l1_tune(L1CTL);
1024 RSL.clear;
1025
1026 /* Step 1: Activate ASYNC HO channel without MS power IE */
1027
1028 /* Activate channel on BTS side */
1029 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1030 /* don't perform immediate assignment here, as we're testing non-IA case */
1031 /* enable dedicated mode */
1032 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1033
1034 /* Verify that no DL SACCH is being received */
1035 f_sacch_missing(?);
1036
1037 f_rsl_chan_deact();
1038 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1039
1040
1041 /* Step 2: Activate ASYNC HO channel with MS power IE */
1042
1043 /* Activate channel on BTS side */
1044 var RSL_IE_List addl_ies := {
1045 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1046 };
1047 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1048 /* don't perform immediate assignment here, as we're testing non-IA case */
1049 /* enable dedicated mode */
1050 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1051
1052 /* Verify that DL SACCH is being received */
1053 f_sacch_present(si5);
1054
1055 f_rsl_chan_deact();
1056 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1057}
1058testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1059 var ConnHdlr vc_conn;
1060 var ConnHdlrPars pars;
1061 f_init();
1062
1063 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1064 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1065 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1066 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1067 vc_conn.done;
1068 }
1069 /* TODO: do the above in parallel, rather than sequentially? */
1070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1071}
1072
1073/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1074 * see section 4.1.4 of 3GPP TS 48.058 */
1075private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1076 var octetstring si5 := f_rnd_octstring(19);
1077 var RSL_IE_List addl_ies;
1078
1079 f_l1_tune(L1CTL);
1080 RSL.clear;
1081
1082 /* Step 1: Activate SYNC HO channel without MS power IE */
1083
1084 /* Activate channel on BTS side */
1085 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1086 /* don't perform immediate assignment here, as we're testing non-IA case */
1087 /* enable dedicated mode */
1088 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1089
1090 /* Verify that no DL SACCH is being received */
1091 f_sacch_missing(?);
1092
1093 f_rsl_chan_deact();
1094 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1095
1096
1097 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1098
1099 /* Activate channel on BTS side */
1100 addl_ies := {
1101 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1102 };
1103 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1104 /* don't perform immediate assignment here, as we're testing non-IA case */
1105 /* enable dedicated mode */
1106 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1107
1108 /* Verify that no DL SACCH is being received */
1109 f_sacch_missing(?);
1110
1111 f_rsl_chan_deact();
1112 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1113
1114
1115 /* Step 2b: Activate SYNC HO channel with TA IE */
1116
1117 /* Activate channel on BTS side */
1118 addl_ies := {
1119 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1120 };
1121 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1122 /* don't perform immediate assignment here, as we're testing non-IA case */
1123 /* enable dedicated mode */
1124 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1125
1126 /* Verify that no DL SACCH is being received */
1127 f_sacch_missing(?);
1128
1129 f_rsl_chan_deact();
1130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1131
1132
1133 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1134
1135 /* Activate channel on BTS side */
1136 addl_ies := {
1137 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1138 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1139 };
1140 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1141 /* don't perform immediate assignment here, as we're testing non-IA case */
1142 /* enable dedicated mode */
1143 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1144
1145 /* Verify that DL SACCH is being received */
1146 f_sacch_present(si5);
1147
1148 f_rsl_chan_deact();
1149 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1150}
1151testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1152 var ConnHdlr vc_conn;
1153 var ConnHdlrPars pars;
1154 f_init();
1155
1156 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1157 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1158 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1159 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1160 vc_conn.done;
1161 }
1162 /* TODO: do the above in parallel, rather than sequentially? */
1163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1164}
Harald Welte629cc6b2018-03-11 17:19:05 +01001165
1166
1167/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001168 * RACH Handling
1169 ***********************************************************************/
1170
Harald Welte8c24c2b2018-02-26 08:31:31 +01001171/* like L1SAP_IS_PACKET_RACH */
1172private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001173 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001174 return true;
1175 }
1176 return false;
1177}
1178
1179/* generate a random RACH for circuit-switched */
1180private function f_rnd_ra_cs() return OCT1 {
1181 var OCT1 ra;
1182 do {
1183 ra := f_rnd_octstring(1);
1184 } while (ra_is_ps(ra));
1185 return ra;
1186}
1187
Harald Welte883340c2018-02-28 18:59:29 +01001188/* generate a random RACH for packet-switched */
1189private function f_rnd_ra_ps() return OCT1 {
1190 var OCT1 ra;
1191 do {
1192 ra := f_rnd_octstring(1);
1193 } while (not ra_is_ps(ra));
1194 return ra;
1195}
1196
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001197/* generate a random 11-bit RA (packet-switched only) */
1198private function f_rnd_ra11_ps() return BIT11 {
1199 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1200 return int2bit(ra11, 11);
1201}
1202
Harald Welte8c24c2b2018-02-26 08:31:31 +01001203/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1204testcase TC_rach_content() runs on test_CT {
1205 f_init(testcasename());
1206 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001207 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001208
Harald Welte8c24c2b2018-02-26 08:31:31 +01001209 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001210 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001211 for (var integer i := 0; i < 1000; i := i+1) {
1212 var OCT1 ra := f_rnd_ra_cs();
1213 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1214 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001216 }
1217 fn_last := fn;
1218
1219 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001220 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001221 alt {
1222 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1223 T.stop;
1224 }
1225 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001227 }
1228 [] RSL_CCHAN.receive { repeat; }
1229 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001230 test_failed := true;
1231 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001232 }
1233 }
1234 }
Maxba06feb2019-03-05 10:52:46 +01001235 if (test_failed) {
1236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001237 }
Maxba06feb2019-03-05 10:52:46 +01001238 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001240}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001241
1242/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1243testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001244 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001245 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001246 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247 f_l1_tune(L1CTL);
1248
1249 var GsmFrameNumber fn_last := 0;
1250 for (var integer i := 0; i < 1000; i := i+1) {
1251 var OCT1 ra := f_rnd_ra_cs();
1252 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1253 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001255 }
1256 fn_last := fn;
1257 }
1258 var integer rsl_chrqd := 0;
1259 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001260 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001261 alt {
1262 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1263 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001264 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001265 repeat;
1266 }
1267 [] RSL_CCHAN.receive { repeat; }
1268 [] T.timeout { }
1269 }
1270 if (rsl_chrqd == 1000) {
1271 setverdict(pass);
1272 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001274 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001276}
1277
Harald Welte3453ab42019-05-24 21:19:58 +02001278private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1279 var charstring bts_str := "bts " & int2str(bts_nr);
1280 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1281}
1282
1283/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1284private template integer tr_rach_slots_per_interval := (90 .. 130);
1285
1286/* Expect 0 RACH load on an idle BTS that has just started up */
1287testcase TC_rach_load_idle_thresh0() runs on test_CT {
1288 var ASP_RSL_Unitdata rx_ud;
1289
1290 f_init_vty_bsc();
1291 /* send load indications even at 0% load */
1292 f_vty_load_ind_thresh(0);
1293 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1294 f_sleep(2.0);
1295
1296 f_init();
1297
1298 timer T := 5.0;
1299 T.start;
1300 alt {
1301 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1302 setverdict(pass);
1303 repeat;
1304 }
1305 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1306 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1307 repeat;
1308 }
1309 [] RSL_CCHAN.receive {
1310 repeat;
1311 }
1312 [] T.timeout { }
1313 }
1314
1315 f_vty_load_ind_thresh(10);
1316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1317}
1318
1319/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1320testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1321 var ASP_RSL_Unitdata rx_ud;
1322
1323 f_init_vty_bsc();
1324 f_init();
1325
1326 timer T := 5.0;
1327 T.start;
1328 alt {
1329 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1330 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1331 repeat;
1332 }
1333 [] RSL_CCHAN.receive {
1334 repeat;
1335 }
1336 [] T.timeout {
1337 setverdict(pass);
1338 }
1339 }
1340
1341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1342}
1343
1344/* Expect 0 RACH load on an idle BTS that has just started up */
1345testcase TC_rach_load_count() runs on test_CT {
1346 var ASP_RSL_Unitdata rx_ud;
1347 var integer load_access_count := 0;
1348
1349 f_init_vty_bsc();
1350 /* send load indications even at 0% load */
1351 f_vty_load_ind_thresh(0);
1352 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1353 f_sleep(2.0);
1354 f_init();
1355
1356 f_init_l1ctl();
1357 f_sleep(1.0);
1358 f_l1_tune(L1CTL);
1359
1360 var GsmFrameNumber fn_last := 0;
1361 for (var integer i := 0; i < 1000; i := i+1) {
1362 var OCT1 ra := f_rnd_ra_cs();
1363 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1364 if (fn == fn_last) {
1365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1366 }
1367 fn_last := fn;
1368 }
1369
1370 timer T := 5.0;
1371 T.start;
1372 alt {
1373 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1374 -> value rx_ud {
1375 var RSL_IE_Body ie;
1376 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1377 load_access_count := load_access_count + ie.rach_load.access_count;
1378 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1379 setverdict(fail, "Access count cannot be < Busy count");
1380 }
1381 repeat;
1382 }
1383 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1384 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1385 repeat;
1386 }
1387 [] RSL_CCHAN.receive {
1388 repeat;
1389 }
1390 [] T.timeout { }
1391 }
1392 if (load_access_count == 1000) {
1393 setverdict(pass);
1394 } else {
1395 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1396 }
1397
1398 f_vty_load_ind_thresh(10);
1399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1400}
1401
1402
1403
Harald Welte54a2a2d2018-02-26 09:14:05 +01001404private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001405 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001406 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001407 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001408 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001409 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +02001411 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001412 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001413}
1414
1415private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001416 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001417 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001418 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001419 f_sleep(0.5);
1420
1421 /* Transmit RACH request + wait for confirmation */
1422 var OCT1 ra := f_rnd_ra_cs();
1423 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1424
1425 /* Check for expected result */
1426 timer T := 1.5;
1427 T.start;
1428 alt {
1429 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1430 setverdict(pass);
1431 }
1432 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001434 }
1435 [] RSL_CCHAN.receive { repeat; }
1436 [not expect_pass] T.timeout {
1437 setverdict(pass);
1438 }
1439 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001441 }
1442 }
1443}
1444
1445/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1446testcase TC_rach_max_ta() runs on test_CT {
1447 f_init(testcasename());
1448 f_init_l1ctl();
1449 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001450 f_sleep(1.0);
1451
1452 /* default max-ta is 63 (full range of GSM timing advance */
1453
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001454 /* We allow early arrival up to 2 symbols */
1455 f_rach_toffs(-1*256, true);
1456 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001457 f_rach_toffs(-10*256, false);
1458
1459 /* 0 / 32 / 63 bits is legal / permitted */
1460 f_rach_toffs(0, true);
1461 f_rach_toffs(32*256, true);
1462 f_rach_toffs(63*256, true);
1463
1464 /* more than 63 bits is not legal / permitted */
1465 f_rach_toffs(64*256, false);
1466 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001468}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469
Harald Welte93640c62018-02-25 16:59:33 +01001470/***********************************************************************
1471 * Measurement Processing / Reporting
1472 ***********************************************************************/
1473
Harald Welte70767382018-02-21 12:16:40 +01001474template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1475 spare := '0'B,
1476 lpd := 0,
1477 sapi := sapi,
1478 c_r := c_r,
1479 ea := true
1480}
1481
Harald Welted879bd92018-03-12 15:01:23 +01001482template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001483 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001484 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001485 len := 0, /* overwritten */
1486 m := false,
1487 el := 1,
1488 payload := pl
1489}
1490
1491/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1492altstep as_l1_sacch() runs on ConnHdlr {
1493 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001494 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001495 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001496 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 +01001497 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001498 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001499
1500 var L1ctlDataReq data_req := {
1501 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1502 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1503 }
1504 log("Sending Measurement Report: ", data_req);
1505 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001506 repeat;
1507 }
1508}
1509
1510altstep as_l1_dcch() runs on ConnHdlr {
1511 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001512 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001513 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1514 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001515 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1516 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001517 repeat;
1518 }
1519}
1520
1521type record MeasElem {
1522 uint6_t rxlev,
1523 uint3_t rxqual
1524}
1525
1526type record MeasElemFS {
1527 MeasElem full,
1528 MeasElem sub
1529}
1530
1531type record ConnL1Pars {
1532 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001533 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001534 MeasElemFS meas_ul,
1535 int16_t timing_offset_256syms,
1536 uint5_t bs_power_level,
1537 uint5_t ms_power_level,
1538 uint8_t ms_actual_ta
1539}
1540
1541/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1542private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1543 return 63 + (toffs256s/256);
1544}
1545
Harald Welted5684392018-03-10 18:22:04 +01001546private function f_max(integer a, integer b) return integer {
1547 if (a > b) {
1548 return a;
1549 } else {
1550 return b;
1551 }
1552}
1553
1554private function f_min(integer a, integer b) return integer {
1555 if (a < b) {
1556 return a;
1557 } else {
1558 return b;
1559 }
1560}
1561
1562/* compute negative tolerance val-tolerance, ensure >= min */
1563private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1564 val := val - tolerance;
1565 return f_max(val, min);
1566}
1567
1568/* compute positive tolerance val+tolerance, ensure <= max */
1569private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1570 val := val + tolerance;
1571 return f_min(val, max);
1572}
1573
1574/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1575private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1576return template integer {
1577 var template integer ret;
1578 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1579 return ret;
1580}
1581
1582
Harald Welte70767382018-02-21 12:16:40 +01001583/* build a template for matching measurement results against */
1584private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1585 var ConnL1Pars l1p := g_pars.l1_pars;
1586 var template RSL_IE_UplinkMeas ul_meas := {
1587 len := 3,
1588 rfu := '0'B,
1589 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001590 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001591 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001592 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001593 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001594 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1595 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001596 supp_meas_info := omit
1597 };
Harald Welte685d5982018-02-27 20:42:05 +01001598 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001599 ul_meas.len := (3+8);
1600 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001601 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001602 toa256_min := ?,
1603 toa256_max := ?,
1604 toa256_std_dev := ?
1605 }
Harald Welte685d5982018-02-27 20:42:05 +01001606 }
Harald Welte70767382018-02-21 12:16:40 +01001607 var template RSL_IE_BS_Power bs_power := {
1608 reserved := 0,
1609 epc := false,
1610 fpc := false,
1611 power_level := l1p.bs_power_level
1612 };
1613 var template RSL_IE_L1Info l1_info := {
1614 ms_power_lvl := l1p.ms_power_level,
1615 fpc := false,
1616 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001617 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001618 };
1619 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001620 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001621 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1622 ?, t_toffs);
1623}
1624
1625/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001626altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001627 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001628 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001629 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1630 /* increment counter of next to-be-expected meas rep */
1631 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1632 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001633 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001634 repeat;
1635 }
1636 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001637 /* increment counter of next to-be-expected meas rep */
1638 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1639 if (g_first_meas_res) {
1640 g_first_meas_res := false;
1641 repeat;
1642 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001644 }
Harald Welte70767382018-02-21 12:16:40 +01001645 }
1646 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001648 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001649 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001651 }
1652}
1653
Harald Weltee613f962018-04-18 22:38:16 +02001654private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1655 select (rsl_alg_id) {
1656 case (RSL_ALG_ID_A5_0) { return 0; }
1657 case (RSL_ALG_ID_A5_1) { return 1; }
1658 case (RSL_ALG_ID_A5_2) { return 2; }
1659 case (RSL_ALG_ID_A5_3) { return 3; }
1660 case (RSL_ALG_ID_A5_4) { return 4; }
1661 case (RSL_ALG_ID_A5_5) { return 5; }
1662 case (RSL_ALG_ID_A5_6) { return 6; }
1663 case (RSL_ALG_ID_A5_7) { return 7; }
1664 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1666 /* Make compiler happy by calling mtc.stop here. It is already
1667 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001668 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001669 }
1670 }
1671}
1672
1673private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1674 select (rsl_alg_id) {
1675 case (RSL_ALG_ID_A5_1) { return '000'B; }
1676 case (RSL_ALG_ID_A5_2) { return '001'B; }
1677 case (RSL_ALG_ID_A5_3) { return '010'B; }
1678 case (RSL_ALG_ID_A5_4) { return '011'B; }
1679 case (RSL_ALG_ID_A5_5) { return '100'B; }
1680 case (RSL_ALG_ID_A5_6) { return '101'B; }
1681 case (RSL_ALG_ID_A5_7) { return '110'B; }
1682 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1684 /* Make compiler happy by calling mtc.stop here. It is already
1685 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001686 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001687 }
1688 }
1689}
1690
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001691/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1692private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1693 var GsmFrameNumber fn;
1694 timer T := 8.0;
1695
1696 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1697 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1698
1699 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1700 /* Send the actual RACH */
1701 fn := f_L1CTL_RACH(L1CTL, ra);
1702
1703 T.start;
1704 alt {
1705 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1706 [] T.timeout {
1707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1708 }
1709 }
1710 T.stop
1711 return fn;
1712}
Harald Weltee613f962018-04-18 22:38:16 +02001713
Harald Welte70767382018-02-21 12:16:40 +01001714/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001715private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001716 var GsmFrameNumber fn;
1717 var ImmediateAssignment imm_ass;
1718 var integer ra := 23;
1719
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001720 /* Send RACH request and wait for ChanReq */
1721 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001722
1723 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001724 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001725
1726 /* Send IMM.ASS via CCHAN */
1727 var ChannelDescription ch_desc := {
1728 chan_nr := g_pars.chan_nr,
1729 tsc := 7,
1730 h := false,
1731 arfcn := mp_trx0_arfcn,
1732 maio_hsn := omit
1733 };
1734 var MobileAllocation ma := {
1735 len := 0,
1736 ma := ''B
1737 };
1738 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1739 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1740
1741 /* receive IMM.ASS on MS side */
1742 var ImmediateAssignment ia_um;
1743 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1744 /* enable dedicated mode */
1745 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001746 /* enable encryption, if requested */
1747 if (encr_enable) {
1748 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1749 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1750 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001751
1752 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001753}
1754
1755/* establish DChan, verify existance + contents of measurement reports */
1756function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001757 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001758 RSL.clear;
1759
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001760 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001761 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001762 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1763 }
Harald Welte70767382018-02-21 12:16:40 +01001764
1765 f_est_dchan();
1766
1767 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1768 * RSL measurement reports on Abis side */
1769 timer T := 8.0;
1770 T.start;
1771 alt {
1772 [] as_l1_sacch();
1773 [] as_meas_res();
1774 [] as_l1_dcch();
1775 [] L1CTL.receive { repeat; }
1776 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001777 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001778 * of any earlier errors, so if we reach this timeout, we're good */
1779 setverdict(pass);
1780 }
1781 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001783 }
1784 }
1785 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001786 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001787}
Harald Welte0472ab42018-03-12 15:02:26 +01001788
Harald Welte70767382018-02-21 12:16:40 +01001789testcase TC_meas_res_sign_tchf() runs on test_CT {
1790 var ConnHdlr vc_conn;
1791 var ConnHdlrPars pars;
1792 f_init(testcasename());
1793 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1794 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1795 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1796 vc_conn.done;
1797 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001799}
1800testcase TC_meas_res_sign_tchh() runs on test_CT {
1801 var ConnHdlr vc_conn;
1802 var ConnHdlrPars pars;
1803 f_init(testcasename());
1804 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1805 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1806 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1807 vc_conn.done;
1808 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001810}
1811testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1812 var ConnHdlr vc_conn;
1813 var ConnHdlrPars pars;
1814 f_init(testcasename());
1815 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1816 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1817 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1818 vc_conn.done;
1819 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001821}
1822testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1823 var ConnHdlr vc_conn;
1824 var ConnHdlrPars pars;
1825 f_init(testcasename());
1826 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1827 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1828 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1829 vc_conn.done;
1830 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001832}
Harald Welte685d5982018-02-27 20:42:05 +01001833testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1834 var ConnHdlr vc_conn;
1835 var ConnHdlrPars pars;
1836 f_init(testcasename());
1837 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1838 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1839 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1840 pars.l1_pars.toa256_enabled := true;
1841 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1842 vc_conn.done;
1843 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001845}
1846
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001847/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1848 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1849function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1850 var L1ctlDlMessage l1_dl;
1851 var RSL_IE_MS_Power ms_power;
1852 var RSL_Message rsl;
1853 var uint5_t power_level := 0;
1854
1855 f_l1_tune(L1CTL);
1856 RSL.clear;
1857
1858 f_est_dchan();
1859
1860 ms_power.reserved := 0;
1861 ms_power.fpc_epc := false;
1862
1863 /* Send the first power control command. This will disable any BTS/TRX
1864 * internal power control and switch the MS (which is not in scope of
1865 * this test) to a constant power level. We start with a power level
1866 * of 0 */
1867 ms_power.power_level := power_level;
1868 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1869 RSL.send(rsl);
1870
1871 alt {
1872
1873 /* Pick all SACCH blocks for checking */
1874 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1875
1876 /* The first byte of the L1 header contains the power level.
1877 * The reserved bits and the fpc bit is set to 0, so we may
1878 * compare directly. */
1879 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1880 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1881 }
1882
1883 /* Signal a new power level via RSL for the next turn. */
1884 if (power_level < 31) {
1885 power_level := power_level + 1;
1886 ms_power.power_level := power_level;
1887 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1888 RSL.send(rsl);
1889 repeat;
1890 }
1891
1892 }
1893
1894 /* Ignore all other blocks */
1895 [] L1CTL.receive { repeat; }
1896
1897 }
1898
1899 f_rsl_chan_deact();
1900 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1901
1902 setverdict(pass);
1903}
1904
1905testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1906 var ConnHdlr vc_conn;
1907 var ConnHdlrPars pars;
1908 f_init(testcasename());
1909
1910 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1911 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1912 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1913 vc_conn.done;
1914 }
1915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1916}
Harald Welte70767382018-02-21 12:16:40 +01001917
Eric Wild6833cc92019-05-23 19:34:44 +02001918/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1919TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1920function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1921 var L1ctlDlMessage l1_dl;
1922 var uint5_t ta_to_test := 16;
1923
1924
1925 f_l1_tune(L1CTL);
1926 RSL.clear;
1927
1928 /* tell fake_trx to use a given timing offset for all bursts */
1929 f_trx_fake_toffs256(ta_to_test*256);
1930
1931 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1932
1933
1934 alt {
1935
1936 /* Pick all SACCH blocks for checking */
1937 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1938
1939 /* The second byte of the L1 header contains the TA. */
1940 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1941 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1942 }
1943
1944 }
1945
1946 /* Ignore all other blocks */
1947 [] L1CTL.receive { repeat; }
1948
1949 }
1950
1951 f_rsl_chan_deact();
1952 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1953
1954 setverdict(pass);
1955}
1956
1957testcase TC_rsl_chan_initial_ta() runs on test_CT {
1958 var ConnHdlr vc_conn;
1959 var ConnHdlrPars pars;
1960 f_init(testcasename());
1961 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1962 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1963 vc_conn.done;
1964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1965}
1966
Harald Welte0472ab42018-03-12 15:02:26 +01001967/* 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 +01001968private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001969 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001970 RSL.clear;
1971
1972 f_est_dchan();
1973 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001974 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001975
1976 timer T := 40.0;
1977 T.start;
1978 alt {
1979 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1980 setverdict(pass)
1981 }
1982 [] RSL.receive { repeat };
1983 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001985 }
1986 }
1987 f_rsl_chan_deact();
1988}
1989testcase TC_conn_fail_crit() runs on test_CT {
1990 var ConnHdlr vc_conn;
1991 var ConnHdlrPars pars;
1992 f_init(testcasename());
1993 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1994 pars.t_guard := 60.0;
1995 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1996 vc_conn.done;
1997}
1998
Harald Welte93640c62018-02-25 16:59:33 +01001999/***********************************************************************
2000 * Paging
2001 ***********************************************************************/
2002
Harald Welte68e495b2018-02-25 00:05:57 +01002003function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2004 if (tmsi == 'FFFFFFFF'O) {
2005 return true;
2006 } else {
2007 return false;
2008 }
2009}
Harald Welte70767382018-02-21 12:16:40 +01002010
Philipp Maier82cb0b12018-08-31 14:41:39 +02002011type record allowedFn { integer frame_nr }
2012template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2013template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2014template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2015template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2016template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2017template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2018template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2019template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2020function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2021{
2022 var integer frame_nr_51;
2023 frame_nr_51 := frame_nr mod 51
2024
2025 var allowedFn fn_check;
2026 fn_check.frame_nr := frame_nr_51;
2027
2028 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002030 return;
2031 }
2032
2033 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2034 return;
2035 }
2036 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2037 return;
2038 }
2039 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2040 return;
2041 }
2042 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2043 return;
2044 }
2045 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2046 return;
2047 }
2048 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2049 return;
2050 }
2051 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2052 return;
2053 }
2054 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2055 return;
2056 }
2057
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002059 return;
2060}
2061
2062altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids, PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01002063runs on test_CT {
2064 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002065 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002066 repeat;
2067 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002068 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002069 var octetstring without_plen :=
2070 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2071 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002072
2073 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2074
Harald Welte68e495b2018-02-25 00:05:57 +01002075 if (match(rr, tr_PAGING_REQ1)) {
2076 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2077 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2078 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2079 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2080 }
2081 } else if (match(rr, tr_PAGING_REQ2)) {
2082 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2083 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2084 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2085 }
2086 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2087 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2088 }
2089 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2090 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2091 }
2092 } else if (match(rr, tr_PAGING_REQ3)) {
2093 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2094 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2095 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2096 }
2097 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2098 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2099 }
2100 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2101 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2102 }
2103 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2104 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2105 }
2106 }
2107 repeat;
2108 }
2109}
2110
2111type record PagingTestCfg {
2112 boolean combined_ccch,
2113 integer bs_ag_blks_res,
2114 float load_factor,
2115 boolean exp_load_ind,
2116 boolean exp_overload,
2117 boolean use_tmsi
2118}
2119
2120type record PagingTestState {
2121 integer num_paging_sent,
2122 integer num_paging_rcv_msgs,
2123 integer num_paging_rcv_ids,
2124 integer num_overload
2125}
2126
2127/* receive + ignore RSL RF RES IND */
2128altstep as_rsl_res_ind() runs on test_CT {
2129 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2130 repeat;
2131 }
2132}
2133
2134/* Helper function for paging related testing */
2135private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2136 f_init(testcasename());
2137 f_init_l1ctl();
2138 f_l1_tune(L1CTL);
2139
2140 var PagingTestState st := {
2141 num_paging_sent := 0,
2142 num_paging_rcv_msgs := 0,
2143 num_paging_rcv_ids := 0,
2144 num_overload := 0
2145 };
2146
2147 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2148 var float max_pch_imsi_per_sec;
2149 if (cfg.use_tmsi) {
2150 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2151 } else {
2152 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2153 }
2154 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2155 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002156 var float time_total := 20.0;
2157 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2158 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002159
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002160 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2161 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002162
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002163 timer T_itv := 0.0;
2164 T_itv.start;
2165 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002166 alt {
2167 /* check for presence of CCCH LOAD IND (paging load) */
2168 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2169 st.num_overload := st.num_overload + 1;
2170 repeat;
2171 }
2172 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002174 }
2175 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2176 log("Rx LOAD_IND");
2177 /* FIXME: analyze/verify interval + contents */
2178 repeat;
2179 }
2180 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002181 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002182 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002183 [] T_itv.timeout {
2184 /* Send paging cmds based on elapsed time */
2185 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2186 while (st.num_paging_sent < new_sent) {
2187 /* build mobile Identity */
2188 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2189 if (cfg.use_tmsi) {
2190 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2191 } else {
2192 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2193 }
2194 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2195 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2196
2197 /* Send RSL PAGING COMMAND */
2198 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2199
2200 st.num_paging_sent := st.num_paging_sent + 1;
2201 }
2202 if (st.num_paging_sent < pkt_total) {
2203 /* Wait for interval to next PAGING COMMAND */
2204 var float time_now := T_total.read;
2205 var float next_sched := int2float(st.num_paging_sent)*interval;
2206 if (next_sched > time_now) {
2207 T_itv.start(next_sched - time_now);
2208 } else {
2209 T_itv.start(0.0);
2210 }
2211 } else {
2212 /* We are done, no need to keep counting */
2213 T_total.stop;
2214 }
2215 }
2216 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002217 [] as_rsl_res_ind();
2218 }
2219 }
2220
2221 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2222 timer T_wait := 18.0;
2223 T_wait.start;
2224 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002225 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002226 [] L1CTL.receive { repeat; }
2227 /* 65535 == empty paging queue, we can terminate*/
2228 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2229 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2230 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002232 }
2233 [] as_rsl_res_ind();
2234 }
2235
2236 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2237 " rcvd_ids=", st.num_paging_rcv_ids);
2238 return st;
2239}
2240
2241/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2242 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2243 * - that CCCH LOAD IND (PCH) are being generated
2244 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2245testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002246 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002247 var PagingTestCfg cfg := {
2248 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002249 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002250 load_factor := 0.8,
2251 exp_load_ind := true,
2252 exp_overload := false,
2253 use_tmsi := false
2254 };
2255 var PagingTestState st := f_TC_paging(cfg);
2256 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2258 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002259 } else {
2260 setverdict(pass);
2261 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002263}
2264
2265/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2266 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2267 * - that CCCH LOAD IND (PCH) are being generated
2268 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2269testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002270 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002271 var PagingTestCfg cfg := {
2272 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002273 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002274 load_factor := 0.8,
2275 exp_load_ind := true,
2276 exp_overload := false,
2277 use_tmsi := true
2278 };
2279 var PagingTestState st := f_TC_paging(cfg);
2280 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2282 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002283 } else {
2284 setverdict(pass);
2285 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002287}
2288
2289/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2290 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2291 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2292 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2293testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002294 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002295 var PagingTestCfg cfg := {
2296 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002297 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002298 load_factor := 2.0,
2299 exp_load_ind := true,
2300 exp_overload := true,
2301 use_tmsi := false
2302 };
2303 var PagingTestState st := f_TC_paging(cfg);
2304 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2305 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002306 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002307 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002308 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 +01002309 } else {
2310 setverdict(pass);
2311 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002313}
2314
2315/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2316 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2317 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2318 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2319testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002320 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002321 var PagingTestCfg cfg := {
2322 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002323 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002324 load_factor := 2.0,
2325 exp_load_ind := true,
2326 exp_overload := true,
2327 use_tmsi := true
2328 };
2329 var PagingTestState st := f_TC_paging(cfg);
2330 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2331 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002332 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002333 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002334 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 +01002335 } else {
2336 setverdict(pass);
2337 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002339}
2340
2341
Harald Welte93640c62018-02-25 16:59:33 +01002342/***********************************************************************
2343 * Immediate Assignment / AGCH
2344 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002345const MobileAllocation c_MA_null := {
2346 len := 0,
2347 ma := ''B
2348}
Harald Welte93640c62018-02-25 16:59:33 +01002349
Harald Weltee8d750e2018-06-10 21:41:35 +02002350template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2351 uint12_t arfcn := 871) := {
2352 chan_nr := chan_nr,
2353 tsc := tsc,
2354 h := false,
2355 arfcn := arfcn,
2356 maio_hsn := omit
2357}
2358
2359private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2360 return int2str(num_tx) & " sent, "
2361 & int2str(num_rx) & " received, "
2362 & int2str(num_del) & " deleted";
2363}
2364
2365private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2366 var L1ctlDlMessage l1_dl;
2367 timer T := 10.0;
2368 var integer num_tx := 0;
2369 var integer num_rx := 0;
2370 var integer num_del := 0;
2371 var charstring res_str;
2372 var float rx_ratio;
2373
Harald Welte68e495b2018-02-25 00:05:57 +01002374 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002375 f_init_l1ctl();
2376 f_l1_tune(L1CTL);
2377
2378 for (var integer i := 0; i < num_total; i := i+1) {
2379 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2380 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2381 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002382 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002383 num_tx := num_tx+1;
2384 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002385 }
2386 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002387 T.start;
2388 alt {
2389 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2390 num_del := num_del+1;
2391 repeat;
2392 }
2393 [] RSL_CCHAN.receive {
2394 repeat;
2395 }
2396 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2397 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2398 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2399 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2400 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002401 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002402 } else {
2403 num_rx := num_rx+1;
2404 }
2405 repeat;
2406 }
2407 [] L1CTL.receive { repeat; }
2408 [] T.timeout { }
2409 }
2410 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2411 log("AGCH test: " & res_str);
2412 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002414 }
2415 rx_ratio := int2float(num_rx) / int2float(num_tx);
2416 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002417 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 +02002418 } else {
2419 setverdict(pass);
2420 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002422}
2423
Harald Weltee8d750e2018-06-10 21:41:35 +02002424/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2425testcase TC_imm_ass_1000_20ms() runs on test_CT {
2426 f_TC_imm_ass(1000, 0.02, 0.25);
2427}
2428
2429/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2430testcase TC_imm_ass_200_0ms() runs on test_CT {
2431 f_TC_imm_ass(200, 0.0, 0.05);
2432}
2433
2434/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2435testcase TC_imm_ass_200_76ms() runs on test_CT {
2436 f_TC_imm_ass(150, 0.076, 1.00);
2437}
2438
2439
2440
Harald Welte48494ca2018-02-25 16:59:50 +01002441/***********************************************************************
2442 * BCCH
2443 ***********************************************************************/
2444
2445/* tuple of Frame Number + decoded SI */
2446type record SystemInformationFn {
2447 GsmFrameNumber frame_number,
2448 SystemInformation si
2449}
2450
2451/* an arbitrary-length vector of decoded SI + gsmtap header */
2452type record of SystemInformationFn SystemInformationVector;
2453
2454/* an array of SI-vectors indexed by TC value */
2455type SystemInformationVector SystemInformationVectorPerTc[8];
2456
2457/* determine if a given SI vector contains given SI type at least once */
2458function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2459 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2460 var integer fn_mod51 := arr[i].frame_number mod 51;
2461 if (not bcch_ext and fn_mod51 == 2 or
2462 bcch_ext and fn_mod51 == 6) {
2463 if (arr[i].si.header.message_type == key) {
2464 return true;
2465 }
2466 }
2467 }
2468 return false;
2469}
2470
2471/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2472function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2473 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002475 }
2476}
2477
2478/* check if a given SI vector contains given SI type at least once on any TC */
2479function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2480 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2481 if (f_si_vecslot_contains(arr[tc], key) or
2482 f_si_vecslot_contains(arr[tc], key, true)) {
2483 return true;
2484 }
2485 }
2486 return false;
2487}
2488
2489/* determine if a given SI vector contains given SI type at least N of M times */
2490function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2491 var integer count := 0;
2492 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002494 }
2495 for (var integer i:= 0; i < m; i := i + 1) {
2496 var integer fn_mod51 := arr[i].frame_number mod 51;
2497 if (not bcch_ext and fn_mod51 == 2 or
2498 bcch_ext and fn_mod51 == 6) {
2499 if (arr[i].si.header.message_type == key) {
2500 count := count + 1;
2501 }
2502 }
2503 }
2504 if (count >= n) {
2505 return true;
2506 } else {
2507 return false;
2508 }
2509}
2510
2511/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2512function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2513 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002515 }
2516}
2517
2518/* determine if a given SI vector contains given SI type at least once */
2519function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2520 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2521 var integer fn_mod51 := arr[i].frame_number mod 51;
2522 if (not bcch_ext and fn_mod51 == 2 or
2523 bcch_ext and fn_mod51 == 6) {
2524 if (arr[i].si.header.message_type != key) {
2525 return false;
2526 }
2527 }
2528 }
2529 return true;
2530}
2531
2532/* ensure a given TC slot of the SI vector contains only given SI type */
2533function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2534 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002536 }
2537}
2538
2539/* SI configuration of cell, against which we validate actual SI messages */
2540type set SystemInformationConfig {
2541 boolean bcch_extended,
2542 boolean si1_present,
2543 boolean si2bis_present,
2544 boolean si2ter_present,
2545 boolean si2quater_present,
2546 boolean si7_present,
2547 boolean si8_present,
2548 boolean si9_present,
2549 boolean si13_present,
2550 boolean si13alt_present,
2551 boolean si15_present,
2552 boolean si16_present,
2553 boolean si17_present,
2554 boolean si2n_present,
2555 boolean si21_present,
2556 boolean si22_present
2557}
2558
2559/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2560function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2561 var integer i;
2562 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2563 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002565 }
2566 }
2567 if (cfg.si1_present) {
2568 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2569 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2570 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2571 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2572 /* make sure *ALL* contain SI1 */
2573 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2574 }
2575 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2576 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2577 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2578 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2579 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2580 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2581
2582 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2583 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2584 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2585 * consecutive occurrences of TC = 4. */
2586 if (cfg.si2bis_present and not cfg.si2ter_present) {
2587 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2588 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2589 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2590 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2591 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2592 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2593 }
2594
2595 if (cfg.si7_present or cfg.si8_present) {
2596 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2597 * if System Information type 4 does not contain all information needed for cell
2598 * selection and reselection. */
2599 if (not cfg.bcch_extended) {
2600 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2601 }
2602 if (cfg.si7_present) {
2603 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2604 }
2605 if (cfg.si8_present) {
2606 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2607 }
2608 }
2609
2610 if (cfg.si2quater_present) {
2611 /* iii) System information type 2 quater is sent if needed, as determined by the system
2612 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2613 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2614 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2615 * within any of 4 consecutive occurrences of TC = 5. */
2616 if (not (cfg.bcch_extended)) {
2617 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2618 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2619 } else {
2620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2621 }
2622 } else {
2623 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2624 }
2625 }
2626 if (cfg.si9_present) {
2627 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2628 * in system information type 3 as defined in 3GPP TS 44.018. */
2629 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2630 }
2631 if (cfg.si13_present) {
2632 /* vii) System Information type 13 is only related to the GPRS service. System Information
2633 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2634 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2635 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2636 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2637 * within any of 4 consecutive occurrences of TC=4. */
2638 if (not cfg.bcch_extended) {
2639 log("not-bccch-extended");
2640 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2641 } else {
2642 log("bccch-extended");
2643 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2644 }
2645 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002647 }
2648 }
2649 if (cfg.si16_present or cfg.si17_present) {
2650 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2651 * should not be sent in a cell where network sharing is used (see rule xv). */
2652 if (cfg.si22_present) {
2653 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2654 }
2655 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002657 }
2658 if (not cfg.bcch_extended) {
2659 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2660 }
2661 if (cfg.si16_present) {
2662 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2663 }
2664 if (cfg.si17_present) {
2665 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2666 }
2667 }
2668
2669 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2670 * broadcast information. The frequency with which they are sent is determined by the
2671 * system operator. System Information type 9 identifies the scheduling of System
2672 * Information type 18 and 20 messages. */
2673
2674 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2675 * Information Type 19 is present, then its scheduling shall be indicated in System
2676 * Information Type 9. */
2677
2678 if (cfg.si15_present) {
2679 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2680 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2681 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2682 * 4 consecutive occurrences of TC = 1. */
2683 if (not cfg.bcch_extended) {
2684 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2685 } else {
2686 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2687 }
2688 }
2689 if (cfg.si13alt_present) {
2690 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2691 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2692 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2693 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2694 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2695 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2696 * of TC = 4. */
2697 if (cfg.si13_present) {
2698 testcase.stop("Error: Cannot have SI13alt and SI13");
2699 }
2700 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002702 }
2703 if (not cfg.bcch_extended) {
2704 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2705 } else {
2706 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2707 }
2708 }
2709 if (cfg.si2n_present) {
2710 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2711 * as determined by the system operator. In the case that the message is sent on the
2712 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2713 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2714 * consecutive occurrences of TC = 4. */
2715 if (not cfg.bcch_extended) {
2716 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2717 } else {
2718 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2719 }
2720 }
2721 if (cfg.si21_present) {
2722 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2723 * determined by the system operator. If Extended Access Barring is in use in the cell
2724 * then this message is sent at least once within any of 4 consecutive occurrences of
2725 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2726 * cell then this message shall only be sent on BCCH Ext. */
2727 if (not cfg.bcch_extended) {
2728 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2729 } else {
2730 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2731 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002733 }
2734 }
2735 }
2736 if (cfg.si22_present) {
2737 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2738 * should not be sent in a cell where SoLSA is used (see rule viii). System
2739 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2740 * =2 and TC=6. */
2741 if (cfg.si16_present or cfg.si17_present) {
2742 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2743 }
2744 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2745 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002747 }
2748 if (not cfg.bcch_extended) {
2749 testcase.stop("Error: SI22 requires BCCH Extd!");
2750 } else {
2751 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2752 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2753 }
2754 }
2755}
2756
2757/* sample Systme Information for specified duration via L1CTL */
2758function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2759 timer T := duration;
2760 var SystemInformationVectorPerTc si_per_tc;
2761 var L1ctlDlMessage l1_dl;
2762
2763 /* initialize all per-TC vectors empty */
2764 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2765 si_per_tc[i] := {};
2766 }
2767
2768 /* flush all previous L1 queued msgs */
2769 pt.clear;
2770
2771 T.start;
2772 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002773 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002774 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2775 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2776 log("Ignoring non-RR SI ", l1_dl);
2777 repeat;
2778 }
2779 var SystemInformationFn sig := {
2780 frame_number := l1_dl.dl_info.frame_nr,
2781 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2782 }
2783 var integer tc := f_gsm_compute_tc(sig.frame_number);
2784 log("SI received at TC=", tc, ": ", sig.si);
2785 /* append to the per-TC bucket */
2786 si_per_tc[tc] := si_per_tc[tc] & { sig };
2787 repeat;
2788 }
2789 [] pt.receive { repeat; }
2790 [] T.timeout { }
2791 }
2792
2793 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2794 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2795 }
2796 log("si_per_tc=", si_per_tc);
2797 return si_per_tc;
2798}
2799
2800/* helper function: Set given SI via RSL + validate scheduling.
2801 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2802function f_TC_si_sched() runs on test_CT {
2803 var SystemInformationVectorPerTc si_per_tc;
2804 f_init_l1ctl();
2805 f_l1_tune(L1CTL);
2806
2807 /* Sample + Validate Scheduling */
2808 si_per_tc := f_l1_sample_si(L1CTL);
2809 f_validate_si_scheduling(si_cfg, si_per_tc);
2810
2811 setverdict(pass);
2812}
2813
2814testcase TC_si_sched_default() runs on test_CT {
2815 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002816 /* 2+3+4 are mandatory and set in f_init() */
2817 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002819}
2820
2821testcase TC_si_sched_1() runs on test_CT {
2822 f_init();
2823 si_cfg.si1_present := true;
2824 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002825 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002827}
2828
2829testcase TC_si_sched_2bis() runs on test_CT {
2830 f_init();
2831 si_cfg.si2bis_present := true;
2832 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2833 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002835}
2836
2837testcase TC_si_sched_2ter() runs on test_CT {
2838 f_init();
2839 si_cfg.si2ter_present := true;
2840 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2841 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002843}
2844
2845testcase TC_si_sched_2ter_2bis() runs on test_CT {
2846 f_init();
2847 si_cfg.si2bis_present := true;
2848 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2849 si_cfg.si2ter_present := true;
2850 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2851 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002853}
2854
2855testcase TC_si_sched_2quater() runs on test_CT {
2856 f_init();
2857 si_cfg.si2quater_present := true;
2858 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2859 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002861}
2862
2863testcase TC_si_sched_13() runs on test_CT {
2864 f_init();
2865 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002866 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002867 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002869}
2870
2871testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2872 f_init();
2873 si_cfg.si2bis_present := true;
2874 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2875 si_cfg.si2ter_present := true;
2876 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2877 si_cfg.si2quater_present := true;
2878 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2879 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002880 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002881 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002883}
2884
2885
Harald Welte68e495b2018-02-25 00:05:57 +01002886testcase TC_bcch_info() runs on test_CT {
2887 f_init(testcasename());
2888 /* FIXME: enable / disable individual BCCH info */
2889 //ts_RSL_BCCH_INFO(si_type, info);
2890 /* expect no ERROR REPORT after either of them *
2891 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002893}
2894
Harald Welte93640c62018-02-25 16:59:33 +01002895/***********************************************************************
2896 * Low-Level Protocol Errors / ERROR REPORT
2897 ***********************************************************************/
2898
Harald Welte01d982c2018-02-25 01:31:40 +01002899private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2900 timer T := 5.0;
2901 T.start;
2902 alt {
2903 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2904 setverdict(pass);
2905 }
2906 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002908 }
2909 [] RSL_CCHAN.receive {
2910 repeat;
2911 }
2912 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002914 }
2915 }
2916}
2917
2918/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2919testcase TC_rsl_protocol_error() runs on test_CT {
2920 f_init(testcasename());
2921 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2922 rsl.ies := omit;
2923 RSL_CCHAN.send(ts_RSL_UD(rsl));
2924
2925 f_exp_err_rep(RSL_ERR_PROTO);
2926}
2927
2928/* Provoke a mandatory IE error and match on ERROR REPORT */
2929testcase TC_rsl_mand_ie_error() runs on test_CT {
2930 f_init(testcasename());
2931
2932 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2933 rsl.ies := { rsl.ies[0] };
2934 RSL_CCHAN.send(ts_RSL_UD(rsl));
2935
2936 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2937}
2938
2939/* Provoke an IE content error and match on ERROR REPORT */
2940testcase TC_rsl_ie_content_error() runs on test_CT {
2941 f_init(testcasename());
2942 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2943 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2944 RSL_CCHAN.send(ts_RSL_UD(rsl));
2945
2946 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2947}
2948
Harald Welteee25aae2019-05-19 14:32:37 +02002949/* attempt to activate channel with wrong RSL Message Discriminator IE */
2950function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2951 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2952 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2953 RSL.send(rsl);
2954 f_rslem_unregister(0, g_chan_nr);
2955}
2956testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2957 var ConnHdlr vc_conn;
2958 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2959
2960 f_init(testcasename());
2961
2962 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2963 vc_conn.done;
2964 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2965
2966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2967}
2968
2969/* Send messages with wrong message type */
2970function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2971 var template (value) RSL_Message rsl_tx;
2972 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2973 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2974 RSL.send(rsl_tx);
2975 f_rslem_unregister(0, g_chan_nr);
2976}
2977function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
2978 var template (value) RSL_Message rsl_tx;
2979 /* we first have to activate the dedicated channel */
2980 f_rsl_chan_act(g_pars.chan_mode);
2981 /* ... to then send an invalid RLL message */
2982 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
2983 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
2984 RSL.send(rsl_tx);
2985 f_rslem_unregister(0, g_chan_nr);
2986}
2987testcase TC_err_rep_wrong_msg_type() runs on test_CT {
2988 var ConnHdlr vc_conn;
2989 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2990 var template (value) RSL_Message rsl_tx;
2991
2992 f_init(testcasename());
2993
2994 /* Common Channel with wrong message type */
2995 RSL_CCHAN.clear;
2996 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2997 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
2998 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
2999 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3000
3001 /* TRX Management */
3002 RSL_CCHAN.clear;
3003 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3004 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3005 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3006 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3007
3008 /* Dedicated Channel */
3009 RSL_CCHAN.clear;
3010 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3011 vc_conn.done;
3012 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3013
3014 /* RLL */
3015 RSL_CCHAN.clear;
3016 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3017 vc_conn.done;
3018 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3019}
3020
3021/* Send messages in wrong sequence (RLL to an inactive lchan) */
3022function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3023 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3024 f_rslem_unregister(0, g_chan_nr);
3025}
3026testcase TC_err_rep_wrong_sequence() runs on test_CT {
3027 var ConnHdlr vc_conn;
3028 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3029
3030 f_init(testcasename());
3031
3032 RSL_CCHAN.clear;
3033 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3034 vc_conn.done;
3035 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3036}
3037
Harald Welte93640c62018-02-25 16:59:33 +01003038/***********************************************************************
3039 * IPA CRCX/MDCX/DLCS media stream handling
3040 ***********************************************************************/
3041
Harald Weltea871a382018-02-25 02:03:14 +01003042/* Send IPA DLCX to inactive lchan */
3043function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003044 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3045 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003046}
3047testcase TC_ipa_dlcx_not_active() runs on test_CT {
3048 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3049 f_init(testcasename());
3050 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3051 vc_conn.done;
3052}
Harald Welte68e495b2018-02-25 00:05:57 +01003053
Harald Weltea3f1df92018-02-25 12:49:55 +01003054/* Send IPA CRCX twice to inactive lchan */
3055function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3056 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3057 "IPA CRCX ACK");
3058 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3059 "IPA CRCX NACK");
3060}
3061testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3062 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3063 f_init(testcasename());
3064 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3065 vc_conn.done;
3066}
3067
3068/* Regular sequence of CRCX/MDCX/DLCX */
3069function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3070 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3071 "IPA CRCX ACK");
3072 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3073 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3074 var uint7_t rtp_pt2 := f_rnd_int(127);
3075 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3076 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3077 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3078 "IPA MDCX ACK");
3079 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3080 "IPA DLCX ACK");
3081}
3082testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3083 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3084 f_init(testcasename());
3085 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3086 vc_conn.done;
3087}
3088
Harald Welte3ae11da2018-02-25 13:36:06 +01003089/* Sequence of CRCX, 2x MDCX, DLCX */
3090function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3091 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3092 "IPA CRCX ACK");
3093 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3094 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3095 var uint7_t rtp_pt2 := f_rnd_int(127);
3096 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3097 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3098 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3099 "IPA MDCX ACK");
3100 /* Second MDCX */
3101 remote_ip := f_rnd_int(c_UINT32_MAX);
3102 remote_port := f_rnd_int(c_UINT16_MAX);
3103 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3104 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3105 "IPA MDCX ACK");
3106 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3107 "IPA DLCX ACK");
3108}
3109testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3110 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3111 f_init(testcasename());
3112 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3113 vc_conn.done;
3114}
3115
Harald Welte9912eb52018-02-25 13:30:15 +01003116/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3117function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3118 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3119 "IPA CRCX NACK");
3120}
3121testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3122 var ConnHdlrPars pars;
3123 var ConnHdlr vc_conn;
3124 f_init(testcasename());
3125
3126 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3127 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3128 vc_conn.done;
3129
3130 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3131 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3132 vc_conn.done;
3133}
3134
Harald Weltea3f1df92018-02-25 12:49:55 +01003135
Harald Welte883340c2018-02-28 18:59:29 +01003136/***********************************************************************
3137 * PCU Socket related tests
3138 ***********************************************************************/
3139
Harald Welte07bd2d22019-05-25 11:03:30 +02003140/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003141friend 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 +01003142runs on test_CT {
3143 timer T := 3.0;
3144
3145 /* we don't expect any RTS.req before PDCH are active */
3146 T.start;
3147 alt {
3148 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003150 }
3151 [] PCU.receive { repeat; }
3152 [] T.timeout { }
3153 }
3154
3155 /* Send PDCH activate request for known PDCH timeslot */
3156 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3157
3158 /* we now expect RTS.req for this timeslot (only) */
3159 T.start;
3160 alt {
3161 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3162 setverdict(pass);
3163 }
3164 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3165 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003167 }
3168 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003170 }
3171 [] PCU.receive { repeat; }
3172 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003174 }
3175 [not exp_success] T.timeout {
3176 setverdict(pass);
3177 }
3178 }
3179}
3180
Harald Welte07bd2d22019-05-25 11:03:30 +02003181/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003182friend 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 +01003183runs on test_CT {
3184 timer T := 3.0;
3185
3186 /* Send PDCH activate request for known PDCH timeslot */
3187 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3188
3189 PCU.clear;
3190 /* we now expect no RTS.req for this timeslot */
3191 T.start;
3192 alt {
3193 [] 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 +02003194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003195 }
3196 [] PCU.receive { repeat; }
3197 [] T.timeout {
3198 setverdict(pass);
3199 }
3200 }
3201}
3202
Harald Weltead033dc2019-05-25 17:28:16 +02003203friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003204 f_init();
3205 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3206}
3207
Harald Welte883340c2018-02-28 18:59:29 +01003208/* PDCH activation via PCU socket; check for presence of RTS.req */
3209testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003210 f_init_pcu_test();
3211
Harald Welte883340c2018-02-28 18:59:29 +01003212 f_TC_pcu_act_req(0, 0, 7, true);
3213}
3214
3215/* PDCH activation via PCU socket on non-PDCU timeslot */
3216testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003217 f_init_pcu_test();
3218
Harald Welte883340c2018-02-28 18:59:29 +01003219 f_TC_pcu_act_req(0, 0, 1, false);
3220}
3221
3222/* PDCH activation via PCU socket on wrong BTS */
3223testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003224 f_init_pcu_test();
3225
Harald Welte883340c2018-02-28 18:59:29 +01003226 f_TC_pcu_act_req(23, 0, 7, false);
3227}
3228
3229/* PDCH activation via PCU socket on wrong TRX */
3230testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003231 f_init_pcu_test();
3232
Harald Welte883340c2018-02-28 18:59:29 +01003233 f_TC_pcu_act_req(0, 23, 7, false);
3234}
3235
3236/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3237testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003238 f_init_pcu_test();
3239
Harald Welte883340c2018-02-28 18:59:29 +01003240 /* Activate PDCH */
3241 f_TC_pcu_act_req(0, 0, 7, true);
3242 f_sleep(1.0);
3243 /* and De-Activate again */
3244 f_TC_pcu_deact_req(0, 0, 7);
3245}
3246
3247/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3248testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003249 f_init_pcu_test();
3250
Harald Welte883340c2018-02-28 18:59:29 +01003251 f_TC_pcu_deact_req(0, 0, 1);
3252}
3253
3254/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3255testcase TC_pcu_ver_si13() runs on test_CT {
3256 const octetstring si13 := '00010203040506070909'O;
3257 var PCUIF_send_data sd;
3258 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003259 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003260
3261 /* Set SI13 via RSL */
3262 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003263
Harald Welte883340c2018-02-28 18:59:29 +01003264 T.start;
3265 alt {
3266 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3267 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3268 setverdict(pass);
3269 } else {
3270 repeat;
3271 }
3272 }
3273 [] PCU.receive { repeat; }
3274 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003276 }
3277 }
3278}
3279
3280private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3281
3282/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003283friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003284 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3285runs on test_CT
3286{
3287 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3288 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3289}
3290
3291/* 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 +02003292friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3293 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003294runs on test_CT
3295{
3296 var PCUIF_send_data sd;
3297
3298 timer T := 3.0;
3299 T.start;
3300 alt {
3301 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3302 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3303 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3304 sd.data.u.rts_req.fn, sapi, data);
3305 }
3306 [] PCU.receive { repeat; }
3307 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003309 }
3310 }
3311}
3312
3313/* Send DATA.req on invalid BTS */
3314testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003315 var TfiUsfArr tua := f_TfiUsfArrInit();
3316 var octetstring data := '0000'O & f_rnd_octstring(21);
3317
3318 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003319
Harald Welte883340c2018-02-28 18:59:29 +01003320 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003321 f_TfiUsfArrSet(tua, 7, 0);
3322 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3323 f_sleep(1.0);
3324
3325 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003326}
3327
3328/* Send DATA.req on invalid TRX */
3329testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003330 var TfiUsfArr tua := f_TfiUsfArrInit();
3331 var octetstring data := '0000'O & f_rnd_octstring(21);
3332
3333 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003334
Harald Welte883340c2018-02-28 18:59:29 +01003335 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003336 f_TfiUsfArrSet(tua, 7, 0);
3337 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3338 f_sleep(1.0);
3339
3340 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003341}
3342
3343/* Send DATA.req on invalid timeslot */
3344testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003345 var TfiUsfArr tua := f_TfiUsfArrInit();
3346 var octetstring data := '0000'O & f_rnd_octstring(21);
3347
3348 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003349
Harald Welte883340c2018-02-28 18:59:29 +01003350 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003351 f_TfiUsfArrSet(tua, 7, 0);
3352 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3353 f_sleep(1.0);
3354
3355 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003356}
3357
3358/* Send DATA.req on timeslot that hasn't been activated */
3359testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003360 var TfiUsfArr tua := f_TfiUsfArrInit();
3361 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003362
Harald Welte7162a612019-05-26 12:56:09 +02003363 f_virtphy_common();
3364
3365 f_TfiUsfArrSet(tua, 7, 0);
3366 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3367 f_sleep(1.0);
3368
3369 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003370}
3371
Harald Weltead033dc2019-05-25 17:28:16 +02003372private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003373 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3374 boolean wait_rts := true)
3375runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003376 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003377 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003378
3379 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003380 if (wait_rts) {
3381 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3382 } else {
3383 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3384 }
Harald Weltead033dc2019-05-25 17:28:16 +02003385
3386 T.start;
3387 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003388 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003389 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3390 setverdict(pass);
3391 }
Harald Welte7162a612019-05-26 12:56:09 +02003392 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3393 setverdict(fail, "Received unexpected ", rx_dl);
3394 }
Harald Weltead033dc2019-05-25 17:28:16 +02003395 [] L1CTL.receive {
3396 repeat;
3397 }
Harald Welte7162a612019-05-26 12:56:09 +02003398 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003399 setverdict(fail, "Timeout waiting for ", data);
3400 }
Harald Welte7162a612019-05-26 12:56:09 +02003401 [not expect_data] T.timeout {
3402 setverdict(pass);
3403 }
Harald Weltead033dc2019-05-25 17:28:16 +02003404 }
3405}
3406
3407private function f_disable_dynamic_ts() runs on test_CT
3408{
3409 f_init_vty_bsc();
3410 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3411 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3412 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3413 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003414 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003415}
3416
3417private function f_virtphy_common() runs on test_CT {
3418 f_disable_dynamic_ts();
3419 f_init_l1ctl();
3420 f_l1_tune(L1CTL);
3421}
3422
3423testcase TC_pcu_data_req_pdtch() runs on test_CT {
3424 var TfiUsfArr tua := f_TfiUsfArrInit();
3425 var octetstring data := '0000'O & f_rnd_octstring(21);
3426
3427 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003428
Harald Welte883340c2018-02-28 18:59:29 +01003429 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003430 f_TfiUsfArrSet(tua, 7, 0);
3431 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3432 f_sleep(1.0);
3433
3434 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003435}
3436
3437testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003438 var TfiUsfArr tua := f_TfiUsfArrInit();
3439 var octetstring data := '0000'O & f_rnd_octstring(21);
3440
3441 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003442
Harald Welte883340c2018-02-28 18:59:29 +01003443 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003444 f_TfiUsfArrSet(tua, 7, 0);
3445 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3446 f_sleep(1.0);
3447
3448 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003449}
3450
3451/* Send AGCH from PCU; check it appears on Um side */
3452testcase TC_pcu_data_req_agch() runs on test_CT {
3453 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003454 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003455 f_init_l1ctl();
3456 f_l1_tune(L1CTL);
3457
3458 f_TC_pcu_act_req(0, 0, 7, true);
3459 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3460
3461 T.start;
3462 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003463 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003464 setverdict(pass);
3465 }
3466 [] L1CTL.receive { repeat; }
3467 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003469 }
3470 }
3471}
3472
3473/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3474testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3475 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003476 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003477 f_init_l1ctl();
3478 f_l1_tune(L1CTL);
3479
3480 /* append 3 last imsi digits so BTS can compute pagng group */
3481 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3482
3483 timer T := 0.5;
3484 T.start;
3485 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003486 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003487 /* TODO: verify paging group */
3488 setverdict(pass);
3489 }
3490 [] L1CTL.receive { repeat; }
3491 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003493 }
3494 }
3495}
3496
3497/* Send RACH from Um side, expect it to show up on PCU socket */
3498testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003499 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003500 f_init_l1ctl();
3501 f_l1_tune(L1CTL);
3502
3503 var GsmFrameNumber fn_last := 0;
3504 for (var integer i := 0; i < 1000; i := i+1) {
3505 var OCT1 ra := f_rnd_ra_ps();
3506 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3507 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003509 }
3510 fn_last := fn;
3511
3512 timer T := 2.0;
3513 T.start;
3514 alt {
3515 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3516 T.stop;
3517 }
3518 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003520 }
3521 [] PCU.receive { repeat; }
3522 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003524 }
3525 }
3526 }
3527 setverdict(pass);
3528}
3529
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003530/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3531 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3532testcase TC_pcu_ext_rach_content() runs on test_CT {
3533 var template PCUIF_Message pcu_rach_ind;
3534 var GsmFrameNumber fn_last := 0;
3535 var L1ctlRachSynchSeq synch_seq;
3536 var PCUIF_BurstType pcu_bt;
3537 var GsmFrameNumber fn;
3538 var BIT11 ra11;
3539
3540 f_init_pcu_test();
3541 f_init_l1ctl();
3542 f_l1_tune(L1CTL);
3543
3544 for (var integer i := 0; i < 1000; i := i+1) {
3545 /* We need to test both TS1 & TS2 */
3546 if (i rem 2 == 0) {
3547 synch_seq := RACH_SYNCH_SEQ_TS1;
3548 pcu_bt := BURST_TYPE_1;
3549 } else {
3550 synch_seq := RACH_SYNCH_SEQ_TS2;
3551 pcu_bt := BURST_TYPE_2;
3552 }
3553
3554 ra11 := f_rnd_ra11_ps();
3555 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3556 if (fn == fn_last) {
3557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3558 "Two RACH in same FN?!?");
3559 }
3560 fn_last := fn;
3561
3562 /* Compose the expected message */
3563 pcu_rach_ind := tr_PCUIF_RACH_IND(
3564 bts_nr := 0,
3565 ra := bit2int(ra11),
3566 is_11bit := 1,
3567 burst_type := pcu_bt,
3568 fn := fn);
3569
3570 timer T := 2.0;
3571 T.start;
3572 alt {
3573 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3574 T.stop;
3575 }
3576 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3578 }
3579 [] PCU.receive { repeat; }
3580 [] T.timeout {
3581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3582 }
3583 }
3584 }
3585 setverdict(pass);
3586}
3587
Harald Welte883340c2018-02-28 18:59:29 +01003588private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3589 var integer strlen := lengthof(str);
3590 for (var integer i := 0; i < len-strlen; i := i+1) {
3591 str := str & pad;
3592 }
3593 return str;
3594}
3595
3596/* Send PAGING via RSL, expect it to shw up on PCU socket */
3597testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003598 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003599
3600 for (var integer i := 0; i < 100; i := i+1) {
3601 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3602 timer T := 3.0;
3603 if (i < 50) {
3604 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3605 } else {
3606 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3607 }
3608 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3609 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3610 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3611
3612 /* Send RSL PAGING COMMAND */
3613 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3614 T.start;
3615 alt {
3616 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3617 }
3618 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003620 }
3621 [] PCU.receive { repeat; }
3622 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003624 }
3625 }
3626 }
3627 setverdict(pass);
3628}
3629
Harald Welted66c9b82019-05-25 09:03:15 +02003630/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3631testcase TC_pcu_time_ind() runs on test_CT {
3632 var PCUIF_send_data pcu_sd;
3633 var integer num_time_ind := 0;
3634 var integer first_fn, last_fn;
3635 var float test_duration := 5.0;
3636 timer T;
3637
3638 f_init_pcu_test();
3639 f_TC_pcu_act_req(0, 0, 7, true);
3640
3641 PCU.clear;
3642 T.start(test_duration);
3643 alt {
3644 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3645 num_time_ind := num_time_ind + 1;
3646 if (not isbound(first_fn)) {
3647 first_fn := pcu_sd.data.u.time_ind.fn;
3648 }
3649 last_fn := pcu_sd.data.u.time_ind.fn;
3650 repeat;
3651 }
3652 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3653 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3654 repeat;
3655 }
3656 [] PCU.receive {
3657 repeat;
3658 }
3659 [] T.timeout {}
3660 }
3661 var integer fn_expired := last_fn - first_fn;
3662 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3663
3664 /* verify the number of frames expired matches our expectation */
3665 const float c_GSM_FN_DURATION_MS := 4.61538;
3666 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3667 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3668 if (not match(fn_expired, t_fn_expected)) {
3669 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3670 }
3671
3672 /* There are three TIME.ind in every fn MOD 13 */
3673 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3674 /* Add some tolerance */
3675 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3676 if (not match(num_time_ind, t_time_ind_exp)) {
3677 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3678 }
3679
3680 setverdict(pass);
3681}
3682
Harald Welte4832c862019-05-25 14:57:18 +02003683/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3684testcase TC_pcu_rts_req() runs on test_CT {
3685 var PCUIF_send_data pcu_sd;
3686 var integer first_fn, last_fn;
3687 var integer num_rts_pdtch := 0;
3688 var integer num_rts_ptcch := 0;
3689 var float test_duration := 5.0;
3690 timer T;
3691
3692 f_init_pcu_test();
3693 f_TC_pcu_act_req(0, 0, 7, true);
3694
3695 PCU.clear;
3696 T.start(test_duration);
3697 alt {
3698 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3699 -> value pcu_sd {
3700 num_rts_pdtch := num_rts_pdtch + 1;
3701 if (not isbound(first_fn)) {
3702 first_fn := pcu_sd.data.u.rts_req.fn;
3703 }
3704 last_fn := pcu_sd.data.u.rts_req.fn;
3705 repeat;
3706 }
3707 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3708 -> value pcu_sd {
3709 num_rts_ptcch := num_rts_ptcch + 1;
3710 if (not isbound(first_fn)) {
3711 first_fn := pcu_sd.data.u.rts_req.fn;
3712 }
3713 last_fn := pcu_sd.data.u.rts_req.fn;
3714 repeat;
3715 }
3716 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3717 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3718 repeat;
3719 }
3720 [] PCU.receive {
3721 repeat;
3722 }
3723 [] T.timeout {}
3724 }
3725 var integer fn_expired := last_fn - first_fn;
3726 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3727 ", num_rts_ptcch=", num_rts_ptcch);
3728
3729 /* verify the number of frames expired matches our expectation */
3730 const float c_GSM_FN_DURATION_MS := 4.61538;
3731 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3732 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3733 if (not match(fn_expired, t_fn_expected)) {
3734 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3735 }
3736
3737 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3738 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3739 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3740 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3741 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3742 t_ptcch_exp);
3743 }
3744
3745 /* We have 12 PDTCH blocks every 52-multiframe */
3746 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3747 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3748 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3749 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3750 t_pdtch_exp);
3751 }
3752
3753 setverdict(pass);
3754}
3755
Harald Welte07bd2d22019-05-25 11:03:30 +02003756/* test for generating Abis side OML ALERT from the PCU */
3757testcase TC_pcu_oml_alert() runs on test_CT {
3758 var PCUIF_send_data pcu_sd;
3759 var integer num_time_ind := 0;
3760 var integer first_fn, last_fn;
3761 var float test_duration := 5.0;
3762 timer T;
3763
3764 f_init_pcu_test();
3765 f_TC_pcu_act_req(0, 0, 7, true);
3766
3767 /* re-connect CTRL port from BTS to BSC */
3768 f_ipa_ctrl_stop();
3769 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3770
3771 /* Send that OML Alert */
3772 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3773
3774 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3775 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3776 setverdict(pass);
3777}
3778
3779
Harald Welted66c9b82019-05-25 09:03:15 +02003780
Harald Welte3d04ae62018-04-04 20:29:05 +02003781/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003782 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003783 ***********************************************************************/
3784
3785private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3786runs on ConnHdlr {
3787 var PCUIF_send_data sd;
3788 /* Expect BTS to immediately acknowledge activation as PDCH */
3789 PCU.clear;
3790 f_rsl_chan_act(g_pars.chan_mode);
3791 /* expect INFO_IND on PCU interface listing TS as PDCH */
3792 alt {
3793 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3794 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003796 }
3797 }
3798 [] PCU.receive { repeat; }
3799 }
3800 /* try to activate this PDCH from the PCU point of view */
3801 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3802 /* FIXME: is there a response? */
3803}
3804
3805private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3806runs on ConnHdlr {
3807 var PCUIF_send_data sd;
3808 /* Send RSL CHAN REL (deactivate) */
3809 PCU.clear;
3810 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3811 /* expect BTS to ask PCU to deactivate the channel */
3812 alt {
3813 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3814 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003816 }
3817 }
3818 [] PCU.receive { repeat; }
3819 }
3820 /* Emulate PCU asking BTS to deactivate PDCH */
3821 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3822 alt {
3823 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3824 setverdict(pass);
3825 }
3826 [] RSL.receive { repeat; }
3827 }
3828}
3829
3830/* Activate Osmocom-style dynamic PDCH from BSC side */
3831function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3832 var PCUIF_Message first_info;
3833 var integer ts_nr := g_chan_nr.tn;
3834 var integer trx_nr := 0;
3835 var integer bts_nr := 0;
3836 var integer pcu_conn_id := -1;
3837
3838 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3839
3840 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3841 f_sleep(3.0);
3842 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3843 setverdict(pass);
3844}
3845testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3846 var ConnHdlrPars pars;
3847 var ConnHdlr vc_conn;
3848 f_init(testcasename());
3849
3850 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3851 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3852 vc_conn.done;
3853}
3854
3855/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3856function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3857 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003858 var integer pcu_conn_id := -1;
3859
3860 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3861
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003862 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3863 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3864 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003865 setverdict(pass);
3866}
3867testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3868 var ConnHdlrPars pars;
3869 var ConnHdlr vc_conn;
3870 f_init(testcasename());
3871
3872 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3873 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3874 vc_conn.done;
3875}
3876
3877/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3878function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3879 var PCUIF_Message first_info;
3880 var integer ts_nr := g_chan_nr.tn;
3881 var integer trx_nr := 0;
3882 var integer bts_nr := 0;
3883 var integer pcu_conn_id := -1;
3884
3885 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3886
3887 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003888 /* Send a second Chan Activ and expect it to be NACKed */
3889 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3890 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003891 setverdict(pass);
3892}
3893testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3894 var ConnHdlrPars pars;
3895 var ConnHdlr vc_conn;
3896 f_init(testcasename());
3897
3898 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3899 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3900 vc_conn.done;
3901}
3902
3903/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3904function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3905 var PCUIF_Message first_info;
3906 var integer ts_nr := g_chan_nr.tn;
3907 var integer trx_nr := 0;
3908 var integer bts_nr := 0;
3909 var integer pcu_conn_id := -1;
3910 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3911
3912 /* register for the TCH/F channel number */
3913 f_rslem_register(0, chan_nr);
3914
3915 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3916
3917 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3918 "RSL CHAN ACT");
3919 setverdict(pass);
3920}
3921testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3922 var ConnHdlrPars pars;
3923 var ConnHdlr vc_conn;
3924 f_init(testcasename());
3925
3926 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3927 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3928 vc_conn.done;
3929}
3930
3931/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3932function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3933 var PCUIF_Message first_info;
3934 var integer ts_nr := g_chan_nr.tn;
3935 var integer trx_nr := 0;
3936 var integer bts_nr := 0;
3937 var integer pcu_conn_id := -1;
3938 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3939 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3940
3941 /* register for the TCH/H channel numbers */
3942 f_rslem_register(0, chan_nr[0]);
3943 f_rslem_register(0, chan_nr[1]);
3944
3945 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3946
3947 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3948 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3949 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3950 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3951 setverdict(pass);
3952}
3953testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3954 var ConnHdlrPars pars;
3955 var ConnHdlr vc_conn;
3956 f_init(testcasename());
3957
3958 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3959 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3960 vc_conn.done;
3961}
3962
Harald Welte9bbbfb52018-04-05 09:33:19 +02003963/***********************************************************************
3964 * IPA Style Dynamic Timeslot Support
3965 ***********************************************************************/
3966
3967private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3968runs on ConnHdlr {
3969 var PCUIF_send_data sd;
3970 /* Expect BTS to immediately acknowledge activation as PDCH */
3971 PCU.clear;
3972 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3973 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003974 timer T_wait := 2.0;
3975 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003976 alt {
3977 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3978 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003979 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
3980 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3981 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003982 }
3983 }
3984 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003985 [] T_wait.timeout {
3986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3987 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
3988 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003989 }
3990 /* try to activate this PDCH from the PCU point of view */
3991 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3992 /* FIXME: is there a response? */
3993
3994 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3995}
3996
3997private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3998runs on ConnHdlr {
3999 var PCUIF_send_data sd;
4000 /* Send RSL CHAN REL (deactivate) */
4001 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4002 PCU.clear;
4003 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004004 timer T_wait := 2.0;
4005 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004006 alt {
4007 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4008 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004009 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4010 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4011 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004012 }
4013 }
4014 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004015 [] T_wait.timeout {
4016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4017 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4018 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004019 }
4020 /* Emulate PCU asking BTS to deactivate PDCH */
4021 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4022 alt {
4023 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4024 setverdict(pass);
4025 }
4026 [] RSL.receive { repeat; }
4027 }
4028}
4029
4030/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4031function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4032 var PCUIF_Message first_info;
4033 var integer ts_nr := g_chan_nr.tn;
4034 var integer trx_nr := 0;
4035 var integer bts_nr := 0;
4036 var integer pcu_conn_id := -1;
4037
4038 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4039
4040 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4041 f_sleep(3.0);
4042 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4043
4044 setverdict(pass);
4045
4046}
4047testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4048 var ConnHdlrPars pars;
4049 var ConnHdlr vc_conn;
4050 f_init();
4051
4052 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4053 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4054 vc_conn.done;
4055}
4056
4057/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4058function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4059 var PCUIF_Message first_info;
4060 var integer ts_nr := g_chan_nr.tn;
4061 var integer trx_nr := 0;
4062 var integer bts_nr := 0;
4063 var integer pcu_conn_id := -1;
4064
4065 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4066
4067 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4068 "RSL CHAN ACT");
4069 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4070 "RF CHAN REL", true);
4071 setverdict(pass);
4072}
4073testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4074 var ConnHdlrPars pars;
4075 var ConnHdlr vc_conn;
4076 f_init(testcasename());
4077
4078 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4079 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4080 vc_conn.done;
4081}
4082
4083/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4084function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4085 var PCUIF_Message first_info;
4086 var integer ts_nr := g_chan_nr.tn;
4087 var integer trx_nr := 0;
4088 var integer bts_nr := 0;
4089 var integer pcu_conn_id := -1;
4090
4091 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4092
4093 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4094 "RSL CHAN ACT");
4095
4096 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4097 alt {
4098 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4099 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004101 }
4102 [] RSL.receive { repeat; }
4103 }
4104
4105 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4106 "RF CHAN REL", true);
4107 setverdict(pass);
4108}
4109testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4110 var ConnHdlrPars pars;
4111 var ConnHdlr vc_conn;
4112 f_init(testcasename());
4113
4114 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4115 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4116 vc_conn.done;
4117}
4118
4119/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4120function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4121 var PCUIF_Message first_info;
4122 var integer ts_nr := g_chan_nr.tn;
4123 var integer trx_nr := 0;
4124 var integer bts_nr := 0;
4125 var integer pcu_conn_id := -1;
4126
4127 /* register for the TCH/F channel number */
4128 f_rslem_register(0, g_chan_nr);
4129
4130 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4131
4132 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4133
4134 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4135 "RSL CHAN ACT");
4136
4137 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4138
4139 setverdict(pass);
4140}
4141testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4142 var ConnHdlrPars pars;
4143 var ConnHdlr vc_conn;
4144 f_init(testcasename());
4145
4146 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4147 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4148 vc_conn.done;
4149}
4150
4151
Harald Welte0472ab42018-03-12 15:02:26 +01004152/***********************************************************************
4153 * LAPDm / RLL related
4154 ***********************************************************************/
4155
4156private function f_tx_lapdm(template (value) LapdmFrame l,
4157 template (value) RslLinkId link_id) runs on ConnHdlr {
4158 var octetstring l2 := enc_LapdmFrame(valueof(l));
4159 if (valueof(link_id.c) == SACCH) {
4160 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004161 var L1ctlDataReq l1hl2 := {
4162 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4163 l2_payload := f_pad_oct(l2, 21, '2B'O)
4164 }
4165 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4166 } else {
4167 /* If required, pad L2 frame with constant 0x2b filling */
4168 l2 := f_pad_oct(l2, 23, '2B'O);
4169
4170 log("encoding ", l, " to ", l2);
4171 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004172 }
Harald Welte0472ab42018-03-12 15:02:26 +01004173}
4174
4175type record RllTestCase {
4176 uint3_t sapi,
4177 RslLinkId link_id,
4178 octetstring l3,
4179 boolean exp
4180}
4181type record of RllTestCase RllTestCases;
4182template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4183 sapi := sapi,
4184 link_id := id,
4185 l3 := l3,
4186 exp := exp
4187}
4188
4189/* execute the same callback function with a set of different parameters (tcs) on a
4190 * variety of logical channels */
4191private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4192 var ConnHdlrPars pars;
4193 var ConnHdlr vc_conn;
4194 f_init(testcasename());
4195
4196 /* test on each of the channels we have */
4197 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4198 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4199
4200 /* test each of the test cases on the current channel */
4201 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4202 pars.spec.rll := tcs[j];
4203 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4204 vc_conn := f_start_handler(fn, pars);
4205 vc_conn.done;
4206 }
4207 }
4208
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004210}
4211
4212/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4213private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4214 var RllTestCase tc := g_pars.spec.rll;
4215 timer T := 3.0;
4216
4217 f_l1_tune(L1CTL);
4218 RSL.clear;
4219
4220 /* activate the logical channel */
4221 f_est_dchan();
4222 L1CTL.clear;
4223
4224 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4225 T.start;
4226 alt {
4227 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4228 if (tc.exp) {
4229 setverdict(pass);
4230 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004232 }
4233 }
4234 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4235 if (tc.exp) {
4236 setverdict(pass);
4237 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004239 }
4240 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004241 /* We also expect to receive the measurements */
4242 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004243 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004245 }
4246 [not tc.exp] T.timeout {
4247 setverdict(pass);
4248 }
4249 }
4250
4251 f_rsl_chan_deact();
4252 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4253 f_rslem_unregister(0, g_chan_nr);
4254}
4255testcase TC_rll_est_ind() runs on test_CT {
4256 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004257 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004258 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004259 /* normal SAPI0 establishment */
4260 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004261 /* SAPI 3 doesn't support contention resolution */
4262 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4263 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4264 /* normal SAPI3 establishment on main DCCH */
4265 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4266 /* normal SAPI3 establishment on SACCH */
4267 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4268 };
4269 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4270}
4271
4272/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4273private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4274 var RllTestCase tc := g_pars.spec.rll;
4275 var L1ctlDlMessage dl;
4276 timer T := 3.0;
4277
4278 f_l1_tune(L1CTL);
4279 RSL.clear;
4280
4281 /* activate the logical channel */
4282 f_est_dchan();
4283 L1CTL.clear;
4284
4285 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4286 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4287 T.start;
4288 alt {
4289 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4290 var LapdmFrame lapdm;
4291 var octetstring l2 := dl.payload.data_ind.payload;
4292 if (dl.dl_info.link_id.c == SACCH) {
4293 /* remove L1 header */
4294 l2 := substr(l2, 2, lengthof(l2)-2);
4295 }
4296 lapdm.ab := dec_LapdmFrameAB(l2);
4297 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4298 setverdict(pass);
4299 } else {
4300 repeat;
4301 }
4302 }
4303 [] L1CTL.receive { repeat; }
4304 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004306 }
4307 }
4308
4309 f_rsl_chan_deact();
4310 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4311 f_rslem_unregister(0, g_chan_nr);
4312}
4313testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4314 var RllTestCases tcs := {
4315 /* normal SAPI3 establishment on main DCCH */
4316 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4317 };
4318 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4319}
4320testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4321 var RllTestCases tcs := {
4322 /* normal SAPI3 establishment on SACCH */
4323 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4324 }
4325 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4326}
4327
4328/* altstep to receive a LAPDm frame matching the given template */
4329private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4330 var L1ctlDlMessage dl;
4331 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4332 var LapdmFrame lapdm;
4333 var octetstring l2 := dl.payload.data_ind.payload;
4334 if (dl.dl_info.link_id.c == SACCH) {
4335 /* remove L1 header */
4336 l2 := substr(l2, 2, lengthof(l2)-2);
4337 }
4338 if (ischosen(exp.ab)) {
4339 lapdm.ab := dec_LapdmFrameAB(l2);
4340 } else if (ischosen(exp.b4)) {
4341 lapdm.b4 := dec_LapdmFrameB4(l2);
4342 } else if (ischosen(exp.bbis)) {
4343 lapdm.bbis := dec_LapdmFrameBbis(l2);
4344 }
4345 log("Rx LAPDm ", lapdm);
4346 if (match(lapdm, exp)) {
4347 setverdict(pass);
4348 } else {
4349 repeat;
4350 }
4351 }
4352 [] L1CTL.receive { repeat; }
4353}
4354private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4355 timer T := t;
4356 T.start;
4357 alt {
4358 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004360 }
4361 [] as_l1_exp_lapdm(exp);
4362 }
4363}
4364
4365/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4366private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4367 /* send SABM from MS -> BTS */
4368 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4369 /* expect RLL EST IND on Abis */
4370 alt {
4371 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4372 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4373 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004375 }
4376 [] RSL.receive { repeat; }
4377 }
4378 /* expect UA from BTS -> MS */
4379 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4380}
4381
4382/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4383private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4384 var RllTestCase tc := g_pars.spec.rll;
4385
4386 f_l1_tune(L1CTL);
4387 RSL.clear;
4388
4389 /* activate the logical channel */
4390 f_est_dchan();
4391 L1CTL.clear;
4392
4393 /* first establish the link-layer */
4394 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4395
4396 /* then send the DISC */
4397 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4398 /* ... and expect the REL IND on the RSL side */
4399 alt {
4400 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4401 setverdict(pass);
4402 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004403 /* We also expect to receive the measurements */
4404 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004405 }
4406
4407 /* release the channel */
4408 f_rsl_chan_deact();
4409 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4410 f_rslem_unregister(0, g_chan_nr);
4411}
4412testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4413 var RllTestCases tcs := {
4414 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4415 };
4416 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4417}
4418
4419testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4420 var RllTestCases tcs := {
4421 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4422 };
4423 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4424}
4425testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4426 var RllTestCases tcs := {
4427 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4428 };
4429 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4430}
4431testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4432 var RllTestCases tcs := {
4433 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4434 };
4435 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4436}
4437
4438/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4439private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4440 var RllTestCase tc := g_pars.spec.rll;
4441 f_l1_tune(L1CTL);
4442 RSL.clear;
4443
4444 /* activate the logical channel */
4445 f_est_dchan();
4446 L1CTL.clear;
4447
4448 /* first establish the link-layer */
4449 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4450
4451 /* then send the REL REQ via RSL */
4452 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4453 /* ... and expect the DISC on the Um side */
4454 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004455 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004456 /* FIXME: send a UA in resposne to the DISC */
4457 }
4458 }
4459
4460 /* release the channel */
4461 f_rsl_chan_deact();
4462 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4463 f_rslem_unregister(0, g_chan_nr);
4464}
4465testcase TC_rll_rel_req() runs on test_CT {
4466 var RllTestCases tcs := {
4467 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4468 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4469 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4470 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4471 };
4472 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4473}
4474
4475/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4476testcase TC_rll_data_req() runs on test_CT {
4477}
4478
4479/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4480testcase TC_rll_data_ind() runs on test_CT {
4481}
4482
4483/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4484private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4485 var RllTestCase tc := g_pars.spec.rll;
4486
4487 f_l1_tune(L1CTL);
4488 RSL.clear;
4489
4490 f_est_dchan();
4491 L1CTL.clear;
4492
4493 /* Send UNITDATA REQ on RSL side */
4494 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4495 /* Expect it to arrive on the other side */
4496 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004497 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004498 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004499 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004500 }
4501
4502 /* release the channel */
4503 f_rsl_chan_deact();
4504 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4505 f_rslem_unregister(0, g_chan_nr);
4506}
4507testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4508 var octetstring l3 := f_rnd_octstring(15);
4509 var RllTestCases tcs := {
4510 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4511 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4512 };
4513 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4514}
4515testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4516 var octetstring l3 := f_rnd_octstring(19);
4517 var RllTestCases tcs := {
4518 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4519 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4520 };
4521 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4522}
4523
4524/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4525private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4526 var RllTestCase tc := g_pars.spec.rll;
4527
4528 f_l1_tune(L1CTL);
4529 RSL.clear;
4530
4531 f_est_dchan();
4532 L1CTL.clear;
4533
4534 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004535 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004536 /* Expdct RLL UNITDATA IND on RSL side */
4537 alt {
4538 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4539 setverdict(pass);
4540 }
4541 [] RSL.receive { repeat; }
4542 }
4543
4544 /* release the channel */
4545 f_rsl_chan_deact();
4546 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4547 f_rslem_unregister(0, g_chan_nr);
4548}
4549testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004550 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004551 var RllTestCases tcs := {
4552 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4553 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4554 };
4555 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4556}
4557testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4558 var octetstring l3 := f_rnd_octstring(18);
4559 var RllTestCases tcs := {
4560 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4561 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4562 };
4563 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4564}
4565
Harald Weltee613f962018-04-18 22:38:16 +02004566/***********************************************************************
4567 * Encryption Related
4568 ***********************************************************************/
4569
4570/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4571function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4572 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4573 if (link_id.c == SACCH) {
4574 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4575 } else {
4576 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4577 }
4578}
4579
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004580/* Expect (or not expect) other kinds of messages */
4581private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4582 [exp_any] RSL.receive { repeat; }
4583 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004585 }
4586}
4587
Harald Weltee613f962018-04-18 22:38:16 +02004588/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004589private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004590 RslLinkId link_id,
4591 octetstring l3,
4592 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004593 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004594) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004595 timer T := 3.0;
4596 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4597 T.start;
4598 /* Expect RLL UNITDATA IND on RSL side */
4599 alt {
4600 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4601 setverdict(pass);
4602 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004603 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004604 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004605 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004607 }
Harald Weltee613f962018-04-18 22:38:16 +02004608 }
4609}
4610
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004611/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4612private function f_data_mo(
4613 RslLinkId link_id,
4614 boolean p, uint3_t nr, uint3_t ns,
4615 octetstring l3,
4616 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004617 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004618) runs on ConnHdlr {
4619 timer T := 3.0;
4620 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4621 T.start;
4622 /* Expect RLL DATA IND on RSL side */
4623 alt {
4624 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4625 setverdict(pass);
4626 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004627 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004628 [] as_rsl_any_ind(exp_any);
4629 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004631 }
4632 }
4633}
4634
Harald Weltee613f962018-04-18 22:38:16 +02004635/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4636function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4637 f_l1_tune(L1CTL);
4638 f_est_dchan(true);
4639
4640 /* now we actually need to transmit some data both ways to check if the encryption works */
4641 var L1ctlDlMessage dl;
4642
Stefan Sperling603d98e2018-07-25 16:47:28 +02004643 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004644 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4645
4646 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4647 f_unitdata_mt(link_id, l3);
4648
4649 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4650 f_unitdata_mo(link_id, l3);
4651
4652 /* release the channel */
4653 f_rsl_chan_deact();
4654 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4655 f_rslem_unregister(0, g_chan_nr);
4656}
4657testcase TC_chan_act_a51() runs on test_CT {
4658 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4659 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4660 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4661}
4662testcase TC_chan_act_a52() runs on test_CT {
4663 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4664 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4665 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4666}
4667testcase TC_chan_act_a53() runs on test_CT {
4668 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4669 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4670 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4671}
4672
4673
4674/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4675function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4676 /* L3 payload doesn't matter, as it is passed transparently */
4677 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4678 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4679 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4680
4681 f_l1_tune(L1CTL);
4682
4683 /* first establish a dedicated channel in the clear */
4684 f_est_dchan(false);
4685
4686 /* Establish ABM */
4687 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4688
4689 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4690 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4691 /* expect the L3 to arrive still unencrypted on the MS side */
4692 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4693
4694 /* configure L1 to apply ciphering */
4695 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4696 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4697
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004698 /* send first ciphered I-frame in response and expect it on RSL */
4699 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004700
4701 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4702 * and hence enable encryption also on the downlink */
4703
4704 /* expect bi-directional communication work in encrypted mode */
4705 f_unitdata_mo(link_id, f_rnd_octstring(15));
4706 f_unitdata_mt(link_id, f_rnd_octstring(15));
4707
4708 /* release the channel */
4709 f_rsl_chan_deact();
4710 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4711 f_rslem_unregister(0, g_chan_nr);
4712}
4713testcase TC_encr_cmd_a51() runs on test_CT {
4714 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4715 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4716 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4717}
4718testcase TC_encr_cmd_a52() runs on test_CT {
4719 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4720 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4721 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4722}
4723testcase TC_encr_cmd_a53() runs on test_CT {
4724 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4725 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4726 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4727}
4728
4729private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4730 var LapdmFrame lf;
4731 var octetstring reenc;
4732
4733 /* decode the LAPDm frame */
4734 if (ischosen(exp_match.ab)) {
4735 lf.ab := dec_LapdmFrameAB(enc);
4736 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004738 }
4739
4740 /* check if decoder result matches expectation */
4741 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004743 } else {
4744 log(name, ": matched");
4745 setverdict(pass);
4746 }
4747
4748 /* test if re-encoded frame equals original input */
4749 reenc := enc_LapdmFrame(lf);
4750 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004752 } else {
4753 setverdict(pass);
4754 }
4755}
4756
4757testcase TC_lapdm_selftest() runs on test_CT {
4758 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4759 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4760 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4761 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4762 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4763 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4764 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4765}
4766
Stefan Sperling4880be42018-08-07 18:12:59 +02004767/***********************************************************************
4768 * DTX Related (see GSM 05.08, section 8.3)
4769 ***********************************************************************/
4770
4771/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4772function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4773 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4774 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4775 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4776 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4777}
4778function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4779 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4780 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4781}
4782function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4783 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4784 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4785 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4786 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4787}
4788function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4789 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4790 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4791 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4792 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4793 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4794 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4795 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4796 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4797}
4798
4799function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4800 var L1ctlDlMessage dl;
4801 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4802 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4803 var GsmFrameNumber first_fn;
4804 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004805 var integer nfill_frames_sacch := 0;
4806 var integer nfill_frames_nonsacch := 0;
4807 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004808 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4809 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004810 const integer frame_dtx_tchf_mod := 104;
4811 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4812 * which operates in terms of blocks rather than frames. */
4813 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4814 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004815 timer T := 5.0;
4816
4817 f_l1_tune(L1CTL);
4818 RSL.clear;
4819 L1CTL.clear;
4820
4821 /* activate TCHF signalling channel */
4822 f_est_dchan(false);
4823
4824 T.start;
4825 alt {
4826 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4827 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4828 var octetstring l2 := dl.payload.data_ind.payload;
4829
4830 if (is_first_frame) {
4831 is_first_frame := false;
4832 first_fn := dl.dl_info.frame_nr;
4833 }
4834
4835 if (dl.dl_info.link_id.c == SACCH) {
4836 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4837 if (not match(l2_fill_frame_sacch, l2)) {
4838 repeat;
4839 }
4840 } else if (not match(l2_fill_frame, l2)) {
4841 repeat;
4842 }
4843
4844 if (dtxd) {
4845 if (not f_g_chan_is_tchf()) {
4846 T.stop;
4847 f_rsl_chan_deact();
4848 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004849 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 +02004850 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004851 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004852 T.stop;
4853 f_rsl_chan_deact();
4854 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004855
4856 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4857 * 2 SACCH, 1 TCH/F */
4858 expected_fill_frames := 3;
4859
4860 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4861 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4862 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004864 } else {
4865 setverdict(pass);
4866 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004867 } else {
4868 if (dl.dl_info.link_id.c == SACCH) {
4869 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004870 repeat;
4871 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004872 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4873 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4874 * we should only see the subset of frames numbers which correspond to a block boundary.
4875 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4876 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4877 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4878 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4879 repeat;
4880 }
4881 }
4882 log("Received DTX TCH fill frame with bad frame number: ", fn,
4883 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4884 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4885 f_rsl_chan_deact();
4886 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004888 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004889 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004890 if (dl.dl_info.link_id.c == SACCH) {
4891 nfill_frames_sacch := nfill_frames_sacch + 1;
4892 } else {
4893 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4894 }
4895 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004896 T.stop;
4897 if (f_g_chan_is_tchf()) {
4898 /* Without DTX we can expect 25 fill frames for every 104 frames.
4899 * (24 FACCH + 1 SACCH filling) */
4900 expected_fill_frames := 25;
4901 } else if (f_g_chan_is_tchh()) {
4902 /* We can expect 2 fill frames for every 104 frames. */
4903 expected_fill_frames := 2;
4904 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4905 /* We can expect 5 fill frames for every 104 frames. */
4906 expected_fill_frames := 5;
4907 } else {
4908 f_rsl_chan_deact();
4909 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004911 }
4912
4913 f_rsl_chan_deact();
4914 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004915
4916 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004917 setverdict(pass);
4918 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004919 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4920 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004922 }
4923 } else {
4924 repeat;
4925 }
4926 }
4927 }
4928 [] L1CTL.receive { repeat; }
4929 [] T.timeout {
4930 f_rsl_chan_deact();
4931 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004933 }
4934 }
4935}
4936
4937function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4938 f_test_l2_fill_frames(false);
4939}
4940
4941function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4942 f_test_l2_fill_frames(true);
4943}
4944
4945function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4946 var ConnHdlr vc_conn;
4947 var ConnHdlrPars pars;
4948 pars.t_guard := 60.0;
4949 f_init(testcasename());
4950 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4951 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4952 if (dtxd) {
4953 if (i >= 4) { /* DTX is only allowed on TCH/F */
4954 break;
4955 }
4956 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4957 } else {
4958 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4959 }
4960 vc_conn.done;
4961 }
4962}
4963
4964/* Verify that L2 fill frames are sent on TCH in signaling mode if
4965 * there is nothing to transmit while DTX is disabled on downlink. */
4966testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4967 f_tch_sign_l2_fill_frame(false);
4968}
4969
4970/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4971 * there is nothing to transmit while DTX is enabled on downlink. */
4972testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4973 f_tch_sign_l2_fill_frame(true);
4974}
Harald Welte0472ab42018-03-12 15:02:26 +01004975
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004976testcase TC_chopped_ipa_ping() runs on test_CT {
4977 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4978}
4979
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004980testcase TC_chopped_ipa_payload() runs on test_CT {
4981 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4982}
4983
Harald Welte0472ab42018-03-12 15:02:26 +01004984/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4985/* protocol error as per 44.006 */
4986/* link layer failure (repetition of I-frame N200 times without ACK */
4987/* repetition of SABM or DISC N200 times without ACK */
4988/* receptiom of SABM in multi-frame established state */
4989
4990
Harald Welte68e495b2018-02-25 00:05:57 +01004991/* TODO Areas:
4992
4993* channel activation
4994** with BS_Power / MS_Power, bypassing power control loop
4995** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004996** with timing advance from initial activation on
4997* mode modify
4998** encryption
4999** multirate
5000* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005001** unsupported algorithm
5002* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005003* BS Power Control
5004* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005005* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005006* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005007** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005008* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005009** DATA_IND from BTS->PCU
5010** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005011
5012*/
Harald Welte70767382018-02-21 12:16:40 +01005013
5014control {
5015 execute( TC_chan_act_stress() );
5016 execute( TC_chan_act_react() );
5017 execute( TC_chan_deact_not_active() );
5018 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005019 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005020 execute( TC_sacch_filling() );
5021 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005022 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005023 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005024 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005025 execute( TC_sacch_chan_act_ho_async() );
5026 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005027 execute( TC_rach_content() );
5028 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005029 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005030 execute( TC_rach_load_idle_thresh0() );
5031 execute( TC_rach_load_idle_below_thresh() );
5032 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005033 execute( TC_meas_res_sign_tchf() );
5034 execute( TC_meas_res_sign_tchh() );
5035 execute( TC_meas_res_sign_sdcch4() );
5036 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005037 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005038 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005039 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005040 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005041 execute( TC_paging_imsi_80percent() );
5042 execute( TC_paging_tmsi_80percent() );
5043 execute( TC_paging_imsi_200percent() );
5044 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005045 execute( TC_rsl_protocol_error() );
5046 execute( TC_rsl_mand_ie_error() );
5047 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005048 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005049 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005050 execute( TC_si_sched_2bis() );
5051 execute( TC_si_sched_2ter() );
5052 execute( TC_si_sched_2ter_2bis() );
5053 execute( TC_si_sched_2quater() );
5054 execute( TC_si_sched_13() );
5055 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005056 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005057 execute( TC_ipa_crcx_twice_not_active() );
5058 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005059 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005060 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005061
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005062 if (mp_pcu_socket != "") {
5063 execute( TC_pcu_act_req() );
5064 execute( TC_pcu_act_req_wrong_ts() );
5065 execute( TC_pcu_act_req_wrong_bts() );
5066 execute( TC_pcu_act_req_wrong_trx() );
5067 execute( TC_pcu_deact_req() );
5068 execute( TC_pcu_deact_req_wrong_ts() );
5069 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005070 if (mp_l1_supports_gprs) {
5071 execute( TC_pcu_data_req_pdtch() );
5072 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005073 execute( TC_pcu_data_req_wrong_bts() );
5074 execute( TC_pcu_data_req_wrong_trx() );
5075 execute( TC_pcu_data_req_wrong_ts() );
5076 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005077 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005078 execute( TC_pcu_data_req_agch() );
5079 execute( TC_pcu_data_req_imm_ass_pch() );
5080 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005081 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005082 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005083 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005084 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005085 execute( TC_pcu_oml_alert() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005086 } else {
5087 log("PCU socket path not available, skipping PCU tests");
5088 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005089
5090 execute( TC_dyn_osmo_pdch_act_deact() );
5091 execute( TC_dyn_osmo_pdch_unsol_deact() );
5092 execute( TC_dyn_osmo_pdch_double_act() );
5093 execute( TC_dyn_osmo_pdch_tchf_act() );
5094 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005095 execute( TC_dyn_ipa_pdch_act_deact() );
5096 execute( TC_dyn_ipa_pdch_tchf_act() );
5097 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5098 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005099
5100 execute( TC_rll_est_ind() );
5101 execute( TC_rll_est_req_DCCH_3() );
5102 execute( TC_rll_est_req_ACCH_3() );
5103 execute( TC_rll_rel_ind_DCCH_0() );
5104 execute( TC_rll_rel_ind_DCCH_3() );
5105 execute( TC_rll_rel_ind_ACCH_0() );
5106 execute( TC_rll_rel_ind_ACCH_3() );
5107 execute( TC_rll_rel_req() );
5108 execute( TC_rll_unit_data_req_DCCH() );
5109 execute( TC_rll_unit_data_req_ACCH() );
5110 execute( TC_rll_unit_data_ind_DCCH() );
5111 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005112
5113 execute( TC_chan_act_a51() );
5114 execute( TC_chan_act_a52() );
5115 execute( TC_chan_act_a53() );
5116 execute( TC_encr_cmd_a51() );
5117 execute( TC_encr_cmd_a52() );
5118 execute( TC_encr_cmd_a53() );
5119
Harald Welteee25aae2019-05-19 14:32:37 +02005120 execute( TC_err_rep_wrong_mdisc() );
5121 execute( TC_err_rep_wrong_msg_type() );
5122 execute( TC_err_rep_wrong_sequence() );
5123
Harald Weltee613f962018-04-18 22:38:16 +02005124 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005125
5126 execute( TC_tch_sign_l2_fill_frame() );
5127 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005128
5129 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005130 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005131}
5132
5133
5134}