blob: 0b70da3d92c39289fee15537a96b4bcaf8c8919c [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;
13import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020014import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010015
16import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010017import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010018import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020019import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010020import from RSL_Emulation all;
21
22import from IPL4asp_Types all;
23import from TRXC_Types all;
24import from TRXC_CodecPort all;
25import from TRXC_CodecPort_CtrlFunct all;
26
Harald Welte883340c2018-02-28 18:59:29 +010027import from PCUIF_Types all;
28import from PCUIF_CodecPort all;
29
Harald Welte7484fc42018-02-24 14:09:45 +010030import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010031import from MobileL3_RRM_Types all;
32import from MobileL3_Types all;
33import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010034
Harald Welte8da48242018-02-27 20:41:32 +010035import from Osmocom_VTY_Functions all;
36import from TELNETasp_PortType all;
37
Harald Welte70767382018-02-21 12:16:40 +010038/* The tests assume a BTS with the following timeslot configuration:
39 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020040 * TS1 : TCH/F
41 * TS2 : TCH/F
42 * TS3 : TCH/F_PDCH (IPA Style)
43 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010044 * TS5 : TCH/H
45 * TS6 : SDCCH/8
46 * TS7 : PDCH
47 */
48
49modulepar {
50 charstring mp_rsl_ip := "127.0.0.2";
51 integer mp_rsl_port := 3003;
52 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070053 charstring mp_bts_trxc_ip := "127.0.0.1";
54 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010055 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020056 charstring mp_ctrl_ip := "127.0.0.1";
57 integer mp_ctrl_port := 4238;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020058 integer mp_tolerance_rxqual := 1;
59 integer mp_tolerance_rxlev := 3;
60 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020061 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020062 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020063 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020064 integer mp_ms_actual_ta_exp := 0;
65 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010066 /* Time to wait for RSL conn from BTS during startup of test */
67 float mp_ipa_up_timeout := 10.0;
Harald Welte70767382018-02-21 12:16:40 +010068}
69
Harald Welte629cc6b2018-03-11 17:19:05 +010070type record of RslChannelNr ChannelNrs;
71
Harald Welte70767382018-02-21 12:16:40 +010072type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010073 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010074 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010075 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010076 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010077 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010078 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010079
80 /* L1CTL port (for classic tests) */
81 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010082
Harald Welte54a2a2d2018-02-26 09:14:05 +010083 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070084 port TRXC_CODEC_PT BTS_TRXC;
85 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +010086
Harald Weltef50e3ae2018-09-10 10:27:56 +020087 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010088 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +020089 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +010090
Harald Welte883340c2018-02-28 18:59:29 +010091 /* PCU Interface of BTS */
92 port PCUIF_CODEC_PT PCU;
93 var integer g_pcu_conn_id;
94 /* Last PCU INFO IND we received */
95 var PCUIF_Message g_pcu_last_info;
96
Harald Welte48494ca2018-02-25 16:59:50 +010097 /* SI configuration */
98 var SystemInformationConfig si_cfg := {
99 bcch_extended := false,
100 si1_present := false,
101 si2bis_present := false,
102 si2ter_present := false,
103 si2quater_present := false,
104 si7_present := false,
105 si8_present := false,
106 si9_present := false,
107 si13_present := false,
108 si13alt_present := false,
109 si15_present := false,
110 si16_present := false,
111 si17_present := false,
112 si2n_present := false,
113 si21_present := false,
114 si22_present := false
115 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100116
117 /* all logical channels available on the BTS */
118 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100119 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100120}
121
122/* an individual call / channel */
123type component ConnHdlr extends RSL_DchanHdlr {
124 port L1CTL_PT L1CTL;
125
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700126 port TRXC_CODEC_PT BTS_TRXC;
127 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100128
129 timer g_Tguard;
130 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
131
132 var ConnHdlrPars g_pars;
133 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100134 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200135
136 /* PCU Interface of BTS */
137 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100138}
139
140function f_init_rsl(charstring id) runs on test_CT {
141 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
142 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
143
144 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
145 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
146 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
147
148 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
149 vc_RSL.start(RSL_Emulation.main(false));
150}
151
152type record ConnHdlrPars {
153 RslChannelNr chan_nr,
154 RSL_IE_ChannelMode chan_mode,
155 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100156 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200157 TestSpecUnion spec optional,
158 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100159}
160
161/* Test-specific parameters */
162type union TestSpecUnion {
163 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100164}
165
Harald Welte82ccef72018-02-25 16:17:33 +0100166template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100167 max_retrans := RACH_MAX_RETRANS_7,
168 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100169 cell_barr_access := false,
170 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100171 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100172};
173
Harald Weltef10153f2018-02-25 16:34:05 +0100174template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100175 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200176 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100177 acs := '0'B,
178 neci := true,
179 rxlev_access_min := 0
180}
181
182template (value) LocationAreaIdentification ts_LAI_default := {
183 mcc_mnc := '262F42'H,
184 lac := 42
185}
186
Harald Welte7484fc42018-02-24 14:09:45 +0100187/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100188template (value) SystemInformation ts_SI3_default := {
189 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100190 payload := {
191 si3 := {
192 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100193 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100194 ctrl_chan_desc := {
195 msc_r99 := true,
196 att := true,
197 bs_ag_blks_res := 1,
198 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100199 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100200 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
201 spare := '00'B,
202 bs_pa_mfrms := 0, /* 2 multiframes */
203 t3212 := 1 /* 6 minutes */
204 },
Harald Welte82ccef72018-02-25 16:17:33 +0100205 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100206 dn_ind := false,
207 pwrc := false,
208 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100209 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100210 },
Harald Weltef10153f2018-02-25 16:34:05 +0100211 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100212 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100213 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100214 }
215 }
216}
Harald Welte70767382018-02-21 12:16:40 +0100217
Harald Weltef8df4cb2018-03-10 15:15:08 +0100218template (value) SystemInformation ts_SI2_default := {
219 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100220 payload := {
221 si2 := {
222 bcch_freq_list := '00000000000000000000000000000000'O,
223 ncc_permitted := '11111111'B,
224 rach_control := ts_RachCtrl_default
225 }
226 }
227}
228
Harald Weltef8df4cb2018-03-10 15:15:08 +0100229template (value) SystemInformation ts_SI4_default := {
230 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100231 payload := {
232 si4 := {
233 lai := ts_LAI_default,
234 cell_sel_par := ts_CellSelPar_default,
235 rach_control := ts_RachCtrl_default,
236 cbch_chan_desc := omit,
237 cbch_mobile_alloc := omit,
238 rest_octets := ''O
239 }
240 }
241}
242
243function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
244runs on test_CT {
245 log("Setting ", rsl_si_type, ": ", si_enc);
246 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
247}
248
249function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
250runs on test_CT {
251 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
252 log("Setting ", rsl_si_type, ": ", si_dec);
253 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
254}
255
Harald Welte8da48242018-02-27 20:41:32 +0100256private function f_init_vty(charstring id) runs on test_CT {
257 map(self:BTSVTY, system:BTSVTY);
258 f_vty_set_prompts(BTSVTY);
259 f_vty_transceive(BTSVTY, "enable");
260}
261
Harald Weltef50e3ae2018-09-10 10:27:56 +0200262private function f_init_vty_bsc() runs on test_CT {
263 map(self:BSCVTY, system:BSCVTY);
264 f_vty_set_prompts(BSCVTY, "OsmoBSC");
265 f_vty_transceive(BSCVTY, "enable");
266}
267
Harald Welte883340c2018-02-28 18:59:29 +0100268/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200269private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
270 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100271 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200272 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
273 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100274 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200275 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100277 }
278}
279
Harald Weltef26de0b2018-04-04 20:28:05 +0200280private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
281 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100282 timer T := 2.0;
283 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100284 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200285 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100286 return;
287 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200288 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100289
290 T.start;
291 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200292 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100293 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100295 }
296 }
297}
298
Harald Welte70767382018-02-21 12:16:40 +0100299/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100300function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100301 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100302 g_AllChannels := {
303 /* TS 1..4: TCH/F */
304 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
305 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
306 /* TS 5: TCH/H */
307 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
308 /* TS 0: SDCCH/4 */
309 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
310 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
311 /* TS 6: SDCCH/8 */
312 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
313 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
314 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
315 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
316 };
317
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200318 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700319 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200320 g_AllChanTypes := {
321 /* TS 1..4: TCH/F */
322 valueof(ts_RslChanNr_Bm(1)),
323 /* TS 5: TCH/H */
324 valueof(ts_RslChanNr_Lm(5,1)),
325 /* TS 0: SDCCH/4 */
326 valueof(ts_RslChanNr_SDCCH4(0,2)),
327 /* TS 6: SDCCH/8 */
328 valueof(ts_RslChanNr_SDCCH8(6,4))
329 };
330 } else {
331 g_AllChanTypes := {
332 /* TS 1..4: TCH/F */
333 valueof(ts_RslChanNr_Bm(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 }
Harald Welte70767382018-02-21 12:16:40 +0100340 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200341 T.start;
342 alt {
343 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
344 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200346 }
347 }
Harald Welte2d142592018-02-25 13:19:44 +0100348 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100349 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200350 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100351
352 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100353 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
354 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
355 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
356 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100357
Harald Weltef26de0b2018-04-04 20:28:05 +0200358 map(self:PCU, system:PCU);
359 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100360
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700361 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100362 var TrxcMessage ret;
363 /* start with a default moderate timing offset equalling TA=2 */
364 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700365 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 +0100366 }
Harald Welte70767382018-02-21 12:16:40 +0100367}
368
Harald Welte68e495b2018-02-25 00:05:57 +0100369/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
370function f_init_l1ctl() runs on test_CT {
371 map(self:L1CTL, system:L1CTL);
372 f_connect_reset(L1CTL);
373}
374
Harald Welte70767382018-02-21 12:16:40 +0100375type function void_fn(charstring id) runs on ConnHdlr;
376
377/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200378function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100379runs on test_CT return ConnHdlr {
380 var charstring id := testcasename();
381 var ConnHdlr vc_conn;
382
383 vc_conn := ConnHdlr.create(id);
384 /* connect to RSL Emulation main component */
385 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
386 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200387 if (pcu_comp) {
388 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
389 * it from the test_CT and connect it to the component. This obviously only
390 * works for one component, i.e. no concurrency */
391 unmap(self:PCU, system:PCU);
392 map(vc_conn:PCU, system:PCU);
393 }
Harald Welte70767382018-02-21 12:16:40 +0100394
395 vc_conn.start(f_handler_init(fn, id, pars));
396 return vc_conn;
397}
398
Harald Welte7484fc42018-02-24 14:09:45 +0100399template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
400 streamId := sid,
401 rsl := rsl
402}
403
404template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
405 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
406 streamId := sid,
407 rsl := rsl
408}
409
Harald Welte70767382018-02-21 12:16:40 +0100410private altstep as_Tguard() runs on ConnHdlr {
411 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100413 }
414}
415
Harald Welte68e495b2018-02-25 00:05:57 +0100416private function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200417 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100418}
419
420private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700421 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100422 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700423 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100424 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200425 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200426 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 +0200427 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700428 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100429}
430
431private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100432 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700433 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100434}
435
436private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100437 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700438 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100439}
440
441/* first function started in ConnHdlr component */
442private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
443runs on ConnHdlr {
444 g_pars := pars;
445 g_chan_nr := pars.chan_nr;
446
447 map(self:L1CTL, system:L1CTL);
448 f_connect_reset(L1CTL);
449
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700450 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100451 f_trxc_connect();
452 }
Harald Welte70767382018-02-21 12:16:40 +0100453
454 g_Tguard.start(pars.t_guard);
455 activate(as_Tguard());
456
457 f_rslem_register(0, pars.chan_nr);
458
459 /* call the user-supplied test case function */
460 fn.apply(id);
461}
462
Harald Welteb1726c92018-03-30 11:56:38 +0200463function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
464 boolean ignore_other := false)
465runs on ConnHdlr return RSL_Message {
466 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100467 timer T := 3.0;
468 RSL.send(tx);
469 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100470 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200471 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100472 T.stop;
473 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100474 }
Harald Welte1eba3742018-02-25 12:48:14 +0100475 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100477 }
Harald Welte21240e62018-03-11 21:43:35 +0100478 [not ignore_other] as_l1_sacch();
479 [not ignore_other] as_meas_res();
480 [not ignore_other] as_l1_dcch();
481 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100483 }
Harald Welte21240e62018-03-11 21:43:35 +0100484 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100485 }
Harald Welteb1726c92018-03-30 11:56:38 +0200486 return rx;
487}
488
489function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
490 boolean ignore_other := false)
491runs on ConnHdlr {
492 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100493}
494
Harald Weltee613f962018-04-18 22:38:16 +0200495function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false)
496runs on ConnHdlr {
497 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
498 if (encr_enable) {
499 /* append encryption related IEs, if requested */
500 var RSL_IE_EncryptionInfo encr_info;
501 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
502 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
503encr_info})) };
504 }
505 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100506}
507
Harald Welte70767382018-02-21 12:16:40 +0100508function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100509 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 +0100510 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100511}
512
Harald Welte70767382018-02-21 12:16:40 +0100513private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
514 template RSL_IE_ChannelMode chan_mode,
515 float t_guard := 20.0) := {
516 chan_nr := valueof(chan_nr),
517 chan_mode := valueof(chan_mode),
518 t_guard := t_guard,
519 l1_pars := {
520 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100521 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100522 meas_ul := {
523 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200524 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100525 rxqual := 0
526 },
527 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200528 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100529 rxqual := 0
530 }
531 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200532 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100533 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200534 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200535 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100536 },
Harald Weltee613f962018-04-18 22:38:16 +0200537 spec := omit,
538 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100539}
540
Harald Welte93640c62018-02-25 16:59:33 +0100541/***********************************************************************
542 * Channel Activation / Deactivation
543 ***********************************************************************/
544
Harald Welte70767382018-02-21 12:16:40 +0100545/* Stress test: Do 500 channel activations/deactivations in rapid succession */
546function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
547 for (var integer i := 0; i < 500; i := i+1) {
548 f_rsl_chan_act(g_pars.chan_mode);
549 f_rsl_chan_deact();
550 }
551 setverdict(pass);
552}
553testcase TC_chan_act_stress() runs on test_CT {
554 var ConnHdlr vc_conn;
555 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
556 f_init(testcasename());
557 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
558 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100560}
561
562/* Test if re-activation of an already active channel fails as expected */
563function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
564 f_rsl_chan_act(g_pars.chan_mode);
565 /* attempt to activate the same lchan again -> expect reject */
566 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
567 alt {
568 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100570 }
571 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
572 setverdict(pass);
573 }
574 }
575 f_rsl_chan_deact();
576}
577testcase TC_chan_act_react() runs on test_CT {
578 var ConnHdlr vc_conn;
579 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100580 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100581 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
582 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100584}
585
586/* Attempt to de-activate a channel that's not active */
587function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
588 timer T := 3.0;
589 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
590 T.start;
591 alt {
592 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
593 setverdict(pass);
594 }
595 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100597 }
598 }
599}
600testcase TC_chan_deact_not_active() runs on test_CT {
601 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100602 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100603 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
604 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100606}
607
608/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
609function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
610 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
611 alt {
612 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100614 }
615 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
616 setverdict(pass);
617 }
618 }
619}
620private type record WrongChanNrCase {
621 RslChannelNr chan_nr,
622 charstring description
623}
624private type record of WrongChanNrCase WrongChanNrCases;
625private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
626 chan_nr := chan_nr,
627 description := desc
628}
629
630testcase TC_chan_act_wrong_nr() runs on test_CT {
631 var ConnHdlr vc_conn;
632 var ConnHdlrPars pars;
633
Harald Welte294b0a22018-03-10 23:26:48 +0100634 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100635
636 var WrongChanNrCases wrong := {
637 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
638 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
639 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
640 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
641 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
642 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
643 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
644 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
645 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
646 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
647 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
648 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
649 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
650 };
651
652 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
653 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
654 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
655 vc_conn.done;
656 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100658}
659
Harald Weltee613f962018-04-18 22:38:16 +0200660/* execute the same callback function on a variety of logical channels */
661private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
662 var ConnHdlr vc_conn;
663 f_init(testcasename());
664
665 /* test on each of the channels we have */
666 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
667 pars.chan_nr := valueof(g_AllChanTypes[i]);
668
669 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
670 vc_conn := f_start_handler(fn, pars);
671 vc_conn.done;
672 }
673
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200675}
676
Harald Welte93640c62018-02-25 16:59:33 +0100677/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100678 * SACCH handling
679 ***********************************************************************/
680
681private function f_exp_sacch(boolean exp) runs on ConnHdlr {
682 timer T_sacch := 3.0;
683 T_sacch.start;
684 alt {
685 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100687 }
688 [not exp] T_sacch.timeout {
689 setverdict(pass);
690 }
691 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
692 setverdict(pass);
693 }
694 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200695 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100696 }
697 [] L1CTL.receive { repeat; }
698 [] RSL.receive { repeat; }
699 }
700}
701
702/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
703private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
704 f_l1_tune(L1CTL);
705 RSL.clear;
706
707 /* activate the logical channel */
708 f_est_dchan();
709 L1CTL.clear;
710
711 /* check that SACCH actually are received as expected */
712 f_exp_sacch(true);
713
714 /* deactivate SACCH on the logical channel */
715 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
716 f_sleep(1.0);
717 L1CTL.clear;
718
719 /* check that no SACCH are received anymore */
720 f_exp_sacch(false);
721
722 /* release the channel */
723 f_rsl_chan_deact();
724 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
725}
726testcase TC_deact_sacch() runs on test_CT {
727 var ConnHdlr vc_conn;
728 var ConnHdlrPars pars;
729 f_init();
730 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
731 //for (var integer i := 0; i < 1; i := i+1) {
732 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
733 log(testcasename(), ": Starting for ", g_AllChannels[i]);
734 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
735 vc_conn.done;
736 }
737 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100739}
740
Harald Welte55700662018-03-12 13:15:43 +0100741/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100742private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
743 var L1ctlDlMessage dl;
744 /* check that the specified SI5 value is actually sent */
745 timer T_sacch := 3.0;
746 L1CTL.clear;
747 T_sacch.start;
748 alt {
749 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
750 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
751 if (match(l3, l3_exp)) {
752 setverdict(pass);
753 } else {
754 repeat;
755 }
756 }
757 [] L1CTL.receive { repeat; }
758 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100760 }
761 }
762}
763
Harald Welte55700662018-03-12 13:15:43 +0100764/* verify that given SACCH payload is not present */
765private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
766 var L1ctlDlMessage dl;
767 /* check that the specified SI5 value is actually sent */
768 timer T_sacch := 3.0;
769 L1CTL.clear;
770 T_sacch.start;
771 alt {
772 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
773 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
774 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100776 } else {
777 repeat;
778 }
779 }
780 [] L1CTL.receive { repeat; }
781 [] T_sacch.timeout {
782 setverdict(pass);
783 }
784 }
785}
786
Harald Welte629cc6b2018-03-11 17:19:05 +0100787/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100788private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
789 /* Set a known default SACCH filling for SI5 */
790 var octetstring si5 := f_rnd_octstring(19);
791 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
792
793 f_l1_tune(L1CTL);
794 RSL.clear;
795
796 /* activate the logical channel */
797 f_est_dchan();
798
799 /* check that the specified SI5 value is actually sent */
800 f_sacch_present(si5);
801
802 /* release the channel */
803 RSL.clear;
804 f_rsl_chan_deact();
805 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
806}
807testcase TC_sacch_filling() runs on test_CT {
808 var ConnHdlr vc_conn;
809 var ConnHdlrPars pars;
810 f_init();
811 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
812 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
813 log(testcasename(), ": Starting for ", g_AllChannels[i]);
814 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
815 vc_conn.done;
816 }
817 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100819}
820
Harald Welte629cc6b2018-03-11 17:19:05 +0100821/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100822private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
823 /* Set a known default SACCH filling for SI5 */
824 var octetstring si5 := f_rnd_octstring(19);
825 var octetstring si5_diff := f_rnd_octstring(19);
826 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
827
828 f_l1_tune(L1CTL);
829 RSL.clear;
830
831 log("Activating channel, expecting standard SI5");
832 /* activate the logical channel */
833 f_est_dchan();
834 /* check that the specified SI5 value is actually sent */
835 f_sacch_present(si5);
836
837 /* set channel-specific different SI5 */
838 log("Setting channel specific SACCH INFO, expecting it");
839 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
840 /* check that the specified lchan-specific value is now used */
841 f_sacch_present(si5_diff);
842
843 /* deactivate the channel and re-activate it, this should result in default SI5 */
844 log("De-activating and re-activating channel, expecting standard SI5");
845 f_rsl_chan_deact();
846 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
847 /* Verify that the TRX-wide default SACCH filling is present again */
848 f_sacch_present(si5);
849
850 /* release the channel */
851 RSL.clear;
852 f_rsl_chan_deact();
853 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
854}
855testcase TC_sacch_info_mod() runs on test_CT {
856 var ConnHdlr vc_conn;
857 var ConnHdlrPars pars;
858 f_init();
859 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
860 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
861 log(testcasename(), ": Starting for ", g_AllChannels[i]);
862 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
863 vc_conn.done;
864 }
865 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100867}
868
Harald Welte075d84c2018-03-12 13:07:24 +0100869/* Test SACCH scheduling of multiple different SI message types */
870private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
871 var octetstring si5 := f_rnd_octstring(19);
872 var octetstring si5bis := f_rnd_octstring(19);
873 var octetstring si5ter := f_rnd_octstring(19);
874 var octetstring si6 := f_rnd_octstring(19);
875
876 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
877 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
878 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
879 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
880
881 f_l1_tune(L1CTL);
882 RSL.clear;
883
884 /* activate the logical channel */
885 f_est_dchan();
886 L1CTL.clear;
887
888 /* check that SACCH actually are received as expected */
889 f_sacch_present(si5);
890 f_sacch_present(si5bis);
891 f_sacch_present(si5ter);
892 f_sacch_present(si6);
893
894 /* release the channel */
895 f_rsl_chan_deact();
896 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
897}
898testcase TC_sacch_multi() runs on test_CT {
899 var ConnHdlr vc_conn;
900 var ConnHdlrPars pars;
901 f_init();
902 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
903 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
904 log(testcasename(), ": Starting for ", g_AllChannels[i]);
905 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
906 vc_conn.done;
907 }
908 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100910}
911
Harald Welte55700662018-03-12 13:15:43 +0100912/* Test if SACH information is modified as expected */
913private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
914 var octetstring si5 := f_rnd_octstring(19);
915 var octetstring si6 := f_rnd_octstring(19);
916
917 /* First, configure both SI5 and SI6 to be transmitted */
918 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
919 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
920
921 f_l1_tune(L1CTL);
922 RSL.clear;
923
924 /* activate the logical channel */
925 f_est_dchan();
926 L1CTL.clear;
927
928 /* check that SACCH actually are received as expected */
929 f_sacch_present(si5);
930 f_sacch_present(si6);
931
932 /* disable SI6 */
933 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
934
935 /* check that SI5 is still transmitted */
936 f_sacch_present(si5);
937 /* check if SI6 is now gone */
938 f_sacch_missing(si6);
939
940 /* release the channel */
941 f_rsl_chan_deact();
942 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
943}
944testcase TC_sacch_multi_chg() runs on test_CT {
945 var ConnHdlr vc_conn;
946 var ConnHdlrPars pars;
947 f_init();
948 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
949 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
950 log(testcasename(), ": Starting for ", g_AllChannels[i]);
951 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
952 vc_conn.done;
953 }
954 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100956}
957
Harald Welte075d84c2018-03-12 13:07:24 +0100958/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
959/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100960
961
962/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100963 * RACH Handling
964 ***********************************************************************/
965
Harald Welte8c24c2b2018-02-26 08:31:31 +0100966/* like L1SAP_IS_PACKET_RACH */
967private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100968 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100969 return true;
970 }
971 return false;
972}
973
974/* generate a random RACH for circuit-switched */
975private function f_rnd_ra_cs() return OCT1 {
976 var OCT1 ra;
977 do {
978 ra := f_rnd_octstring(1);
979 } while (ra_is_ps(ra));
980 return ra;
981}
982
Harald Welte883340c2018-02-28 18:59:29 +0100983/* generate a random RACH for packet-switched */
984private function f_rnd_ra_ps() return OCT1 {
985 var OCT1 ra;
986 do {
987 ra := f_rnd_octstring(1);
988 } while (not ra_is_ps(ra));
989 return ra;
990}
991
Harald Welte8c24c2b2018-02-26 08:31:31 +0100992/* Send 1000 RACH requests and check their RA+FN on the RSL side */
993testcase TC_rach_content() runs on test_CT {
994 f_init(testcasename());
995 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100996 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100997
Harald Welte8c24c2b2018-02-26 08:31:31 +0100998 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +0100999 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001000 for (var integer i := 0; i < 1000; i := i+1) {
1001 var OCT1 ra := f_rnd_ra_cs();
1002 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1003 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001005 }
1006 fn_last := fn;
1007
1008 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001009 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001010 alt {
1011 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1012 T.stop;
1013 }
1014 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001016 }
1017 [] RSL_CCHAN.receive { repeat; }
1018 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001019 test_failed := true;
1020 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001021 }
1022 }
1023 }
Maxba06feb2019-03-05 10:52:46 +01001024 if (test_failed) {
1025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001026 }
Maxba06feb2019-03-05 10:52:46 +01001027 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001029}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001030
1031/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1032testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001033 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001034 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001035 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001036 f_l1_tune(L1CTL);
1037
1038 var GsmFrameNumber fn_last := 0;
1039 for (var integer i := 0; i < 1000; i := i+1) {
1040 var OCT1 ra := f_rnd_ra_cs();
1041 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1042 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001044 }
1045 fn_last := fn;
1046 }
1047 var integer rsl_chrqd := 0;
1048 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001049 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001050 alt {
1051 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1052 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001053 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001054 repeat;
1055 }
1056 [] RSL_CCHAN.receive { repeat; }
1057 [] T.timeout { }
1058 }
1059 if (rsl_chrqd == 1000) {
1060 setverdict(pass);
1061 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001063 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001065}
1066
Harald Welte54a2a2d2018-02-26 09:14:05 +01001067private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001068 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001069 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001070 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001071 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001072 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 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 +02001074 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001075 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001076}
1077
1078private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001079 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001080 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001081 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001082 f_sleep(0.5);
1083
1084 /* Transmit RACH request + wait for confirmation */
1085 var OCT1 ra := f_rnd_ra_cs();
1086 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1087
1088 /* Check for expected result */
1089 timer T := 1.5;
1090 T.start;
1091 alt {
1092 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1093 setverdict(pass);
1094 }
1095 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001097 }
1098 [] RSL_CCHAN.receive { repeat; }
1099 [not expect_pass] T.timeout {
1100 setverdict(pass);
1101 }
1102 [expect_pass] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for CHAN RQD");
Harald Welte54a2a2d2018-02-26 09:14:05 +01001104 }
1105 }
1106}
1107
1108/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1109testcase TC_rach_max_ta() runs on test_CT {
1110 f_init(testcasename());
1111 f_init_l1ctl();
1112 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001113 f_sleep(1.0);
1114
1115 /* default max-ta is 63 (full range of GSM timing advance */
1116
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001117 /* We allow early arrival up to 2 symbols */
1118 f_rach_toffs(-1*256, true);
1119 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001120 f_rach_toffs(-10*256, false);
1121
1122 /* 0 / 32 / 63 bits is legal / permitted */
1123 f_rach_toffs(0, true);
1124 f_rach_toffs(32*256, true);
1125 f_rach_toffs(63*256, true);
1126
1127 /* more than 63 bits is not legal / permitted */
1128 f_rach_toffs(64*256, false);
1129 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001130 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001131}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001132
Harald Welte93640c62018-02-25 16:59:33 +01001133/***********************************************************************
1134 * Measurement Processing / Reporting
1135 ***********************************************************************/
1136
Harald Welte70767382018-02-21 12:16:40 +01001137template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1138 spare := '0'B,
1139 lpd := 0,
1140 sapi := sapi,
1141 c_r := c_r,
1142 ea := true
1143}
1144
Harald Welted879bd92018-03-12 15:01:23 +01001145template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001146 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001147 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001148 len := 0, /* overwritten */
1149 m := false,
1150 el := 1,
1151 payload := pl
1152}
1153
1154/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1155altstep as_l1_sacch() runs on ConnHdlr {
1156 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001157 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001158 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001159 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 +01001160 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001161 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001162
1163 var L1ctlDataReq data_req := {
1164 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1165 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1166 }
1167 log("Sending Measurement Report: ", data_req);
1168 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001169 repeat;
1170 }
1171}
1172
1173altstep as_l1_dcch() runs on ConnHdlr {
1174 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001175 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001176 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1177 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001178 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1179 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001180 repeat;
1181 }
1182}
1183
1184type record MeasElem {
1185 uint6_t rxlev,
1186 uint3_t rxqual
1187}
1188
1189type record MeasElemFS {
1190 MeasElem full,
1191 MeasElem sub
1192}
1193
1194type record ConnL1Pars {
1195 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001196 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001197 MeasElemFS meas_ul,
1198 int16_t timing_offset_256syms,
1199 uint5_t bs_power_level,
1200 uint5_t ms_power_level,
1201 uint8_t ms_actual_ta
1202}
1203
1204/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1205private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1206 return 63 + (toffs256s/256);
1207}
1208
Harald Welted5684392018-03-10 18:22:04 +01001209private function f_max(integer a, integer b) return integer {
1210 if (a > b) {
1211 return a;
1212 } else {
1213 return b;
1214 }
1215}
1216
1217private function f_min(integer a, integer b) return integer {
1218 if (a < b) {
1219 return a;
1220 } else {
1221 return b;
1222 }
1223}
1224
1225/* compute negative tolerance val-tolerance, ensure >= min */
1226private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1227 val := val - tolerance;
1228 return f_max(val, min);
1229}
1230
1231/* compute positive tolerance val+tolerance, ensure <= max */
1232private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1233 val := val + tolerance;
1234 return f_min(val, max);
1235}
1236
1237/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1238private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1239return template integer {
1240 var template integer ret;
1241 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1242 return ret;
1243}
1244
1245
Harald Welte70767382018-02-21 12:16:40 +01001246/* build a template for matching measurement results against */
1247private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1248 var ConnL1Pars l1p := g_pars.l1_pars;
1249 var template RSL_IE_UplinkMeas ul_meas := {
1250 len := 3,
1251 rfu := '0'B,
1252 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001253 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001254 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001255 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001256 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001257 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1258 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001259 supp_meas_info := omit
1260 };
Harald Welte685d5982018-02-27 20:42:05 +01001261 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001262 ul_meas.len := (3+8);
1263 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001264 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001265 toa256_min := ?,
1266 toa256_max := ?,
1267 toa256_std_dev := ?
1268 }
Harald Welte685d5982018-02-27 20:42:05 +01001269 }
Harald Welte70767382018-02-21 12:16:40 +01001270 var template RSL_IE_BS_Power bs_power := {
1271 reserved := 0,
1272 epc := false,
1273 fpc := false,
1274 power_level := l1p.bs_power_level
1275 };
1276 var template RSL_IE_L1Info l1_info := {
1277 ms_power_lvl := l1p.ms_power_level,
1278 fpc := false,
1279 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001280 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001281 };
1282 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001283 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001284 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1285 ?, t_toffs);
1286}
1287
1288/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001289altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001290 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001291 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001292 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1293 /* increment counter of next to-be-expected meas rep */
1294 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1295 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001296 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001297 repeat;
1298 }
1299 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001300 /* increment counter of next to-be-expected meas rep */
1301 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1302 if (g_first_meas_res) {
1303 g_first_meas_res := false;
1304 repeat;
1305 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001307 }
Harald Welte70767382018-02-21 12:16:40 +01001308 }
1309 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001311 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001312 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001314 }
1315}
1316
Harald Weltee613f962018-04-18 22:38:16 +02001317private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1318 select (rsl_alg_id) {
1319 case (RSL_ALG_ID_A5_0) { return 0; }
1320 case (RSL_ALG_ID_A5_1) { return 1; }
1321 case (RSL_ALG_ID_A5_2) { return 2; }
1322 case (RSL_ALG_ID_A5_3) { return 3; }
1323 case (RSL_ALG_ID_A5_4) { return 4; }
1324 case (RSL_ALG_ID_A5_5) { return 5; }
1325 case (RSL_ALG_ID_A5_6) { return 6; }
1326 case (RSL_ALG_ID_A5_7) { return 7; }
1327 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1329 /* Make compiler happy by calling mtc.stop here. It is already
1330 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001331 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001332 }
1333 }
1334}
1335
1336private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1337 select (rsl_alg_id) {
1338 case (RSL_ALG_ID_A5_1) { return '000'B; }
1339 case (RSL_ALG_ID_A5_2) { return '001'B; }
1340 case (RSL_ALG_ID_A5_3) { return '010'B; }
1341 case (RSL_ALG_ID_A5_4) { return '011'B; }
1342 case (RSL_ALG_ID_A5_5) { return '100'B; }
1343 case (RSL_ALG_ID_A5_6) { return '101'B; }
1344 case (RSL_ALG_ID_A5_7) { return '110'B; }
1345 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1347 /* Make compiler happy by calling mtc.stop here. It is already
1348 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001349 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001350 }
1351 }
1352}
1353
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001354/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1355private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1356 var GsmFrameNumber fn;
1357 timer T := 8.0;
1358
1359 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1360 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1361
1362 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1363 /* Send the actual RACH */
1364 fn := f_L1CTL_RACH(L1CTL, ra);
1365
1366 T.start;
1367 alt {
1368 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1369 [] T.timeout {
1370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1371 }
1372 }
1373 T.stop
1374 return fn;
1375}
Harald Weltee613f962018-04-18 22:38:16 +02001376
Harald Welte70767382018-02-21 12:16:40 +01001377/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001378private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001379 var GsmFrameNumber fn;
1380 var ImmediateAssignment imm_ass;
1381 var integer ra := 23;
1382
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001383 /* Send RACH request and wait for ChanReq */
1384 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001385
1386 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001387 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001388
1389 /* Send IMM.ASS via CCHAN */
1390 var ChannelDescription ch_desc := {
1391 chan_nr := g_pars.chan_nr,
1392 tsc := 7,
1393 h := false,
1394 arfcn := mp_trx0_arfcn,
1395 maio_hsn := omit
1396 };
1397 var MobileAllocation ma := {
1398 len := 0,
1399 ma := ''B
1400 };
1401 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1402 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1403
1404 /* receive IMM.ASS on MS side */
1405 var ImmediateAssignment ia_um;
1406 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1407 /* enable dedicated mode */
1408 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001409 /* enable encryption, if requested */
1410 if (encr_enable) {
1411 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1412 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1413 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001414
1415 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001416}
1417
1418/* establish DChan, verify existance + contents of measurement reports */
1419function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001420 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001421 RSL.clear;
1422
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001423 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001424 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001425 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1426 }
Harald Welte70767382018-02-21 12:16:40 +01001427
1428 f_est_dchan();
1429
1430 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1431 * RSL measurement reports on Abis side */
1432 timer T := 8.0;
1433 T.start;
1434 alt {
1435 [] as_l1_sacch();
1436 [] as_meas_res();
1437 [] as_l1_dcch();
1438 [] L1CTL.receive { repeat; }
1439 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001440 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001441 * of any earlier errors, so if we reach this timeout, we're good */
1442 setverdict(pass);
1443 }
1444 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001446 }
1447 }
1448 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001450}
Harald Welte0472ab42018-03-12 15:02:26 +01001451
Harald Welte70767382018-02-21 12:16:40 +01001452testcase TC_meas_res_sign_tchf() runs on test_CT {
1453 var ConnHdlr vc_conn;
1454 var ConnHdlrPars pars;
1455 f_init(testcasename());
1456 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1457 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1458 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1459 vc_conn.done;
1460 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001462}
1463testcase TC_meas_res_sign_tchh() runs on test_CT {
1464 var ConnHdlr vc_conn;
1465 var ConnHdlrPars pars;
1466 f_init(testcasename());
1467 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1468 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1469 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1470 vc_conn.done;
1471 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001473}
1474testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1475 var ConnHdlr vc_conn;
1476 var ConnHdlrPars pars;
1477 f_init(testcasename());
1478 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1479 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1480 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1481 vc_conn.done;
1482 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001484}
1485testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init(testcasename());
1489 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1490 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1491 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1492 vc_conn.done;
1493 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001495}
Harald Welte685d5982018-02-27 20:42:05 +01001496testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1497 var ConnHdlr vc_conn;
1498 var ConnHdlrPars pars;
1499 f_init(testcasename());
1500 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1501 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1502 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1503 pars.l1_pars.toa256_enabled := true;
1504 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1505 vc_conn.done;
1506 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001508}
1509
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001510/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1511 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1512function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1513 var L1ctlDlMessage l1_dl;
1514 var RSL_IE_MS_Power ms_power;
1515 var RSL_Message rsl;
1516 var uint5_t power_level := 0;
1517
1518 f_l1_tune(L1CTL);
1519 RSL.clear;
1520
1521 f_est_dchan();
1522
1523 ms_power.reserved := 0;
1524 ms_power.fpc_epc := false;
1525
1526 /* Send the first power control command. This will disable any BTS/TRX
1527 * internal power control and switch the MS (which is not in scope of
1528 * this test) to a constant power level. We start with a power level
1529 * of 0 */
1530 ms_power.power_level := power_level;
1531 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1532 RSL.send(rsl);
1533
1534 alt {
1535
1536 /* Pick all SACCH blocks for checking */
1537 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1538
1539 /* The first byte of the L1 header contains the power level.
1540 * The reserved bits and the fpc bit is set to 0, so we may
1541 * compare directly. */
1542 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1543 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1544 }
1545
1546 /* Signal a new power level via RSL for the next turn. */
1547 if (power_level < 31) {
1548 power_level := power_level + 1;
1549 ms_power.power_level := power_level;
1550 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1551 RSL.send(rsl);
1552 repeat;
1553 }
1554
1555 }
1556
1557 /* Ignore all other blocks */
1558 [] L1CTL.receive { repeat; }
1559
1560 }
1561
1562 f_rsl_chan_deact();
1563 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1564
1565 setverdict(pass);
1566}
1567
1568testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1569 var ConnHdlr vc_conn;
1570 var ConnHdlrPars pars;
1571 f_init(testcasename());
1572
1573 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1574 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1575 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1576 vc_conn.done;
1577 }
1578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1579}
Harald Welte70767382018-02-21 12:16:40 +01001580
Harald Welte0472ab42018-03-12 15:02:26 +01001581/* 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 +01001582private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001583 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001584 RSL.clear;
1585
1586 f_est_dchan();
1587 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001588 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001589
1590 timer T := 40.0;
1591 T.start;
1592 alt {
1593 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1594 setverdict(pass)
1595 }
1596 [] RSL.receive { repeat };
1597 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001599 }
1600 }
1601 f_rsl_chan_deact();
1602}
1603testcase TC_conn_fail_crit() runs on test_CT {
1604 var ConnHdlr vc_conn;
1605 var ConnHdlrPars pars;
1606 f_init(testcasename());
1607 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1608 pars.t_guard := 60.0;
1609 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1610 vc_conn.done;
1611}
1612
Harald Welte93640c62018-02-25 16:59:33 +01001613/***********************************************************************
1614 * Paging
1615 ***********************************************************************/
1616
Harald Welte68e495b2018-02-25 00:05:57 +01001617function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1618 if (tmsi == 'FFFFFFFF'O) {
1619 return true;
1620 } else {
1621 return false;
1622 }
1623}
Harald Welte70767382018-02-21 12:16:40 +01001624
Philipp Maier82cb0b12018-08-31 14:41:39 +02001625type record allowedFn { integer frame_nr }
1626template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
1627template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
1628template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
1629template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
1630template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
1631template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
1632template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
1633template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
1634function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
1635{
1636 var integer frame_nr_51;
1637 frame_nr_51 := frame_nr mod 51
1638
1639 var allowedFn fn_check;
1640 fn_check.frame_nr := frame_nr_51;
1641
1642 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001644 return;
1645 }
1646
1647 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
1648 return;
1649 }
1650 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
1651 return;
1652 }
1653 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
1654 return;
1655 }
1656 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
1657 return;
1658 }
1659 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
1660 return;
1661 }
1662 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
1663 return;
1664 }
1665 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
1666 return;
1667 }
1668 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
1669 return;
1670 }
1671
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001673 return;
1674}
1675
1676altstep 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 +01001677runs on test_CT {
1678 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001679 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001680 repeat;
1681 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001682 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001683 var octetstring without_plen :=
1684 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1685 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02001686
1687 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
1688
Harald Welte68e495b2018-02-25 00:05:57 +01001689 if (match(rr, tr_PAGING_REQ1)) {
1690 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1691 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1692 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1693 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1694 }
1695 } else if (match(rr, tr_PAGING_REQ2)) {
1696 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1697 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1698 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1699 }
1700 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1701 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1702 }
1703 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1704 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1705 }
1706 } else if (match(rr, tr_PAGING_REQ3)) {
1707 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1708 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1709 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1710 }
1711 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1712 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1713 }
1714 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1715 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1716 }
1717 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1718 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1719 }
1720 }
1721 repeat;
1722 }
1723}
1724
1725type record PagingTestCfg {
1726 boolean combined_ccch,
1727 integer bs_ag_blks_res,
1728 float load_factor,
1729 boolean exp_load_ind,
1730 boolean exp_overload,
1731 boolean use_tmsi
1732}
1733
1734type record PagingTestState {
1735 integer num_paging_sent,
1736 integer num_paging_rcv_msgs,
1737 integer num_paging_rcv_ids,
1738 integer num_overload
1739}
1740
1741/* receive + ignore RSL RF RES IND */
1742altstep as_rsl_res_ind() runs on test_CT {
1743 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1744 repeat;
1745 }
1746}
1747
1748/* Helper function for paging related testing */
1749private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1750 f_init(testcasename());
1751 f_init_l1ctl();
1752 f_l1_tune(L1CTL);
1753
1754 var PagingTestState st := {
1755 num_paging_sent := 0,
1756 num_paging_rcv_msgs := 0,
1757 num_paging_rcv_ids := 0,
1758 num_overload := 0
1759 };
1760
1761 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1762 var float max_pch_imsi_per_sec;
1763 if (cfg.use_tmsi) {
1764 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1765 } else {
1766 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1767 }
1768 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1769 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001770 var float time_total := 20.0;
1771 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
1772 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01001773
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001774 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
1775 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01001776
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001777 timer T_itv := 0.0;
1778 T_itv.start;
1779 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01001780 alt {
1781 /* check for presence of CCCH LOAD IND (paging load) */
1782 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1783 st.num_overload := st.num_overload + 1;
1784 repeat;
1785 }
1786 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01001788 }
1789 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1790 log("Rx LOAD_IND");
1791 /* FIXME: analyze/verify interval + contents */
1792 repeat;
1793 }
1794 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02001795 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001796 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001797 [] T_itv.timeout {
1798 /* Send paging cmds based on elapsed time */
1799 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
1800 while (st.num_paging_sent < new_sent) {
1801 /* build mobile Identity */
1802 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1803 if (cfg.use_tmsi) {
1804 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1805 } else {
1806 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
1807 }
1808 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1809 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1810
1811 /* Send RSL PAGING COMMAND */
1812 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
1813
1814 st.num_paging_sent := st.num_paging_sent + 1;
1815 }
1816 if (st.num_paging_sent < pkt_total) {
1817 /* Wait for interval to next PAGING COMMAND */
1818 var float time_now := T_total.read;
1819 var float next_sched := int2float(st.num_paging_sent)*interval;
1820 if (next_sched > time_now) {
1821 T_itv.start(next_sched - time_now);
1822 } else {
1823 T_itv.start(0.0);
1824 }
1825 } else {
1826 /* We are done, no need to keep counting */
1827 T_total.stop;
1828 }
1829 }
1830 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01001831 [] as_rsl_res_ind();
1832 }
1833 }
1834
1835 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1836 timer T_wait := 18.0;
1837 T_wait.start;
1838 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02001839 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001840 [] L1CTL.receive { repeat; }
1841 /* 65535 == empty paging queue, we can terminate*/
1842 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1843 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1844 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01001846 }
1847 [] as_rsl_res_ind();
1848 }
1849
1850 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1851 " rcvd_ids=", st.num_paging_rcv_ids);
1852 return st;
1853}
1854
1855/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1856 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1857 * - that CCCH LOAD IND (PCH) are being generated
1858 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1859testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001860 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001861 var PagingTestCfg cfg := {
1862 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001863 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001864 load_factor := 0.8,
1865 exp_load_ind := true,
1866 exp_overload := false,
1867 use_tmsi := false
1868 };
1869 var PagingTestState st := f_TC_paging(cfg);
1870 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1872 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001873 } else {
1874 setverdict(pass);
1875 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001877}
1878
1879/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1880 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1881 * - that CCCH LOAD IND (PCH) are being generated
1882 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1883testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001884 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001885 var PagingTestCfg cfg := {
1886 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001887 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001888 load_factor := 0.8,
1889 exp_load_ind := true,
1890 exp_overload := false,
1891 use_tmsi := true
1892 };
1893 var PagingTestState st := f_TC_paging(cfg);
1894 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1896 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001897 } else {
1898 setverdict(pass);
1899 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001901}
1902
1903/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1904 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1905 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1906 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1907testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001908 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001909 var PagingTestCfg cfg := {
1910 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001911 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001912 load_factor := 2.0,
1913 exp_load_ind := true,
1914 exp_overload := true,
1915 use_tmsi := false
1916 };
1917 var PagingTestState st := f_TC_paging(cfg);
1918 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1919 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001920 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001921 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001922 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 +01001923 } else {
1924 setverdict(pass);
1925 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001927}
1928
1929/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1930 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1931 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1932 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1933testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001934 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001935 var PagingTestCfg cfg := {
1936 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001937 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001938 load_factor := 2.0,
1939 exp_load_ind := true,
1940 exp_overload := true,
1941 use_tmsi := true
1942 };
1943 var PagingTestState st := f_TC_paging(cfg);
1944 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1945 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001946 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001947 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001948 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 +01001949 } else {
1950 setverdict(pass);
1951 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001953}
1954
1955
Harald Welte93640c62018-02-25 16:59:33 +01001956/***********************************************************************
1957 * Immediate Assignment / AGCH
1958 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001959const MobileAllocation c_MA_null := {
1960 len := 0,
1961 ma := ''B
1962}
Harald Welte93640c62018-02-25 16:59:33 +01001963
Harald Weltee8d750e2018-06-10 21:41:35 +02001964template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1965 uint12_t arfcn := 871) := {
1966 chan_nr := chan_nr,
1967 tsc := tsc,
1968 h := false,
1969 arfcn := arfcn,
1970 maio_hsn := omit
1971}
1972
1973private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1974 return int2str(num_tx) & " sent, "
1975 & int2str(num_rx) & " received, "
1976 & int2str(num_del) & " deleted";
1977}
1978
1979private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1980 var L1ctlDlMessage l1_dl;
1981 timer T := 10.0;
1982 var integer num_tx := 0;
1983 var integer num_rx := 0;
1984 var integer num_del := 0;
1985 var charstring res_str;
1986 var float rx_ratio;
1987
Harald Welte68e495b2018-02-25 00:05:57 +01001988 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001989 f_init_l1ctl();
1990 f_l1_tune(L1CTL);
1991
1992 for (var integer i := 0; i < num_total; i := i+1) {
1993 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1994 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1995 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001996 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001997 num_tx := num_tx+1;
1998 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001999 }
2000 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002001 T.start;
2002 alt {
2003 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2004 num_del := num_del+1;
2005 repeat;
2006 }
2007 [] RSL_CCHAN.receive {
2008 repeat;
2009 }
2010 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2011 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2012 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2013 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2014 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002015 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002016 } else {
2017 num_rx := num_rx+1;
2018 }
2019 repeat;
2020 }
2021 [] L1CTL.receive { repeat; }
2022 [] T.timeout { }
2023 }
2024 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2025 log("AGCH test: " & res_str);
2026 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002028 }
2029 rx_ratio := int2float(num_rx) / int2float(num_tx);
2030 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002031 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 +02002032 } else {
2033 setverdict(pass);
2034 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002036}
2037
Harald Weltee8d750e2018-06-10 21:41:35 +02002038/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2039testcase TC_imm_ass_1000_20ms() runs on test_CT {
2040 f_TC_imm_ass(1000, 0.02, 0.25);
2041}
2042
2043/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2044testcase TC_imm_ass_200_0ms() runs on test_CT {
2045 f_TC_imm_ass(200, 0.0, 0.05);
2046}
2047
2048/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2049testcase TC_imm_ass_200_76ms() runs on test_CT {
2050 f_TC_imm_ass(150, 0.076, 1.00);
2051}
2052
2053
2054
Harald Welte48494ca2018-02-25 16:59:50 +01002055/***********************************************************************
2056 * BCCH
2057 ***********************************************************************/
2058
2059/* tuple of Frame Number + decoded SI */
2060type record SystemInformationFn {
2061 GsmFrameNumber frame_number,
2062 SystemInformation si
2063}
2064
2065/* an arbitrary-length vector of decoded SI + gsmtap header */
2066type record of SystemInformationFn SystemInformationVector;
2067
2068/* an array of SI-vectors indexed by TC value */
2069type SystemInformationVector SystemInformationVectorPerTc[8];
2070
2071/* determine if a given SI vector contains given SI type at least once */
2072function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2073 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2074 var integer fn_mod51 := arr[i].frame_number mod 51;
2075 if (not bcch_ext and fn_mod51 == 2 or
2076 bcch_ext and fn_mod51 == 6) {
2077 if (arr[i].si.header.message_type == key) {
2078 return true;
2079 }
2080 }
2081 }
2082 return false;
2083}
2084
2085/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2086function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2087 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002089 }
2090}
2091
2092/* check if a given SI vector contains given SI type at least once on any TC */
2093function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2094 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2095 if (f_si_vecslot_contains(arr[tc], key) or
2096 f_si_vecslot_contains(arr[tc], key, true)) {
2097 return true;
2098 }
2099 }
2100 return false;
2101}
2102
2103/* determine if a given SI vector contains given SI type at least N of M times */
2104function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2105 var integer count := 0;
2106 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002108 }
2109 for (var integer i:= 0; i < m; i := i + 1) {
2110 var integer fn_mod51 := arr[i].frame_number mod 51;
2111 if (not bcch_ext and fn_mod51 == 2 or
2112 bcch_ext and fn_mod51 == 6) {
2113 if (arr[i].si.header.message_type == key) {
2114 count := count + 1;
2115 }
2116 }
2117 }
2118 if (count >= n) {
2119 return true;
2120 } else {
2121 return false;
2122 }
2123}
2124
2125/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2126function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2127 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002129 }
2130}
2131
2132/* determine if a given SI vector contains given SI type at least once */
2133function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2134 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2135 var integer fn_mod51 := arr[i].frame_number mod 51;
2136 if (not bcch_ext and fn_mod51 == 2 or
2137 bcch_ext and fn_mod51 == 6) {
2138 if (arr[i].si.header.message_type != key) {
2139 return false;
2140 }
2141 }
2142 }
2143 return true;
2144}
2145
2146/* ensure a given TC slot of the SI vector contains only given SI type */
2147function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2148 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002150 }
2151}
2152
2153/* SI configuration of cell, against which we validate actual SI messages */
2154type set SystemInformationConfig {
2155 boolean bcch_extended,
2156 boolean si1_present,
2157 boolean si2bis_present,
2158 boolean si2ter_present,
2159 boolean si2quater_present,
2160 boolean si7_present,
2161 boolean si8_present,
2162 boolean si9_present,
2163 boolean si13_present,
2164 boolean si13alt_present,
2165 boolean si15_present,
2166 boolean si16_present,
2167 boolean si17_present,
2168 boolean si2n_present,
2169 boolean si21_present,
2170 boolean si22_present
2171}
2172
2173/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2174function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2175 var integer i;
2176 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2177 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002179 }
2180 }
2181 if (cfg.si1_present) {
2182 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2183 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2184 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2185 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2186 /* make sure *ALL* contain SI1 */
2187 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2188 }
2189 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2190 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2191 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2192 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2193 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2194 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2195
2196 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2197 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2198 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2199 * consecutive occurrences of TC = 4. */
2200 if (cfg.si2bis_present and not cfg.si2ter_present) {
2201 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2202 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2203 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2204 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2205 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2206 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2207 }
2208
2209 if (cfg.si7_present or cfg.si8_present) {
2210 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2211 * if System Information type 4 does not contain all information needed for cell
2212 * selection and reselection. */
2213 if (not cfg.bcch_extended) {
2214 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2215 }
2216 if (cfg.si7_present) {
2217 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2218 }
2219 if (cfg.si8_present) {
2220 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2221 }
2222 }
2223
2224 if (cfg.si2quater_present) {
2225 /* iii) System information type 2 quater is sent if needed, as determined by the system
2226 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2227 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2228 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2229 * within any of 4 consecutive occurrences of TC = 5. */
2230 if (not (cfg.bcch_extended)) {
2231 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2232 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2233 } else {
2234 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2235 }
2236 } else {
2237 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2238 }
2239 }
2240 if (cfg.si9_present) {
2241 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2242 * in system information type 3 as defined in 3GPP TS 44.018. */
2243 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2244 }
2245 if (cfg.si13_present) {
2246 /* vii) System Information type 13 is only related to the GPRS service. System Information
2247 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2248 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2249 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2250 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2251 * within any of 4 consecutive occurrences of TC=4. */
2252 if (not cfg.bcch_extended) {
2253 log("not-bccch-extended");
2254 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2255 } else {
2256 log("bccch-extended");
2257 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2258 }
2259 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002261 }
2262 }
2263 if (cfg.si16_present or cfg.si17_present) {
2264 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2265 * should not be sent in a cell where network sharing is used (see rule xv). */
2266 if (cfg.si22_present) {
2267 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2268 }
2269 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002271 }
2272 if (not cfg.bcch_extended) {
2273 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2274 }
2275 if (cfg.si16_present) {
2276 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2277 }
2278 if (cfg.si17_present) {
2279 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2280 }
2281 }
2282
2283 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2284 * broadcast information. The frequency with which they are sent is determined by the
2285 * system operator. System Information type 9 identifies the scheduling of System
2286 * Information type 18 and 20 messages. */
2287
2288 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2289 * Information Type 19 is present, then its scheduling shall be indicated in System
2290 * Information Type 9. */
2291
2292 if (cfg.si15_present) {
2293 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2294 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2295 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2296 * 4 consecutive occurrences of TC = 1. */
2297 if (not cfg.bcch_extended) {
2298 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2299 } else {
2300 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2301 }
2302 }
2303 if (cfg.si13alt_present) {
2304 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2305 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2306 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2307 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2308 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2309 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2310 * of TC = 4. */
2311 if (cfg.si13_present) {
2312 testcase.stop("Error: Cannot have SI13alt and SI13");
2313 }
2314 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002315 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002316 }
2317 if (not cfg.bcch_extended) {
2318 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2319 } else {
2320 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2321 }
2322 }
2323 if (cfg.si2n_present) {
2324 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2325 * as determined by the system operator. In the case that the message is sent on the
2326 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2327 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2328 * consecutive occurrences of TC = 4. */
2329 if (not cfg.bcch_extended) {
2330 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2331 } else {
2332 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2333 }
2334 }
2335 if (cfg.si21_present) {
2336 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2337 * determined by the system operator. If Extended Access Barring is in use in the cell
2338 * then this message is sent at least once within any of 4 consecutive occurrences of
2339 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2340 * cell then this message shall only be sent on BCCH Ext. */
2341 if (not cfg.bcch_extended) {
2342 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2343 } else {
2344 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2345 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002347 }
2348 }
2349 }
2350 if (cfg.si22_present) {
2351 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2352 * should not be sent in a cell where SoLSA is used (see rule viii). System
2353 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2354 * =2 and TC=6. */
2355 if (cfg.si16_present or cfg.si17_present) {
2356 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2357 }
2358 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2359 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002361 }
2362 if (not cfg.bcch_extended) {
2363 testcase.stop("Error: SI22 requires BCCH Extd!");
2364 } else {
2365 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2366 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2367 }
2368 }
2369}
2370
2371/* sample Systme Information for specified duration via L1CTL */
2372function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2373 timer T := duration;
2374 var SystemInformationVectorPerTc si_per_tc;
2375 var L1ctlDlMessage l1_dl;
2376
2377 /* initialize all per-TC vectors empty */
2378 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2379 si_per_tc[i] := {};
2380 }
2381
2382 /* flush all previous L1 queued msgs */
2383 pt.clear;
2384
2385 T.start;
2386 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002387 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002388 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2389 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2390 log("Ignoring non-RR SI ", l1_dl);
2391 repeat;
2392 }
2393 var SystemInformationFn sig := {
2394 frame_number := l1_dl.dl_info.frame_nr,
2395 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2396 }
2397 var integer tc := f_gsm_compute_tc(sig.frame_number);
2398 log("SI received at TC=", tc, ": ", sig.si);
2399 /* append to the per-TC bucket */
2400 si_per_tc[tc] := si_per_tc[tc] & { sig };
2401 repeat;
2402 }
2403 [] pt.receive { repeat; }
2404 [] T.timeout { }
2405 }
2406
2407 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2408 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2409 }
2410 log("si_per_tc=", si_per_tc);
2411 return si_per_tc;
2412}
2413
2414/* helper function: Set given SI via RSL + validate scheduling.
2415 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2416function f_TC_si_sched() runs on test_CT {
2417 var SystemInformationVectorPerTc si_per_tc;
2418 f_init_l1ctl();
2419 f_l1_tune(L1CTL);
2420
2421 /* Sample + Validate Scheduling */
2422 si_per_tc := f_l1_sample_si(L1CTL);
2423 f_validate_si_scheduling(si_cfg, si_per_tc);
2424
2425 setverdict(pass);
2426}
2427
2428testcase TC_si_sched_default() runs on test_CT {
2429 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002430 /* 2+3+4 are mandatory and set in f_init() */
2431 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002433}
2434
2435testcase TC_si_sched_1() runs on test_CT {
2436 f_init();
2437 si_cfg.si1_present := true;
2438 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002439 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002441}
2442
2443testcase TC_si_sched_2bis() runs on test_CT {
2444 f_init();
2445 si_cfg.si2bis_present := true;
2446 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2447 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002449}
2450
2451testcase TC_si_sched_2ter() runs on test_CT {
2452 f_init();
2453 si_cfg.si2ter_present := true;
2454 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2455 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002457}
2458
2459testcase TC_si_sched_2ter_2bis() runs on test_CT {
2460 f_init();
2461 si_cfg.si2bis_present := true;
2462 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2463 si_cfg.si2ter_present := true;
2464 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2465 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002467}
2468
2469testcase TC_si_sched_2quater() runs on test_CT {
2470 f_init();
2471 si_cfg.si2quater_present := true;
2472 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2473 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002475}
2476
2477testcase TC_si_sched_13() runs on test_CT {
2478 f_init();
2479 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002480 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002481 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002483}
2484
2485testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2486 f_init();
2487 si_cfg.si2bis_present := true;
2488 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2489 si_cfg.si2ter_present := true;
2490 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2491 si_cfg.si2quater_present := true;
2492 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2493 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002494 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002495 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002497}
2498
2499
Harald Welte68e495b2018-02-25 00:05:57 +01002500testcase TC_bcch_info() runs on test_CT {
2501 f_init(testcasename());
2502 /* FIXME: enable / disable individual BCCH info */
2503 //ts_RSL_BCCH_INFO(si_type, info);
2504 /* expect no ERROR REPORT after either of them *
2505 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002507}
2508
Harald Welte93640c62018-02-25 16:59:33 +01002509/***********************************************************************
2510 * Low-Level Protocol Errors / ERROR REPORT
2511 ***********************************************************************/
2512
Harald Welte01d982c2018-02-25 01:31:40 +01002513private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2514 timer T := 5.0;
2515 T.start;
2516 alt {
2517 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2518 setverdict(pass);
2519 }
2520 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002522 }
2523 [] RSL_CCHAN.receive {
2524 repeat;
2525 }
2526 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002528 }
2529 }
2530}
2531
2532/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2533testcase TC_rsl_protocol_error() runs on test_CT {
2534 f_init(testcasename());
2535 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2536 rsl.ies := omit;
2537 RSL_CCHAN.send(ts_RSL_UD(rsl));
2538
2539 f_exp_err_rep(RSL_ERR_PROTO);
2540}
2541
2542/* Provoke a mandatory IE error and match on ERROR REPORT */
2543testcase TC_rsl_mand_ie_error() runs on test_CT {
2544 f_init(testcasename());
2545
2546 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2547 rsl.ies := { rsl.ies[0] };
2548 RSL_CCHAN.send(ts_RSL_UD(rsl));
2549
2550 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2551}
2552
2553/* Provoke an IE content error and match on ERROR REPORT */
2554testcase TC_rsl_ie_content_error() runs on test_CT {
2555 f_init(testcasename());
2556 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2557 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2558 RSL_CCHAN.send(ts_RSL_UD(rsl));
2559
2560 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2561}
2562
Harald Welte93640c62018-02-25 16:59:33 +01002563/***********************************************************************
2564 * IPA CRCX/MDCX/DLCS media stream handling
2565 ***********************************************************************/
2566
Harald Weltea871a382018-02-25 02:03:14 +01002567/* Send IPA DLCX to inactive lchan */
2568function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002569 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2570 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002571}
2572testcase TC_ipa_dlcx_not_active() runs on test_CT {
2573 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2574 f_init(testcasename());
2575 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2576 vc_conn.done;
2577}
Harald Welte68e495b2018-02-25 00:05:57 +01002578
Harald Weltea3f1df92018-02-25 12:49:55 +01002579/* Send IPA CRCX twice to inactive lchan */
2580function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2581 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2582 "IPA CRCX ACK");
2583 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2584 "IPA CRCX NACK");
2585}
2586testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2587 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2588 f_init(testcasename());
2589 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2590 vc_conn.done;
2591}
2592
2593/* Regular sequence of CRCX/MDCX/DLCX */
2594function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2595 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2596 "IPA CRCX ACK");
2597 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2598 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2599 var uint7_t rtp_pt2 := f_rnd_int(127);
2600 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2601 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2602 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2603 "IPA MDCX ACK");
2604 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2605 "IPA DLCX ACK");
2606}
2607testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2608 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2609 f_init(testcasename());
2610 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2611 vc_conn.done;
2612}
2613
Harald Welte3ae11da2018-02-25 13:36:06 +01002614/* Sequence of CRCX, 2x MDCX, DLCX */
2615function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2616 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2617 "IPA CRCX ACK");
2618 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2619 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2620 var uint7_t rtp_pt2 := f_rnd_int(127);
2621 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2622 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2623 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2624 "IPA MDCX ACK");
2625 /* Second MDCX */
2626 remote_ip := f_rnd_int(c_UINT32_MAX);
2627 remote_port := f_rnd_int(c_UINT16_MAX);
2628 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2629 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2630 "IPA MDCX ACK");
2631 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2632 "IPA DLCX ACK");
2633}
2634testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2635 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2636 f_init(testcasename());
2637 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2638 vc_conn.done;
2639}
2640
Harald Welte9912eb52018-02-25 13:30:15 +01002641/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2642function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2643 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2644 "IPA CRCX NACK");
2645}
2646testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2647 var ConnHdlrPars pars;
2648 var ConnHdlr vc_conn;
2649 f_init(testcasename());
2650
2651 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2652 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2653 vc_conn.done;
2654
2655 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2656 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2657 vc_conn.done;
2658}
2659
Harald Weltea3f1df92018-02-25 12:49:55 +01002660
Harald Welte883340c2018-02-28 18:59:29 +01002661/***********************************************************************
2662 * PCU Socket related tests
2663 ***********************************************************************/
2664
2665private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2666runs on test_CT {
2667 timer T := 3.0;
2668
2669 /* we don't expect any RTS.req before PDCH are active */
2670 T.start;
2671 alt {
2672 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01002674 }
2675 [] PCU.receive { repeat; }
2676 [] T.timeout { }
2677 }
2678
2679 /* Send PDCH activate request for known PDCH timeslot */
2680 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2681
2682 /* we now expect RTS.req for this timeslot (only) */
2683 T.start;
2684 alt {
2685 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2686 setverdict(pass);
2687 }
2688 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2689 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01002691 }
2692 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01002694 }
2695 [] PCU.receive { repeat; }
2696 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002698 }
2699 [not exp_success] T.timeout {
2700 setverdict(pass);
2701 }
2702 }
2703}
2704
2705private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2706runs on test_CT {
2707 timer T := 3.0;
2708
2709 /* Send PDCH activate request for known PDCH timeslot */
2710 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2711
2712 PCU.clear;
2713 /* we now expect no RTS.req for this timeslot */
2714 T.start;
2715 alt {
2716 [] 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 +02002717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002718 }
2719 [] PCU.receive { repeat; }
2720 [] T.timeout {
2721 setverdict(pass);
2722 }
2723 }
2724}
2725
2726/* PDCH activation via PCU socket; check for presence of RTS.req */
2727testcase TC_pcu_act_req() runs on test_CT {
2728 f_init();
2729 f_TC_pcu_act_req(0, 0, 7, true);
2730}
2731
2732/* PDCH activation via PCU socket on non-PDCU timeslot */
2733testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2734 f_init();
2735 f_TC_pcu_act_req(0, 0, 1, false);
2736}
2737
2738/* PDCH activation via PCU socket on wrong BTS */
2739testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2740 f_init();
2741 f_TC_pcu_act_req(23, 0, 7, false);
2742}
2743
2744/* PDCH activation via PCU socket on wrong TRX */
2745testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2746 f_init();
2747 f_TC_pcu_act_req(0, 23, 7, false);
2748}
2749
2750/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2751testcase TC_pcu_deact_req() runs on test_CT {
2752 f_init();
2753 /* Activate PDCH */
2754 f_TC_pcu_act_req(0, 0, 7, true);
2755 f_sleep(1.0);
2756 /* and De-Activate again */
2757 f_TC_pcu_deact_req(0, 0, 7);
2758}
2759
2760/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2761testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2762 f_init();
2763 f_TC_pcu_deact_req(0, 0, 1);
2764}
2765
2766/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2767testcase TC_pcu_ver_si13() runs on test_CT {
2768 const octetstring si13 := '00010203040506070909'O;
2769 var PCUIF_send_data sd;
2770 timer T:= 3.0;
2771 f_init();
2772
2773 /* Set SI13 via RSL */
2774 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2775 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2776 T.start;
2777 alt {
2778 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2779 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2780 setverdict(pass);
2781 } else {
2782 repeat;
2783 }
2784 }
2785 [] PCU.receive { repeat; }
2786 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01002788 }
2789 }
2790}
2791
2792private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2793
2794/* helper function to send a PCU DATA.req */
2795private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2796 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2797runs on test_CT
2798{
2799 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2800 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2801}
2802
2803/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2804private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2805 PCUIF_Sapi sapi, octetstring data)
2806runs on test_CT
2807{
2808 var PCUIF_send_data sd;
2809
2810 timer T := 3.0;
2811 T.start;
2812 alt {
2813 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2814 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2815 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2816 sd.data.u.rts_req.fn, sapi, data);
2817 }
2818 [] PCU.receive { repeat; }
2819 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01002821 }
2822 }
2823}
2824
2825/* Send DATA.req on invalid BTS */
2826testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2827 f_init();
2828 f_TC_pcu_act_req(0, 0, 7, true);
2829 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2830 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2831 f_sleep(10.0);
2832}
2833
2834/* Send DATA.req on invalid TRX */
2835testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2836 f_init();
2837 f_TC_pcu_act_req(0, 0, 7, true);
2838 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2839 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2840 f_sleep(10.0);
2841}
2842
2843/* Send DATA.req on invalid timeslot */
2844testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2845 f_init();
2846 f_TC_pcu_act_req(0, 0, 7, true);
2847 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2848 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2849 f_sleep(10.0);
2850}
2851
2852/* Send DATA.req on timeslot that hasn't been activated */
2853testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2854 f_init();
2855 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2856 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2857 f_sleep(2.0);
2858}
2859
2860testcase TC_pcu_data_req_pdtch() runs on test_CT {
2861 f_init();
2862 f_TC_pcu_act_req(0, 0, 7, true);
2863 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2864 /* FIXME: how to check this was actually sent */
2865 f_sleep(2.0);
2866}
2867
2868testcase TC_pcu_data_req_ptcch() runs on test_CT {
2869 f_init();
2870 f_TC_pcu_act_req(0, 0, 7, true);
2871 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2872 /* FIXME: how to check this was actually sent */
2873 f_sleep(2.0);
2874}
2875
2876/* Send AGCH from PCU; check it appears on Um side */
2877testcase TC_pcu_data_req_agch() runs on test_CT {
2878 timer T := 3.0;
2879 f_init();
2880 f_init_l1ctl();
2881 f_l1_tune(L1CTL);
2882
2883 f_TC_pcu_act_req(0, 0, 7, true);
2884 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2885
2886 T.start;
2887 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002888 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002889 setverdict(pass);
2890 }
2891 [] L1CTL.receive { repeat; }
2892 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002894 }
2895 }
2896}
2897
2898/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2899testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2900 var octetstring imm_ass := f_rnd_octstring(23);
2901 f_init();
2902 f_init_l1ctl();
2903 f_l1_tune(L1CTL);
2904
2905 /* append 3 last imsi digits so BTS can compute pagng group */
2906 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2907
2908 timer T := 0.5;
2909 T.start;
2910 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002911 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002912 /* TODO: verify paging group */
2913 setverdict(pass);
2914 }
2915 [] L1CTL.receive { repeat; }
2916 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002918 }
2919 }
2920}
2921
2922/* Send RACH from Um side, expect it to show up on PCU socket */
2923testcase TC_pcu_rach_content() runs on test_CT {
2924 f_init();
2925 f_init_l1ctl();
2926 f_l1_tune(L1CTL);
2927
2928 var GsmFrameNumber fn_last := 0;
2929 for (var integer i := 0; i < 1000; i := i+1) {
2930 var OCT1 ra := f_rnd_ra_ps();
2931 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2932 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01002934 }
2935 fn_last := fn;
2936
2937 timer T := 2.0;
2938 T.start;
2939 alt {
2940 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2941 T.stop;
2942 }
2943 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002945 }
2946 [] PCU.receive { repeat; }
2947 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002949 }
2950 }
2951 }
2952 setverdict(pass);
2953}
2954
2955private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2956 var integer strlen := lengthof(str);
2957 for (var integer i := 0; i < len-strlen; i := i+1) {
2958 str := str & pad;
2959 }
2960 return str;
2961}
2962
2963/* Send PAGING via RSL, expect it to shw up on PCU socket */
2964testcase TC_pcu_paging_from_rsl() runs on test_CT {
2965 f_init();
2966
2967 for (var integer i := 0; i < 100; i := i+1) {
2968 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2969 timer T := 3.0;
2970 if (i < 50) {
2971 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2972 } else {
2973 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2974 }
2975 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2976 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2977 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2978
2979 /* Send RSL PAGING COMMAND */
2980 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2981 T.start;
2982 alt {
2983 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2984 }
2985 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01002987 }
2988 [] PCU.receive { repeat; }
2989 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01002991 }
2992 }
2993 }
2994 setverdict(pass);
2995}
2996
Harald Welte3d04ae62018-04-04 20:29:05 +02002997/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002998 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002999 ***********************************************************************/
3000
3001private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3002runs on ConnHdlr {
3003 var PCUIF_send_data sd;
3004 /* Expect BTS to immediately acknowledge activation as PDCH */
3005 PCU.clear;
3006 f_rsl_chan_act(g_pars.chan_mode);
3007 /* expect INFO_IND on PCU interface listing TS as PDCH */
3008 alt {
3009 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3010 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 +02003011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003012 }
3013 }
3014 [] PCU.receive { repeat; }
3015 }
3016 /* try to activate this PDCH from the PCU point of view */
3017 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3018 /* FIXME: is there a response? */
3019}
3020
3021private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3022runs on ConnHdlr {
3023 var PCUIF_send_data sd;
3024 /* Send RSL CHAN REL (deactivate) */
3025 PCU.clear;
3026 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3027 /* expect BTS to ask PCU to deactivate the channel */
3028 alt {
3029 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3030 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 +02003031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003032 }
3033 }
3034 [] PCU.receive { repeat; }
3035 }
3036 /* Emulate PCU asking BTS to deactivate PDCH */
3037 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3038 alt {
3039 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3040 setverdict(pass);
3041 }
3042 [] RSL.receive { repeat; }
3043 }
3044}
3045
3046/* Activate Osmocom-style dynamic PDCH from BSC side */
3047function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3048 var PCUIF_Message first_info;
3049 var integer ts_nr := g_chan_nr.tn;
3050 var integer trx_nr := 0;
3051 var integer bts_nr := 0;
3052 var integer pcu_conn_id := -1;
3053
3054 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3055
3056 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3057 f_sleep(3.0);
3058 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3059 setverdict(pass);
3060}
3061testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3062 var ConnHdlrPars pars;
3063 var ConnHdlr vc_conn;
3064 f_init(testcasename());
3065
3066 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3067 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3068 vc_conn.done;
3069}
3070
3071/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3072function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3073 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003074 var integer pcu_conn_id := -1;
3075
3076 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3077
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003078 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3079 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3080 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003081 setverdict(pass);
3082}
3083testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3084 var ConnHdlrPars pars;
3085 var ConnHdlr vc_conn;
3086 f_init(testcasename());
3087
3088 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3089 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3090 vc_conn.done;
3091}
3092
3093/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3094function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3095 var PCUIF_Message first_info;
3096 var integer ts_nr := g_chan_nr.tn;
3097 var integer trx_nr := 0;
3098 var integer bts_nr := 0;
3099 var integer pcu_conn_id := -1;
3100
3101 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3102
3103 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003104 /* Send a second Chan Activ and expect it to be NACKed */
3105 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3106 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003107 setverdict(pass);
3108}
3109testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3110 var ConnHdlrPars pars;
3111 var ConnHdlr vc_conn;
3112 f_init(testcasename());
3113
3114 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3115 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3116 vc_conn.done;
3117}
3118
3119/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3120function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3121 var PCUIF_Message first_info;
3122 var integer ts_nr := g_chan_nr.tn;
3123 var integer trx_nr := 0;
3124 var integer bts_nr := 0;
3125 var integer pcu_conn_id := -1;
3126 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3127
3128 /* register for the TCH/F channel number */
3129 f_rslem_register(0, chan_nr);
3130
3131 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3132
3133 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3134 "RSL CHAN ACT");
3135 setverdict(pass);
3136}
3137testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3138 var ConnHdlrPars pars;
3139 var ConnHdlr vc_conn;
3140 f_init(testcasename());
3141
3142 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3143 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3144 vc_conn.done;
3145}
3146
3147/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3148function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3149 var PCUIF_Message first_info;
3150 var integer ts_nr := g_chan_nr.tn;
3151 var integer trx_nr := 0;
3152 var integer bts_nr := 0;
3153 var integer pcu_conn_id := -1;
3154 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3155 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3156
3157 /* register for the TCH/H channel numbers */
3158 f_rslem_register(0, chan_nr[0]);
3159 f_rslem_register(0, chan_nr[1]);
3160
3161 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3162
3163 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3164 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3165 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3166 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3167 setverdict(pass);
3168}
3169testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3170 var ConnHdlrPars pars;
3171 var ConnHdlr vc_conn;
3172 f_init(testcasename());
3173
3174 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3175 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3176 vc_conn.done;
3177}
3178
Harald Welte9bbbfb52018-04-05 09:33:19 +02003179/***********************************************************************
3180 * IPA Style Dynamic Timeslot Support
3181 ***********************************************************************/
3182
3183private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3184runs on ConnHdlr {
3185 var PCUIF_send_data sd;
3186 /* Expect BTS to immediately acknowledge activation as PDCH */
3187 PCU.clear;
3188 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3189 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003190 timer T_wait := 2.0;
3191 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003192 alt {
3193 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3194 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 +01003195 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
3196 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3197 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003198 }
3199 }
3200 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003201 [] T_wait.timeout {
3202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3203 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
3204 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003205 }
3206 /* try to activate this PDCH from the PCU point of view */
3207 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3208 /* FIXME: is there a response? */
3209
3210 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3211}
3212
3213private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3214runs on ConnHdlr {
3215 var PCUIF_send_data sd;
3216 /* Send RSL CHAN REL (deactivate) */
3217 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3218 PCU.clear;
3219 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003220 timer T_wait := 2.0;
3221 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003222 alt {
3223 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3224 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 +01003225 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
3226 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3227 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003228 }
3229 }
3230 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003231 [] T_wait.timeout {
3232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3233 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
3234 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003235 }
3236 /* Emulate PCU asking BTS to deactivate PDCH */
3237 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3238 alt {
3239 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3240 setverdict(pass);
3241 }
3242 [] RSL.receive { repeat; }
3243 }
3244}
3245
3246/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3247function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3248 var PCUIF_Message first_info;
3249 var integer ts_nr := g_chan_nr.tn;
3250 var integer trx_nr := 0;
3251 var integer bts_nr := 0;
3252 var integer pcu_conn_id := -1;
3253
3254 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3255
3256 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3257 f_sleep(3.0);
3258 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3259
3260 setverdict(pass);
3261
3262}
3263testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3264 var ConnHdlrPars pars;
3265 var ConnHdlr vc_conn;
3266 f_init();
3267
3268 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3269 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3270 vc_conn.done;
3271}
3272
3273/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3274function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3275 var PCUIF_Message first_info;
3276 var integer ts_nr := g_chan_nr.tn;
3277 var integer trx_nr := 0;
3278 var integer bts_nr := 0;
3279 var integer pcu_conn_id := -1;
3280
3281 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3282
3283 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3284 "RSL CHAN ACT");
3285 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3286 "RF CHAN REL", true);
3287 setverdict(pass);
3288}
3289testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3290 var ConnHdlrPars pars;
3291 var ConnHdlr vc_conn;
3292 f_init(testcasename());
3293
3294 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3295 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3296 vc_conn.done;
3297}
3298
3299/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3300function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3301 var PCUIF_Message first_info;
3302 var integer ts_nr := g_chan_nr.tn;
3303 var integer trx_nr := 0;
3304 var integer bts_nr := 0;
3305 var integer pcu_conn_id := -1;
3306
3307 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3308
3309 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3310 "RSL CHAN ACT");
3311
3312 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3313 alt {
3314 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3315 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003317 }
3318 [] RSL.receive { repeat; }
3319 }
3320
3321 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3322 "RF CHAN REL", true);
3323 setverdict(pass);
3324}
3325testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3326 var ConnHdlrPars pars;
3327 var ConnHdlr vc_conn;
3328 f_init(testcasename());
3329
3330 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3331 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3332 vc_conn.done;
3333}
3334
3335/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3336function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3337 var PCUIF_Message first_info;
3338 var integer ts_nr := g_chan_nr.tn;
3339 var integer trx_nr := 0;
3340 var integer bts_nr := 0;
3341 var integer pcu_conn_id := -1;
3342
3343 /* register for the TCH/F channel number */
3344 f_rslem_register(0, g_chan_nr);
3345
3346 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3347
3348 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3349
3350 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3351 "RSL CHAN ACT");
3352
3353 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3354
3355 setverdict(pass);
3356}
3357testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3358 var ConnHdlrPars pars;
3359 var ConnHdlr vc_conn;
3360 f_init(testcasename());
3361
3362 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3363 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3364 vc_conn.done;
3365}
3366
3367
Harald Welte0472ab42018-03-12 15:02:26 +01003368/***********************************************************************
3369 * LAPDm / RLL related
3370 ***********************************************************************/
3371
3372private function f_tx_lapdm(template (value) LapdmFrame l,
3373 template (value) RslLinkId link_id) runs on ConnHdlr {
3374 var octetstring l2 := enc_LapdmFrame(valueof(l));
3375 if (valueof(link_id.c) == SACCH) {
3376 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02003377 var L1ctlDataReq l1hl2 := {
3378 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
3379 l2_payload := f_pad_oct(l2, 21, '2B'O)
3380 }
3381 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
3382 } else {
3383 /* If required, pad L2 frame with constant 0x2b filling */
3384 l2 := f_pad_oct(l2, 23, '2B'O);
3385
3386 log("encoding ", l, " to ", l2);
3387 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01003388 }
Harald Welte0472ab42018-03-12 15:02:26 +01003389}
3390
3391type record RllTestCase {
3392 uint3_t sapi,
3393 RslLinkId link_id,
3394 octetstring l3,
3395 boolean exp
3396}
3397type record of RllTestCase RllTestCases;
3398template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3399 sapi := sapi,
3400 link_id := id,
3401 l3 := l3,
3402 exp := exp
3403}
3404
3405/* execute the same callback function with a set of different parameters (tcs) on a
3406 * variety of logical channels */
3407private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3408 var ConnHdlrPars pars;
3409 var ConnHdlr vc_conn;
3410 f_init(testcasename());
3411
3412 /* test on each of the channels we have */
3413 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3414 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3415
3416 /* test each of the test cases on the current channel */
3417 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3418 pars.spec.rll := tcs[j];
3419 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3420 vc_conn := f_start_handler(fn, pars);
3421 vc_conn.done;
3422 }
3423 }
3424
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01003426}
3427
3428/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3429private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3430 var RllTestCase tc := g_pars.spec.rll;
3431 timer T := 3.0;
3432
3433 f_l1_tune(L1CTL);
3434 RSL.clear;
3435
3436 /* activate the logical channel */
3437 f_est_dchan();
3438 L1CTL.clear;
3439
3440 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3441 T.start;
3442 alt {
3443 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3444 if (tc.exp) {
3445 setverdict(pass);
3446 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003448 }
3449 }
3450 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3451 if (tc.exp) {
3452 setverdict(pass);
3453 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003455 }
3456 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003457 /* We also expect to receive the measurements */
3458 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003459 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003461 }
3462 [not tc.exp] T.timeout {
3463 setverdict(pass);
3464 }
3465 }
3466
3467 f_rsl_chan_deact();
3468 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3469 f_rslem_unregister(0, g_chan_nr);
3470}
3471testcase TC_rll_est_ind() runs on test_CT {
3472 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003473 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003474 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003475 /* normal SAPI0 establishment */
3476 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003477 /* SAPI 3 doesn't support contention resolution */
3478 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3479 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3480 /* normal SAPI3 establishment on main DCCH */
3481 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3482 /* normal SAPI3 establishment on SACCH */
3483 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3484 };
3485 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3486}
3487
3488/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3489private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3490 var RllTestCase tc := g_pars.spec.rll;
3491 var L1ctlDlMessage dl;
3492 timer T := 3.0;
3493
3494 f_l1_tune(L1CTL);
3495 RSL.clear;
3496
3497 /* activate the logical channel */
3498 f_est_dchan();
3499 L1CTL.clear;
3500
3501 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3502 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3503 T.start;
3504 alt {
3505 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3506 var LapdmFrame lapdm;
3507 var octetstring l2 := dl.payload.data_ind.payload;
3508 if (dl.dl_info.link_id.c == SACCH) {
3509 /* remove L1 header */
3510 l2 := substr(l2, 2, lengthof(l2)-2);
3511 }
3512 lapdm.ab := dec_LapdmFrameAB(l2);
3513 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3514 setverdict(pass);
3515 } else {
3516 repeat;
3517 }
3518 }
3519 [] L1CTL.receive { repeat; }
3520 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01003522 }
3523 }
3524
3525 f_rsl_chan_deact();
3526 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3527 f_rslem_unregister(0, g_chan_nr);
3528}
3529testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3530 var RllTestCases tcs := {
3531 /* normal SAPI3 establishment on main DCCH */
3532 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3533 };
3534 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3535}
3536testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3537 var RllTestCases tcs := {
3538 /* normal SAPI3 establishment on SACCH */
3539 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3540 }
3541 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3542}
3543
3544/* altstep to receive a LAPDm frame matching the given template */
3545private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3546 var L1ctlDlMessage dl;
3547 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3548 var LapdmFrame lapdm;
3549 var octetstring l2 := dl.payload.data_ind.payload;
3550 if (dl.dl_info.link_id.c == SACCH) {
3551 /* remove L1 header */
3552 l2 := substr(l2, 2, lengthof(l2)-2);
3553 }
3554 if (ischosen(exp.ab)) {
3555 lapdm.ab := dec_LapdmFrameAB(l2);
3556 } else if (ischosen(exp.b4)) {
3557 lapdm.b4 := dec_LapdmFrameB4(l2);
3558 } else if (ischosen(exp.bbis)) {
3559 lapdm.bbis := dec_LapdmFrameBbis(l2);
3560 }
3561 log("Rx LAPDm ", lapdm);
3562 if (match(lapdm, exp)) {
3563 setverdict(pass);
3564 } else {
3565 repeat;
3566 }
3567 }
3568 [] L1CTL.receive { repeat; }
3569}
3570private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3571 timer T := t;
3572 T.start;
3573 alt {
3574 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01003576 }
3577 [] as_l1_exp_lapdm(exp);
3578 }
3579}
3580
3581/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3582private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3583 /* send SABM from MS -> BTS */
3584 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3585 /* expect RLL EST IND on Abis */
3586 alt {
3587 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3588 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3589 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003591 }
3592 [] RSL.receive { repeat; }
3593 }
3594 /* expect UA from BTS -> MS */
3595 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3596}
3597
3598/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3599private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3600 var RllTestCase tc := g_pars.spec.rll;
3601
3602 f_l1_tune(L1CTL);
3603 RSL.clear;
3604
3605 /* activate the logical channel */
3606 f_est_dchan();
3607 L1CTL.clear;
3608
3609 /* first establish the link-layer */
3610 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3611
3612 /* then send the DISC */
3613 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3614 /* ... and expect the REL IND on the RSL side */
3615 alt {
3616 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3617 setverdict(pass);
3618 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003619 /* We also expect to receive the measurements */
3620 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003621 }
3622
3623 /* release the channel */
3624 f_rsl_chan_deact();
3625 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3626 f_rslem_unregister(0, g_chan_nr);
3627}
3628testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3629 var RllTestCases tcs := {
3630 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3631 };
3632 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3633}
3634
3635testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3636 var RllTestCases tcs := {
3637 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3638 };
3639 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3640}
3641testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3642 var RllTestCases tcs := {
3643 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3644 };
3645 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3646}
3647testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3648 var RllTestCases tcs := {
3649 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3650 };
3651 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3652}
3653
3654/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3655private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3656 var RllTestCase tc := g_pars.spec.rll;
3657 f_l1_tune(L1CTL);
3658 RSL.clear;
3659
3660 /* activate the logical channel */
3661 f_est_dchan();
3662 L1CTL.clear;
3663
3664 /* first establish the link-layer */
3665 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3666
3667 /* then send the REL REQ via RSL */
3668 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3669 /* ... and expect the DISC on the Um side */
3670 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003671 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003672 /* FIXME: send a UA in resposne to the DISC */
3673 }
3674 }
3675
3676 /* release the channel */
3677 f_rsl_chan_deact();
3678 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3679 f_rslem_unregister(0, g_chan_nr);
3680}
3681testcase TC_rll_rel_req() runs on test_CT {
3682 var RllTestCases tcs := {
3683 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3684 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3685 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3686 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3687 };
3688 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3689}
3690
3691/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3692testcase TC_rll_data_req() runs on test_CT {
3693}
3694
3695/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3696testcase TC_rll_data_ind() runs on test_CT {
3697}
3698
3699/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3700private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3701 var RllTestCase tc := g_pars.spec.rll;
3702
3703 f_l1_tune(L1CTL);
3704 RSL.clear;
3705
3706 f_est_dchan();
3707 L1CTL.clear;
3708
3709 /* Send UNITDATA REQ on RSL side */
3710 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3711 /* Expect it to arrive on the other side */
3712 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003713 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003714 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003715 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003716 }
3717
3718 /* release the channel */
3719 f_rsl_chan_deact();
3720 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3721 f_rslem_unregister(0, g_chan_nr);
3722}
3723testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3724 var octetstring l3 := f_rnd_octstring(15);
3725 var RllTestCases tcs := {
3726 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3727 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3728 };
3729 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3730}
3731testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3732 var octetstring l3 := f_rnd_octstring(19);
3733 var RllTestCases tcs := {
3734 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3735 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3736 };
3737 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3738}
3739
3740/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3741private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3742 var RllTestCase tc := g_pars.spec.rll;
3743
3744 f_l1_tune(L1CTL);
3745 RSL.clear;
3746
3747 f_est_dchan();
3748 L1CTL.clear;
3749
3750 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003751 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003752 /* Expdct RLL UNITDATA IND on RSL side */
3753 alt {
3754 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3755 setverdict(pass);
3756 }
3757 [] RSL.receive { repeat; }
3758 }
3759
3760 /* release the channel */
3761 f_rsl_chan_deact();
3762 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3763 f_rslem_unregister(0, g_chan_nr);
3764}
3765testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02003766 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01003767 var RllTestCases tcs := {
3768 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3769 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3770 };
3771 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3772}
3773testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3774 var octetstring l3 := f_rnd_octstring(18);
3775 var RllTestCases tcs := {
3776 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3777 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3778 };
3779 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3780}
3781
Harald Weltee613f962018-04-18 22:38:16 +02003782/***********************************************************************
3783 * Encryption Related
3784 ***********************************************************************/
3785
3786/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3787function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3788 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3789 if (link_id.c == SACCH) {
3790 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3791 } else {
3792 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3793 }
3794}
3795
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003796/* Expect (or not expect) other kinds of messages */
3797private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
3798 [exp_any] RSL.receive { repeat; }
3799 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003801 }
3802}
3803
Harald Weltee613f962018-04-18 22:38:16 +02003804/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07003805private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003806 RslLinkId link_id,
3807 octetstring l3,
3808 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003809 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003810) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02003811 timer T := 3.0;
3812 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3813 T.start;
3814 /* Expect RLL UNITDATA IND on RSL side */
3815 alt {
3816 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3817 setverdict(pass);
3818 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003819 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003820 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02003821 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02003823 }
Harald Weltee613f962018-04-18 22:38:16 +02003824 }
3825}
3826
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003827/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
3828private function f_data_mo(
3829 RslLinkId link_id,
3830 boolean p, uint3_t nr, uint3_t ns,
3831 octetstring l3,
3832 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003833 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003834) runs on ConnHdlr {
3835 timer T := 3.0;
3836 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
3837 T.start;
3838 /* Expect RLL DATA IND on RSL side */
3839 alt {
3840 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
3841 setverdict(pass);
3842 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003843 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003844 [] as_rsl_any_ind(exp_any);
3845 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003847 }
3848 }
3849}
3850
Harald Weltee613f962018-04-18 22:38:16 +02003851/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3852function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3853 f_l1_tune(L1CTL);
3854 f_est_dchan(true);
3855
3856 /* now we actually need to transmit some data both ways to check if the encryption works */
3857 var L1ctlDlMessage dl;
3858
Stefan Sperling603d98e2018-07-25 16:47:28 +02003859 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02003860 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3861
3862 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3863 f_unitdata_mt(link_id, l3);
3864
3865 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3866 f_unitdata_mo(link_id, l3);
3867
3868 /* release the channel */
3869 f_rsl_chan_deact();
3870 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3871 f_rslem_unregister(0, g_chan_nr);
3872}
3873testcase TC_chan_act_a51() runs on test_CT {
3874 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3875 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3876 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3877}
3878testcase TC_chan_act_a52() runs on test_CT {
3879 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3880 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3881 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3882}
3883testcase TC_chan_act_a53() runs on test_CT {
3884 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3885 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3886 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3887}
3888
3889
3890/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3891function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3892 /* L3 payload doesn't matter, as it is passed transparently */
3893 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3894 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3895 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3896
3897 f_l1_tune(L1CTL);
3898
3899 /* first establish a dedicated channel in the clear */
3900 f_est_dchan(false);
3901
3902 /* Establish ABM */
3903 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3904
3905 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3906 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3907 /* expect the L3 to arrive still unencrypted on the MS side */
3908 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3909
3910 /* configure L1 to apply ciphering */
3911 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3912 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3913
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003914 /* send first ciphered I-frame in response and expect it on RSL */
3915 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02003916
3917 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3918 * and hence enable encryption also on the downlink */
3919
3920 /* expect bi-directional communication work in encrypted mode */
3921 f_unitdata_mo(link_id, f_rnd_octstring(15));
3922 f_unitdata_mt(link_id, f_rnd_octstring(15));
3923
3924 /* release the channel */
3925 f_rsl_chan_deact();
3926 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3927 f_rslem_unregister(0, g_chan_nr);
3928}
3929testcase TC_encr_cmd_a51() runs on test_CT {
3930 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3931 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3932 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3933}
3934testcase TC_encr_cmd_a52() runs on test_CT {
3935 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3936 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3937 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3938}
3939testcase TC_encr_cmd_a53() runs on test_CT {
3940 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3941 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3942 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3943}
3944
3945private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3946 var LapdmFrame lf;
3947 var octetstring reenc;
3948
3949 /* decode the LAPDm frame */
3950 if (ischosen(exp_match.ab)) {
3951 lf.ab := dec_LapdmFrameAB(enc);
3952 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02003954 }
3955
3956 /* check if decoder result matches expectation */
3957 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003959 } else {
3960 log(name, ": matched");
3961 setverdict(pass);
3962 }
3963
3964 /* test if re-encoded frame equals original input */
3965 reenc := enc_LapdmFrame(lf);
3966 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003968 } else {
3969 setverdict(pass);
3970 }
3971}
3972
3973testcase TC_lapdm_selftest() runs on test_CT {
3974 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3975 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3976 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3977 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3978 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3979 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3980 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3981}
3982
Stefan Sperling4880be42018-08-07 18:12:59 +02003983/***********************************************************************
3984 * DTX Related (see GSM 05.08, section 8.3)
3985 ***********************************************************************/
3986
3987/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
3988function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
3989 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
3990 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
3991 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
3992 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
3993}
3994function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
3995 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
3996 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
3997}
3998function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
3999 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4000 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4001 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4002 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4003}
4004function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4005 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4006 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4007 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4008 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4009 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4010 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4011 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4012 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4013}
4014
4015function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4016 var L1ctlDlMessage dl;
4017 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4018 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4019 var GsmFrameNumber first_fn;
4020 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004021 var integer nfill_frames_sacch := 0;
4022 var integer nfill_frames_nonsacch := 0;
4023 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004024 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4025 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004026 const integer frame_dtx_tchf_mod := 104;
4027 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4028 * which operates in terms of blocks rather than frames. */
4029 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4030 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004031 timer T := 5.0;
4032
4033 f_l1_tune(L1CTL);
4034 RSL.clear;
4035 L1CTL.clear;
4036
4037 /* activate TCHF signalling channel */
4038 f_est_dchan(false);
4039
4040 T.start;
4041 alt {
4042 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4043 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4044 var octetstring l2 := dl.payload.data_ind.payload;
4045
4046 if (is_first_frame) {
4047 is_first_frame := false;
4048 first_fn := dl.dl_info.frame_nr;
4049 }
4050
4051 if (dl.dl_info.link_id.c == SACCH) {
4052 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4053 if (not match(l2_fill_frame_sacch, l2)) {
4054 repeat;
4055 }
4056 } else if (not match(l2_fill_frame, l2)) {
4057 repeat;
4058 }
4059
4060 if (dtxd) {
4061 if (not f_g_chan_is_tchf()) {
4062 T.stop;
4063 f_rsl_chan_deact();
4064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004065 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 +02004066 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004067 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004068 T.stop;
4069 f_rsl_chan_deact();
4070 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004071
4072 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4073 * 2 SACCH, 1 TCH/F */
4074 expected_fill_frames := 3;
4075
4076 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4077 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4078 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004080 } else {
4081 setverdict(pass);
4082 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004083 } else {
4084 if (dl.dl_info.link_id.c == SACCH) {
4085 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004086 repeat;
4087 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004088 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4089 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4090 * we should only see the subset of frames numbers which correspond to a block boundary.
4091 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4092 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4093 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4094 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4095 repeat;
4096 }
4097 }
4098 log("Received DTX TCH fill frame with bad frame number: ", fn,
4099 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4100 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4101 f_rsl_chan_deact();
4102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004104 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004105 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004106 if (dl.dl_info.link_id.c == SACCH) {
4107 nfill_frames_sacch := nfill_frames_sacch + 1;
4108 } else {
4109 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4110 }
4111 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004112 T.stop;
4113 if (f_g_chan_is_tchf()) {
4114 /* Without DTX we can expect 25 fill frames for every 104 frames.
4115 * (24 FACCH + 1 SACCH filling) */
4116 expected_fill_frames := 25;
4117 } else if (f_g_chan_is_tchh()) {
4118 /* We can expect 2 fill frames for every 104 frames. */
4119 expected_fill_frames := 2;
4120 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4121 /* We can expect 5 fill frames for every 104 frames. */
4122 expected_fill_frames := 5;
4123 } else {
4124 f_rsl_chan_deact();
4125 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004127 }
4128
4129 f_rsl_chan_deact();
4130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004131
4132 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004133 setverdict(pass);
4134 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004135 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4136 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004138 }
4139 } else {
4140 repeat;
4141 }
4142 }
4143 }
4144 [] L1CTL.receive { repeat; }
4145 [] T.timeout {
4146 f_rsl_chan_deact();
4147 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004149 }
4150 }
4151}
4152
4153function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4154 f_test_l2_fill_frames(false);
4155}
4156
4157function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4158 f_test_l2_fill_frames(true);
4159}
4160
4161function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4162 var ConnHdlr vc_conn;
4163 var ConnHdlrPars pars;
4164 pars.t_guard := 60.0;
4165 f_init(testcasename());
4166 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4167 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4168 if (dtxd) {
4169 if (i >= 4) { /* DTX is only allowed on TCH/F */
4170 break;
4171 }
4172 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4173 } else {
4174 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4175 }
4176 vc_conn.done;
4177 }
4178}
4179
4180/* Verify that L2 fill frames are sent on TCH in signaling mode if
4181 * there is nothing to transmit while DTX is disabled on downlink. */
4182testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4183 f_tch_sign_l2_fill_frame(false);
4184}
4185
4186/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4187 * there is nothing to transmit while DTX is enabled on downlink. */
4188testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4189 f_tch_sign_l2_fill_frame(true);
4190}
Harald Welte0472ab42018-03-12 15:02:26 +01004191
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004192testcase TC_chopped_ipa_ping() runs on test_CT {
4193 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4194}
4195
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004196testcase TC_chopped_ipa_payload() runs on test_CT {
4197 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4198}
4199
Harald Welte0472ab42018-03-12 15:02:26 +01004200/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4201/* protocol error as per 44.006 */
4202/* link layer failure (repetition of I-frame N200 times without ACK */
4203/* repetition of SABM or DISC N200 times without ACK */
4204/* receptiom of SABM in multi-frame established state */
4205
4206
4207
4208
Harald Welte883340c2018-02-28 18:59:29 +01004209
Harald Welte68e495b2018-02-25 00:05:57 +01004210/* TODO Areas:
4211
4212* channel activation
4213** with BS_Power / MS_Power, bypassing power control loop
4214** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004215** with timing advance from initial activation on
4216* mode modify
4217** encryption
4218** multirate
4219* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01004220** unsupported algorithm
4221* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01004222* BS Power Control
4223* Physical Context
Harald Welte43c54642018-09-15 17:47:04 +03004224* CCCH Load Indication for RACH
Harald Welte68e495b2018-02-25 00:05:57 +01004225* SMS Broadcast Req / Cmd / CBCH LOad Ind
4226* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01004227* error handling
Harald Welte43c54642018-09-15 17:47:04 +03004228** discriminator error
Harald Welte68e495b2018-02-25 00:05:57 +01004229** type error
4230** sequence error
4231** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01004232* PCU interface
4233** TIME_IND from BTS->PCU
4234** DATA_IND from BTS->PCU
4235** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01004236
4237*/
Harald Welte70767382018-02-21 12:16:40 +01004238
4239control {
4240 execute( TC_chan_act_stress() );
4241 execute( TC_chan_act_react() );
4242 execute( TC_chan_deact_not_active() );
4243 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01004244 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01004245 execute( TC_sacch_filling() );
4246 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01004247 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01004248 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01004249 execute( TC_rach_content() );
4250 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01004251 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01004252 execute( TC_meas_res_sign_tchf() );
4253 execute( TC_meas_res_sign_tchh() );
4254 execute( TC_meas_res_sign_sdcch4() );
4255 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01004256 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01004257 execute( TC_rsl_ms_pwr_ctrl() );
Harald Welte70767382018-02-21 12:16:40 +01004258 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01004259 execute( TC_paging_imsi_80percent() );
4260 execute( TC_paging_tmsi_80percent() );
4261 execute( TC_paging_imsi_200percent() );
4262 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01004263 execute( TC_rsl_protocol_error() );
4264 execute( TC_rsl_mand_ie_error() );
4265 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01004266 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01004267 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01004268 execute( TC_si_sched_2bis() );
4269 execute( TC_si_sched_2ter() );
4270 execute( TC_si_sched_2ter_2bis() );
4271 execute( TC_si_sched_2quater() );
4272 execute( TC_si_sched_13() );
4273 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01004274 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01004275 execute( TC_ipa_crcx_twice_not_active() );
4276 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01004277 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01004278 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01004279
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01004280 if (mp_pcu_socket != "") {
4281 execute( TC_pcu_act_req() );
4282 execute( TC_pcu_act_req_wrong_ts() );
4283 execute( TC_pcu_act_req_wrong_bts() );
4284 execute( TC_pcu_act_req_wrong_trx() );
4285 execute( TC_pcu_deact_req() );
4286 execute( TC_pcu_deact_req_wrong_ts() );
4287 execute( TC_pcu_ver_si13() );
4288 execute( TC_pcu_data_req_wrong_bts() );
4289 execute( TC_pcu_data_req_wrong_trx() );
4290 execute( TC_pcu_data_req_wrong_ts() );
4291 execute( TC_pcu_data_req_ts_inactive() );
4292 execute( TC_pcu_data_req_pdtch() );
4293 execute( TC_pcu_data_req_ptcch() );
4294 execute( TC_pcu_data_req_agch() );
4295 execute( TC_pcu_data_req_imm_ass_pch() );
4296 execute( TC_pcu_rach_content() );
4297 execute( TC_pcu_paging_from_rsl() );
4298 } else {
4299 log("PCU socket path not available, skipping PCU tests");
4300 }
Harald Welte3d04ae62018-04-04 20:29:05 +02004301
4302 execute( TC_dyn_osmo_pdch_act_deact() );
4303 execute( TC_dyn_osmo_pdch_unsol_deact() );
4304 execute( TC_dyn_osmo_pdch_double_act() );
4305 execute( TC_dyn_osmo_pdch_tchf_act() );
4306 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02004307 execute( TC_dyn_ipa_pdch_act_deact() );
4308 execute( TC_dyn_ipa_pdch_tchf_act() );
4309 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
4310 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01004311
4312 execute( TC_rll_est_ind() );
4313 execute( TC_rll_est_req_DCCH_3() );
4314 execute( TC_rll_est_req_ACCH_3() );
4315 execute( TC_rll_rel_ind_DCCH_0() );
4316 execute( TC_rll_rel_ind_DCCH_3() );
4317 execute( TC_rll_rel_ind_ACCH_0() );
4318 execute( TC_rll_rel_ind_ACCH_3() );
4319 execute( TC_rll_rel_req() );
4320 execute( TC_rll_unit_data_req_DCCH() );
4321 execute( TC_rll_unit_data_req_ACCH() );
4322 execute( TC_rll_unit_data_ind_DCCH() );
4323 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02004324
4325 execute( TC_chan_act_a51() );
4326 execute( TC_chan_act_a52() );
4327 execute( TC_chan_act_a53() );
4328 execute( TC_encr_cmd_a51() );
4329 execute( TC_encr_cmd_a52() );
4330 execute( TC_encr_cmd_a53() );
4331
4332 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02004333
4334 execute( TC_tch_sign_l2_fill_frame() );
4335 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004336
4337 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004338 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01004339}
4340
4341
4342}