blob: e61732371a9fd02059b4668d7e71bc16db6c711c [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 {
Max6e053042019-03-14 16:34:22 +01001103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
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
Max2c6f5632019-03-18 17:25:17 +01002726private function f_init_pcu_test() runs on test_CT {
2727 f_init();
2728 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
2729}
2730
Harald Welte883340c2018-02-28 18:59:29 +01002731/* PDCH activation via PCU socket; check for presence of RTS.req */
2732testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002733 f_init_pcu_test();
2734
Harald Welte883340c2018-02-28 18:59:29 +01002735 f_TC_pcu_act_req(0, 0, 7, true);
2736}
2737
2738/* PDCH activation via PCU socket on non-PDCU timeslot */
2739testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002740 f_init_pcu_test();
2741
Harald Welte883340c2018-02-28 18:59:29 +01002742 f_TC_pcu_act_req(0, 0, 1, false);
2743}
2744
2745/* PDCH activation via PCU socket on wrong BTS */
2746testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002747 f_init_pcu_test();
2748
Harald Welte883340c2018-02-28 18:59:29 +01002749 f_TC_pcu_act_req(23, 0, 7, false);
2750}
2751
2752/* PDCH activation via PCU socket on wrong TRX */
2753testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002754 f_init_pcu_test();
2755
Harald Welte883340c2018-02-28 18:59:29 +01002756 f_TC_pcu_act_req(0, 23, 7, false);
2757}
2758
2759/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2760testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002761 f_init_pcu_test();
2762
Harald Welte883340c2018-02-28 18:59:29 +01002763 /* Activate PDCH */
2764 f_TC_pcu_act_req(0, 0, 7, true);
2765 f_sleep(1.0);
2766 /* and De-Activate again */
2767 f_TC_pcu_deact_req(0, 0, 7);
2768}
2769
2770/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2771testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002772 f_init_pcu_test();
2773
Harald Welte883340c2018-02-28 18:59:29 +01002774 f_TC_pcu_deact_req(0, 0, 1);
2775}
2776
2777/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2778testcase TC_pcu_ver_si13() runs on test_CT {
2779 const octetstring si13 := '00010203040506070909'O;
2780 var PCUIF_send_data sd;
2781 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01002782 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002783
2784 /* Set SI13 via RSL */
2785 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01002786
Harald Welte883340c2018-02-28 18:59:29 +01002787 T.start;
2788 alt {
2789 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2790 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2791 setverdict(pass);
2792 } else {
2793 repeat;
2794 }
2795 }
2796 [] PCU.receive { repeat; }
2797 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01002799 }
2800 }
2801}
2802
2803private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2804
2805/* helper function to send a PCU DATA.req */
2806private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2807 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2808runs on test_CT
2809{
2810 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2811 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2812}
2813
2814/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2815private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2816 PCUIF_Sapi sapi, octetstring data)
2817runs on test_CT
2818{
2819 var PCUIF_send_data sd;
2820
2821 timer T := 3.0;
2822 T.start;
2823 alt {
2824 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2825 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2826 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2827 sd.data.u.rts_req.fn, sapi, data);
2828 }
2829 [] PCU.receive { repeat; }
2830 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01002832 }
2833 }
2834}
2835
2836/* Send DATA.req on invalid BTS */
2837testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002838 f_init_pcu_test();
2839
Harald Welte883340c2018-02-28 18:59:29 +01002840 f_TC_pcu_act_req(0, 0, 7, true);
2841 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2842 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2843 f_sleep(10.0);
2844}
2845
2846/* Send DATA.req on invalid TRX */
2847testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002848 f_init_pcu_test();
2849
Harald Welte883340c2018-02-28 18:59:29 +01002850 f_TC_pcu_act_req(0, 0, 7, true);
2851 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2852 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2853 f_sleep(10.0);
2854}
2855
2856/* Send DATA.req on invalid timeslot */
2857testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002858 f_init_pcu_test();
2859
Harald Welte883340c2018-02-28 18:59:29 +01002860 f_TC_pcu_act_req(0, 0, 7, true);
2861 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2862 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2863 f_sleep(10.0);
2864}
2865
2866/* Send DATA.req on timeslot that hasn't been activated */
2867testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002868 f_init_pcu_test();
2869
Harald Welte883340c2018-02-28 18:59:29 +01002870 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2871 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2872 f_sleep(2.0);
2873}
2874
2875testcase TC_pcu_data_req_pdtch() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002876 f_init_pcu_test();
2877
Harald Welte883340c2018-02-28 18:59:29 +01002878 f_TC_pcu_act_req(0, 0, 7, true);
2879 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2880 /* FIXME: how to check this was actually sent */
2881 f_sleep(2.0);
2882}
2883
2884testcase TC_pcu_data_req_ptcch() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002885 f_init_pcu_test();
2886
Harald Welte883340c2018-02-28 18:59:29 +01002887 f_TC_pcu_act_req(0, 0, 7, true);
2888 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2889 /* FIXME: how to check this was actually sent */
2890 f_sleep(2.0);
2891}
2892
2893/* Send AGCH from PCU; check it appears on Um side */
2894testcase TC_pcu_data_req_agch() runs on test_CT {
2895 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01002896 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002897 f_init_l1ctl();
2898 f_l1_tune(L1CTL);
2899
2900 f_TC_pcu_act_req(0, 0, 7, true);
2901 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2902
2903 T.start;
2904 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002905 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002906 setverdict(pass);
2907 }
2908 [] L1CTL.receive { repeat; }
2909 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002911 }
2912 }
2913}
2914
2915/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2916testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2917 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01002918 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002919 f_init_l1ctl();
2920 f_l1_tune(L1CTL);
2921
2922 /* append 3 last imsi digits so BTS can compute pagng group */
2923 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2924
2925 timer T := 0.5;
2926 T.start;
2927 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002928 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002929 /* TODO: verify paging group */
2930 setverdict(pass);
2931 }
2932 [] L1CTL.receive { repeat; }
2933 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002935 }
2936 }
2937}
2938
2939/* Send RACH from Um side, expect it to show up on PCU socket */
2940testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002941 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002942 f_init_l1ctl();
2943 f_l1_tune(L1CTL);
2944
2945 var GsmFrameNumber fn_last := 0;
2946 for (var integer i := 0; i < 1000; i := i+1) {
2947 var OCT1 ra := f_rnd_ra_ps();
2948 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2949 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01002951 }
2952 fn_last := fn;
2953
2954 timer T := 2.0;
2955 T.start;
2956 alt {
2957 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2958 T.stop;
2959 }
2960 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002962 }
2963 [] PCU.receive { repeat; }
2964 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002966 }
2967 }
2968 }
2969 setverdict(pass);
2970}
2971
2972private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2973 var integer strlen := lengthof(str);
2974 for (var integer i := 0; i < len-strlen; i := i+1) {
2975 str := str & pad;
2976 }
2977 return str;
2978}
2979
2980/* Send PAGING via RSL, expect it to shw up on PCU socket */
2981testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002982 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002983
2984 for (var integer i := 0; i < 100; i := i+1) {
2985 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2986 timer T := 3.0;
2987 if (i < 50) {
2988 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2989 } else {
2990 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2991 }
2992 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2993 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2994 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2995
2996 /* Send RSL PAGING COMMAND */
2997 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2998 T.start;
2999 alt {
3000 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3001 }
3002 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003004 }
3005 [] PCU.receive { repeat; }
3006 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003008 }
3009 }
3010 }
3011 setverdict(pass);
3012}
3013
Harald Welte3d04ae62018-04-04 20:29:05 +02003014/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003015 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003016 ***********************************************************************/
3017
3018private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3019runs on ConnHdlr {
3020 var PCUIF_send_data sd;
3021 /* Expect BTS to immediately acknowledge activation as PDCH */
3022 PCU.clear;
3023 f_rsl_chan_act(g_pars.chan_mode);
3024 /* expect INFO_IND on PCU interface listing TS as PDCH */
3025 alt {
3026 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3027 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 +02003028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003029 }
3030 }
3031 [] PCU.receive { repeat; }
3032 }
3033 /* try to activate this PDCH from the PCU point of view */
3034 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3035 /* FIXME: is there a response? */
3036}
3037
3038private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3039runs on ConnHdlr {
3040 var PCUIF_send_data sd;
3041 /* Send RSL CHAN REL (deactivate) */
3042 PCU.clear;
3043 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3044 /* expect BTS to ask PCU to deactivate the channel */
3045 alt {
3046 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3047 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 +02003048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003049 }
3050 }
3051 [] PCU.receive { repeat; }
3052 }
3053 /* Emulate PCU asking BTS to deactivate PDCH */
3054 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3055 alt {
3056 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3057 setverdict(pass);
3058 }
3059 [] RSL.receive { repeat; }
3060 }
3061}
3062
3063/* Activate Osmocom-style dynamic PDCH from BSC side */
3064function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3065 var PCUIF_Message first_info;
3066 var integer ts_nr := g_chan_nr.tn;
3067 var integer trx_nr := 0;
3068 var integer bts_nr := 0;
3069 var integer pcu_conn_id := -1;
3070
3071 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3072
3073 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3074 f_sleep(3.0);
3075 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3076 setverdict(pass);
3077}
3078testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3079 var ConnHdlrPars pars;
3080 var ConnHdlr vc_conn;
3081 f_init(testcasename());
3082
3083 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3084 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3085 vc_conn.done;
3086}
3087
3088/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3089function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3090 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003091 var integer pcu_conn_id := -1;
3092
3093 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3094
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003095 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3096 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3097 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003098 setverdict(pass);
3099}
3100testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3101 var ConnHdlrPars pars;
3102 var ConnHdlr vc_conn;
3103 f_init(testcasename());
3104
3105 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3106 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3107 vc_conn.done;
3108}
3109
3110/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3111function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3112 var PCUIF_Message first_info;
3113 var integer ts_nr := g_chan_nr.tn;
3114 var integer trx_nr := 0;
3115 var integer bts_nr := 0;
3116 var integer pcu_conn_id := -1;
3117
3118 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3119
3120 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003121 /* Send a second Chan Activ and expect it to be NACKed */
3122 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3123 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003124 setverdict(pass);
3125}
3126testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3127 var ConnHdlrPars pars;
3128 var ConnHdlr vc_conn;
3129 f_init(testcasename());
3130
3131 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3132 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3133 vc_conn.done;
3134}
3135
3136/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3137function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3138 var PCUIF_Message first_info;
3139 var integer ts_nr := g_chan_nr.tn;
3140 var integer trx_nr := 0;
3141 var integer bts_nr := 0;
3142 var integer pcu_conn_id := -1;
3143 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3144
3145 /* register for the TCH/F channel number */
3146 f_rslem_register(0, chan_nr);
3147
3148 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3149
3150 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3151 "RSL CHAN ACT");
3152 setverdict(pass);
3153}
3154testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3155 var ConnHdlrPars pars;
3156 var ConnHdlr vc_conn;
3157 f_init(testcasename());
3158
3159 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3160 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3161 vc_conn.done;
3162}
3163
3164/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3165function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3166 var PCUIF_Message first_info;
3167 var integer ts_nr := g_chan_nr.tn;
3168 var integer trx_nr := 0;
3169 var integer bts_nr := 0;
3170 var integer pcu_conn_id := -1;
3171 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3172 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3173
3174 /* register for the TCH/H channel numbers */
3175 f_rslem_register(0, chan_nr[0]);
3176 f_rslem_register(0, chan_nr[1]);
3177
3178 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3179
3180 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3181 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3182 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3183 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3184 setverdict(pass);
3185}
3186testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3187 var ConnHdlrPars pars;
3188 var ConnHdlr vc_conn;
3189 f_init(testcasename());
3190
3191 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3192 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3193 vc_conn.done;
3194}
3195
Harald Welte9bbbfb52018-04-05 09:33:19 +02003196/***********************************************************************
3197 * IPA Style Dynamic Timeslot Support
3198 ***********************************************************************/
3199
3200private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3201runs on ConnHdlr {
3202 var PCUIF_send_data sd;
3203 /* Expect BTS to immediately acknowledge activation as PDCH */
3204 PCU.clear;
3205 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3206 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003207 timer T_wait := 2.0;
3208 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003209 alt {
3210 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3211 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 +01003212 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
3213 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3214 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003215 }
3216 }
3217 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003218 [] T_wait.timeout {
3219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3220 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
3221 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003222 }
3223 /* try to activate this PDCH from the PCU point of view */
3224 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3225 /* FIXME: is there a response? */
3226
3227 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3228}
3229
3230private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3231runs on ConnHdlr {
3232 var PCUIF_send_data sd;
3233 /* Send RSL CHAN REL (deactivate) */
3234 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3235 PCU.clear;
3236 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003237 timer T_wait := 2.0;
3238 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003239 alt {
3240 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3241 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 +01003242 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
3243 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3244 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003245 }
3246 }
3247 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003248 [] T_wait.timeout {
3249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3250 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
3251 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003252 }
3253 /* Emulate PCU asking BTS to deactivate PDCH */
3254 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3255 alt {
3256 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3257 setverdict(pass);
3258 }
3259 [] RSL.receive { repeat; }
3260 }
3261}
3262
3263/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3264function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3265 var PCUIF_Message first_info;
3266 var integer ts_nr := g_chan_nr.tn;
3267 var integer trx_nr := 0;
3268 var integer bts_nr := 0;
3269 var integer pcu_conn_id := -1;
3270
3271 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3272
3273 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3274 f_sleep(3.0);
3275 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3276
3277 setverdict(pass);
3278
3279}
3280testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3281 var ConnHdlrPars pars;
3282 var ConnHdlr vc_conn;
3283 f_init();
3284
3285 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3286 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3287 vc_conn.done;
3288}
3289
3290/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3291function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3292 var PCUIF_Message first_info;
3293 var integer ts_nr := g_chan_nr.tn;
3294 var integer trx_nr := 0;
3295 var integer bts_nr := 0;
3296 var integer pcu_conn_id := -1;
3297
3298 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3299
3300 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3301 "RSL CHAN ACT");
3302 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3303 "RF CHAN REL", true);
3304 setverdict(pass);
3305}
3306testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3307 var ConnHdlrPars pars;
3308 var ConnHdlr vc_conn;
3309 f_init(testcasename());
3310
3311 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3312 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3313 vc_conn.done;
3314}
3315
3316/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3317function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3318 var PCUIF_Message first_info;
3319 var integer ts_nr := g_chan_nr.tn;
3320 var integer trx_nr := 0;
3321 var integer bts_nr := 0;
3322 var integer pcu_conn_id := -1;
3323
3324 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3325
3326 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3327 "RSL CHAN ACT");
3328
3329 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3330 alt {
3331 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3332 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003334 }
3335 [] RSL.receive { repeat; }
3336 }
3337
3338 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3339 "RF CHAN REL", true);
3340 setverdict(pass);
3341}
3342testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3343 var ConnHdlrPars pars;
3344 var ConnHdlr vc_conn;
3345 f_init(testcasename());
3346
3347 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3348 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3349 vc_conn.done;
3350}
3351
3352/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3353function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3354 var PCUIF_Message first_info;
3355 var integer ts_nr := g_chan_nr.tn;
3356 var integer trx_nr := 0;
3357 var integer bts_nr := 0;
3358 var integer pcu_conn_id := -1;
3359
3360 /* register for the TCH/F channel number */
3361 f_rslem_register(0, g_chan_nr);
3362
3363 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3364
3365 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3366
3367 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3368 "RSL CHAN ACT");
3369
3370 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3371
3372 setverdict(pass);
3373}
3374testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3375 var ConnHdlrPars pars;
3376 var ConnHdlr vc_conn;
3377 f_init(testcasename());
3378
3379 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3380 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3381 vc_conn.done;
3382}
3383
3384
Harald Welte0472ab42018-03-12 15:02:26 +01003385/***********************************************************************
3386 * LAPDm / RLL related
3387 ***********************************************************************/
3388
3389private function f_tx_lapdm(template (value) LapdmFrame l,
3390 template (value) RslLinkId link_id) runs on ConnHdlr {
3391 var octetstring l2 := enc_LapdmFrame(valueof(l));
3392 if (valueof(link_id.c) == SACCH) {
3393 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02003394 var L1ctlDataReq l1hl2 := {
3395 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
3396 l2_payload := f_pad_oct(l2, 21, '2B'O)
3397 }
3398 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
3399 } else {
3400 /* If required, pad L2 frame with constant 0x2b filling */
3401 l2 := f_pad_oct(l2, 23, '2B'O);
3402
3403 log("encoding ", l, " to ", l2);
3404 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01003405 }
Harald Welte0472ab42018-03-12 15:02:26 +01003406}
3407
3408type record RllTestCase {
3409 uint3_t sapi,
3410 RslLinkId link_id,
3411 octetstring l3,
3412 boolean exp
3413}
3414type record of RllTestCase RllTestCases;
3415template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3416 sapi := sapi,
3417 link_id := id,
3418 l3 := l3,
3419 exp := exp
3420}
3421
3422/* execute the same callback function with a set of different parameters (tcs) on a
3423 * variety of logical channels */
3424private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3425 var ConnHdlrPars pars;
3426 var ConnHdlr vc_conn;
3427 f_init(testcasename());
3428
3429 /* test on each of the channels we have */
3430 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3431 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3432
3433 /* test each of the test cases on the current channel */
3434 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3435 pars.spec.rll := tcs[j];
3436 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3437 vc_conn := f_start_handler(fn, pars);
3438 vc_conn.done;
3439 }
3440 }
3441
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01003443}
3444
3445/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3446private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3447 var RllTestCase tc := g_pars.spec.rll;
3448 timer T := 3.0;
3449
3450 f_l1_tune(L1CTL);
3451 RSL.clear;
3452
3453 /* activate the logical channel */
3454 f_est_dchan();
3455 L1CTL.clear;
3456
3457 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3458 T.start;
3459 alt {
3460 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3461 if (tc.exp) {
3462 setverdict(pass);
3463 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003465 }
3466 }
3467 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3468 if (tc.exp) {
3469 setverdict(pass);
3470 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003472 }
3473 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003474 /* We also expect to receive the measurements */
3475 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003476 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003478 }
3479 [not tc.exp] T.timeout {
3480 setverdict(pass);
3481 }
3482 }
3483
3484 f_rsl_chan_deact();
3485 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3486 f_rslem_unregister(0, g_chan_nr);
3487}
3488testcase TC_rll_est_ind() runs on test_CT {
3489 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003490 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003491 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003492 /* normal SAPI0 establishment */
3493 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003494 /* SAPI 3 doesn't support contention resolution */
3495 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3496 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3497 /* normal SAPI3 establishment on main DCCH */
3498 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3499 /* normal SAPI3 establishment on SACCH */
3500 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3501 };
3502 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3503}
3504
3505/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3506private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3507 var RllTestCase tc := g_pars.spec.rll;
3508 var L1ctlDlMessage dl;
3509 timer T := 3.0;
3510
3511 f_l1_tune(L1CTL);
3512 RSL.clear;
3513
3514 /* activate the logical channel */
3515 f_est_dchan();
3516 L1CTL.clear;
3517
3518 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3519 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3520 T.start;
3521 alt {
3522 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3523 var LapdmFrame lapdm;
3524 var octetstring l2 := dl.payload.data_ind.payload;
3525 if (dl.dl_info.link_id.c == SACCH) {
3526 /* remove L1 header */
3527 l2 := substr(l2, 2, lengthof(l2)-2);
3528 }
3529 lapdm.ab := dec_LapdmFrameAB(l2);
3530 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3531 setverdict(pass);
3532 } else {
3533 repeat;
3534 }
3535 }
3536 [] L1CTL.receive { repeat; }
3537 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01003539 }
3540 }
3541
3542 f_rsl_chan_deact();
3543 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3544 f_rslem_unregister(0, g_chan_nr);
3545}
3546testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3547 var RllTestCases tcs := {
3548 /* normal SAPI3 establishment on main DCCH */
3549 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3550 };
3551 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3552}
3553testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3554 var RllTestCases tcs := {
3555 /* normal SAPI3 establishment on SACCH */
3556 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3557 }
3558 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3559}
3560
3561/* altstep to receive a LAPDm frame matching the given template */
3562private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3563 var L1ctlDlMessage dl;
3564 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3565 var LapdmFrame lapdm;
3566 var octetstring l2 := dl.payload.data_ind.payload;
3567 if (dl.dl_info.link_id.c == SACCH) {
3568 /* remove L1 header */
3569 l2 := substr(l2, 2, lengthof(l2)-2);
3570 }
3571 if (ischosen(exp.ab)) {
3572 lapdm.ab := dec_LapdmFrameAB(l2);
3573 } else if (ischosen(exp.b4)) {
3574 lapdm.b4 := dec_LapdmFrameB4(l2);
3575 } else if (ischosen(exp.bbis)) {
3576 lapdm.bbis := dec_LapdmFrameBbis(l2);
3577 }
3578 log("Rx LAPDm ", lapdm);
3579 if (match(lapdm, exp)) {
3580 setverdict(pass);
3581 } else {
3582 repeat;
3583 }
3584 }
3585 [] L1CTL.receive { repeat; }
3586}
3587private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3588 timer T := t;
3589 T.start;
3590 alt {
3591 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01003593 }
3594 [] as_l1_exp_lapdm(exp);
3595 }
3596}
3597
3598/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3599private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3600 /* send SABM from MS -> BTS */
3601 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3602 /* expect RLL EST IND on Abis */
3603 alt {
3604 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3605 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3606 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003608 }
3609 [] RSL.receive { repeat; }
3610 }
3611 /* expect UA from BTS -> MS */
3612 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3613}
3614
3615/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3616private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3617 var RllTestCase tc := g_pars.spec.rll;
3618
3619 f_l1_tune(L1CTL);
3620 RSL.clear;
3621
3622 /* activate the logical channel */
3623 f_est_dchan();
3624 L1CTL.clear;
3625
3626 /* first establish the link-layer */
3627 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3628
3629 /* then send the DISC */
3630 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3631 /* ... and expect the REL IND on the RSL side */
3632 alt {
3633 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3634 setverdict(pass);
3635 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003636 /* We also expect to receive the measurements */
3637 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003638 }
3639
3640 /* release the channel */
3641 f_rsl_chan_deact();
3642 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3643 f_rslem_unregister(0, g_chan_nr);
3644}
3645testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3646 var RllTestCases tcs := {
3647 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3648 };
3649 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3650}
3651
3652testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3653 var RllTestCases tcs := {
3654 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3655 };
3656 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3657}
3658testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3659 var RllTestCases tcs := {
3660 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3661 };
3662 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3663}
3664testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3665 var RllTestCases tcs := {
3666 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3667 };
3668 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3669}
3670
3671/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3672private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3673 var RllTestCase tc := g_pars.spec.rll;
3674 f_l1_tune(L1CTL);
3675 RSL.clear;
3676
3677 /* activate the logical channel */
3678 f_est_dchan();
3679 L1CTL.clear;
3680
3681 /* first establish the link-layer */
3682 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3683
3684 /* then send the REL REQ via RSL */
3685 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3686 /* ... and expect the DISC on the Um side */
3687 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003688 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003689 /* FIXME: send a UA in resposne to the DISC */
3690 }
3691 }
3692
3693 /* release the channel */
3694 f_rsl_chan_deact();
3695 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3696 f_rslem_unregister(0, g_chan_nr);
3697}
3698testcase TC_rll_rel_req() runs on test_CT {
3699 var RllTestCases tcs := {
3700 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3701 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3702 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3703 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3704 };
3705 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3706}
3707
3708/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3709testcase TC_rll_data_req() runs on test_CT {
3710}
3711
3712/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3713testcase TC_rll_data_ind() runs on test_CT {
3714}
3715
3716/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3717private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3718 var RllTestCase tc := g_pars.spec.rll;
3719
3720 f_l1_tune(L1CTL);
3721 RSL.clear;
3722
3723 f_est_dchan();
3724 L1CTL.clear;
3725
3726 /* Send UNITDATA REQ on RSL side */
3727 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3728 /* Expect it to arrive on the other side */
3729 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003730 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003731 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003732 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003733 }
3734
3735 /* release the channel */
3736 f_rsl_chan_deact();
3737 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3738 f_rslem_unregister(0, g_chan_nr);
3739}
3740testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3741 var octetstring l3 := f_rnd_octstring(15);
3742 var RllTestCases tcs := {
3743 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3744 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3745 };
3746 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3747}
3748testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3749 var octetstring l3 := f_rnd_octstring(19);
3750 var RllTestCases tcs := {
3751 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3752 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3753 };
3754 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3755}
3756
3757/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3758private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3759 var RllTestCase tc := g_pars.spec.rll;
3760
3761 f_l1_tune(L1CTL);
3762 RSL.clear;
3763
3764 f_est_dchan();
3765 L1CTL.clear;
3766
3767 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003768 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003769 /* Expdct RLL UNITDATA IND on RSL side */
3770 alt {
3771 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3772 setverdict(pass);
3773 }
3774 [] RSL.receive { repeat; }
3775 }
3776
3777 /* release the channel */
3778 f_rsl_chan_deact();
3779 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3780 f_rslem_unregister(0, g_chan_nr);
3781}
3782testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02003783 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01003784 var RllTestCases tcs := {
3785 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3786 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3787 };
3788 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3789}
3790testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3791 var octetstring l3 := f_rnd_octstring(18);
3792 var RllTestCases tcs := {
3793 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3794 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3795 };
3796 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3797}
3798
Harald Weltee613f962018-04-18 22:38:16 +02003799/***********************************************************************
3800 * Encryption Related
3801 ***********************************************************************/
3802
3803/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3804function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3805 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3806 if (link_id.c == SACCH) {
3807 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3808 } else {
3809 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3810 }
3811}
3812
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003813/* Expect (or not expect) other kinds of messages */
3814private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
3815 [exp_any] RSL.receive { repeat; }
3816 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003818 }
3819}
3820
Harald Weltee613f962018-04-18 22:38:16 +02003821/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07003822private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003823 RslLinkId link_id,
3824 octetstring l3,
3825 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003826 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003827) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02003828 timer T := 3.0;
3829 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3830 T.start;
3831 /* Expect RLL UNITDATA IND on RSL side */
3832 alt {
3833 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3834 setverdict(pass);
3835 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003836 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003837 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02003838 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02003840 }
Harald Weltee613f962018-04-18 22:38:16 +02003841 }
3842}
3843
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003844/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
3845private function f_data_mo(
3846 RslLinkId link_id,
3847 boolean p, uint3_t nr, uint3_t ns,
3848 octetstring l3,
3849 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003850 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003851) runs on ConnHdlr {
3852 timer T := 3.0;
3853 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
3854 T.start;
3855 /* Expect RLL DATA IND on RSL side */
3856 alt {
3857 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
3858 setverdict(pass);
3859 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003860 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003861 [] as_rsl_any_ind(exp_any);
3862 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003864 }
3865 }
3866}
3867
Harald Weltee613f962018-04-18 22:38:16 +02003868/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3869function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3870 f_l1_tune(L1CTL);
3871 f_est_dchan(true);
3872
3873 /* now we actually need to transmit some data both ways to check if the encryption works */
3874 var L1ctlDlMessage dl;
3875
Stefan Sperling603d98e2018-07-25 16:47:28 +02003876 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02003877 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3878
3879 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3880 f_unitdata_mt(link_id, l3);
3881
3882 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3883 f_unitdata_mo(link_id, l3);
3884
3885 /* release the channel */
3886 f_rsl_chan_deact();
3887 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3888 f_rslem_unregister(0, g_chan_nr);
3889}
3890testcase TC_chan_act_a51() runs on test_CT {
3891 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3892 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3893 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3894}
3895testcase TC_chan_act_a52() runs on test_CT {
3896 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3897 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3898 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3899}
3900testcase TC_chan_act_a53() runs on test_CT {
3901 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3902 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3903 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3904}
3905
3906
3907/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3908function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3909 /* L3 payload doesn't matter, as it is passed transparently */
3910 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3911 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3912 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3913
3914 f_l1_tune(L1CTL);
3915
3916 /* first establish a dedicated channel in the clear */
3917 f_est_dchan(false);
3918
3919 /* Establish ABM */
3920 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3921
3922 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3923 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3924 /* expect the L3 to arrive still unencrypted on the MS side */
3925 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3926
3927 /* configure L1 to apply ciphering */
3928 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3929 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3930
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003931 /* send first ciphered I-frame in response and expect it on RSL */
3932 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02003933
3934 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3935 * and hence enable encryption also on the downlink */
3936
3937 /* expect bi-directional communication work in encrypted mode */
3938 f_unitdata_mo(link_id, f_rnd_octstring(15));
3939 f_unitdata_mt(link_id, f_rnd_octstring(15));
3940
3941 /* release the channel */
3942 f_rsl_chan_deact();
3943 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3944 f_rslem_unregister(0, g_chan_nr);
3945}
3946testcase TC_encr_cmd_a51() runs on test_CT {
3947 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3948 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3949 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3950}
3951testcase TC_encr_cmd_a52() runs on test_CT {
3952 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3953 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3954 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3955}
3956testcase TC_encr_cmd_a53() runs on test_CT {
3957 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3958 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3959 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3960}
3961
3962private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3963 var LapdmFrame lf;
3964 var octetstring reenc;
3965
3966 /* decode the LAPDm frame */
3967 if (ischosen(exp_match.ab)) {
3968 lf.ab := dec_LapdmFrameAB(enc);
3969 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02003971 }
3972
3973 /* check if decoder result matches expectation */
3974 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003976 } else {
3977 log(name, ": matched");
3978 setverdict(pass);
3979 }
3980
3981 /* test if re-encoded frame equals original input */
3982 reenc := enc_LapdmFrame(lf);
3983 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003985 } else {
3986 setverdict(pass);
3987 }
3988}
3989
3990testcase TC_lapdm_selftest() runs on test_CT {
3991 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3992 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3993 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3994 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3995 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3996 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3997 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3998}
3999
Stefan Sperling4880be42018-08-07 18:12:59 +02004000/***********************************************************************
4001 * DTX Related (see GSM 05.08, section 8.3)
4002 ***********************************************************************/
4003
4004/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4005function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4006 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4007 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4008 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4009 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4010}
4011function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4012 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4013 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4014}
4015function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4016 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4017 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4018 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4019 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4020}
4021function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4022 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4023 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4024 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4025 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4026 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4027 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4028 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4029 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4030}
4031
4032function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4033 var L1ctlDlMessage dl;
4034 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4035 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4036 var GsmFrameNumber first_fn;
4037 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004038 var integer nfill_frames_sacch := 0;
4039 var integer nfill_frames_nonsacch := 0;
4040 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004041 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4042 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004043 const integer frame_dtx_tchf_mod := 104;
4044 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4045 * which operates in terms of blocks rather than frames. */
4046 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4047 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004048 timer T := 5.0;
4049
4050 f_l1_tune(L1CTL);
4051 RSL.clear;
4052 L1CTL.clear;
4053
4054 /* activate TCHF signalling channel */
4055 f_est_dchan(false);
4056
4057 T.start;
4058 alt {
4059 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4060 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4061 var octetstring l2 := dl.payload.data_ind.payload;
4062
4063 if (is_first_frame) {
4064 is_first_frame := false;
4065 first_fn := dl.dl_info.frame_nr;
4066 }
4067
4068 if (dl.dl_info.link_id.c == SACCH) {
4069 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4070 if (not match(l2_fill_frame_sacch, l2)) {
4071 repeat;
4072 }
4073 } else if (not match(l2_fill_frame, l2)) {
4074 repeat;
4075 }
4076
4077 if (dtxd) {
4078 if (not f_g_chan_is_tchf()) {
4079 T.stop;
4080 f_rsl_chan_deact();
4081 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004082 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 +02004083 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004084 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004085 T.stop;
4086 f_rsl_chan_deact();
4087 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004088
4089 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4090 * 2 SACCH, 1 TCH/F */
4091 expected_fill_frames := 3;
4092
4093 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4094 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4095 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004097 } else {
4098 setverdict(pass);
4099 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004100 } else {
4101 if (dl.dl_info.link_id.c == SACCH) {
4102 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004103 repeat;
4104 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004105 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4106 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4107 * we should only see the subset of frames numbers which correspond to a block boundary.
4108 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4109 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4110 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4111 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4112 repeat;
4113 }
4114 }
4115 log("Received DTX TCH fill frame with bad frame number: ", fn,
4116 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4117 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4118 f_rsl_chan_deact();
4119 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004121 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004122 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004123 if (dl.dl_info.link_id.c == SACCH) {
4124 nfill_frames_sacch := nfill_frames_sacch + 1;
4125 } else {
4126 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4127 }
4128 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004129 T.stop;
4130 if (f_g_chan_is_tchf()) {
4131 /* Without DTX we can expect 25 fill frames for every 104 frames.
4132 * (24 FACCH + 1 SACCH filling) */
4133 expected_fill_frames := 25;
4134 } else if (f_g_chan_is_tchh()) {
4135 /* We can expect 2 fill frames for every 104 frames. */
4136 expected_fill_frames := 2;
4137 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4138 /* We can expect 5 fill frames for every 104 frames. */
4139 expected_fill_frames := 5;
4140 } else {
4141 f_rsl_chan_deact();
4142 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004144 }
4145
4146 f_rsl_chan_deact();
4147 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004148
4149 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004150 setverdict(pass);
4151 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004152 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4153 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004155 }
4156 } else {
4157 repeat;
4158 }
4159 }
4160 }
4161 [] L1CTL.receive { repeat; }
4162 [] T.timeout {
4163 f_rsl_chan_deact();
4164 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004166 }
4167 }
4168}
4169
4170function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4171 f_test_l2_fill_frames(false);
4172}
4173
4174function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4175 f_test_l2_fill_frames(true);
4176}
4177
4178function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4179 var ConnHdlr vc_conn;
4180 var ConnHdlrPars pars;
4181 pars.t_guard := 60.0;
4182 f_init(testcasename());
4183 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4184 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4185 if (dtxd) {
4186 if (i >= 4) { /* DTX is only allowed on TCH/F */
4187 break;
4188 }
4189 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4190 } else {
4191 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4192 }
4193 vc_conn.done;
4194 }
4195}
4196
4197/* Verify that L2 fill frames are sent on TCH in signaling mode if
4198 * there is nothing to transmit while DTX is disabled on downlink. */
4199testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4200 f_tch_sign_l2_fill_frame(false);
4201}
4202
4203/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4204 * there is nothing to transmit while DTX is enabled on downlink. */
4205testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4206 f_tch_sign_l2_fill_frame(true);
4207}
Harald Welte0472ab42018-03-12 15:02:26 +01004208
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004209testcase TC_chopped_ipa_ping() runs on test_CT {
4210 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4211}
4212
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004213testcase TC_chopped_ipa_payload() runs on test_CT {
4214 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4215}
4216
Harald Welte0472ab42018-03-12 15:02:26 +01004217/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4218/* protocol error as per 44.006 */
4219/* link layer failure (repetition of I-frame N200 times without ACK */
4220/* repetition of SABM or DISC N200 times without ACK */
4221/* receptiom of SABM in multi-frame established state */
4222
4223
4224
4225
Harald Welte883340c2018-02-28 18:59:29 +01004226
Harald Welte68e495b2018-02-25 00:05:57 +01004227/* TODO Areas:
4228
4229* channel activation
4230** with BS_Power / MS_Power, bypassing power control loop
4231** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004232** with timing advance from initial activation on
4233* mode modify
4234** encryption
4235** multirate
4236* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01004237** unsupported algorithm
4238* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01004239* BS Power Control
4240* Physical Context
Harald Welte43c54642018-09-15 17:47:04 +03004241* CCCH Load Indication for RACH
Harald Welte68e495b2018-02-25 00:05:57 +01004242* SMS Broadcast Req / Cmd / CBCH LOad Ind
4243* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01004244* error handling
Harald Welte43c54642018-09-15 17:47:04 +03004245** discriminator error
Harald Welte68e495b2018-02-25 00:05:57 +01004246** type error
4247** sequence error
4248** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01004249* PCU interface
4250** TIME_IND from BTS->PCU
4251** DATA_IND from BTS->PCU
4252** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01004253
4254*/
Harald Welte70767382018-02-21 12:16:40 +01004255
4256control {
4257 execute( TC_chan_act_stress() );
4258 execute( TC_chan_act_react() );
4259 execute( TC_chan_deact_not_active() );
4260 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01004261 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01004262 execute( TC_sacch_filling() );
4263 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01004264 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01004265 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01004266 execute( TC_rach_content() );
4267 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01004268 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01004269 execute( TC_meas_res_sign_tchf() );
4270 execute( TC_meas_res_sign_tchh() );
4271 execute( TC_meas_res_sign_sdcch4() );
4272 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01004273 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01004274 execute( TC_rsl_ms_pwr_ctrl() );
Harald Welte70767382018-02-21 12:16:40 +01004275 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01004276 execute( TC_paging_imsi_80percent() );
4277 execute( TC_paging_tmsi_80percent() );
4278 execute( TC_paging_imsi_200percent() );
4279 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01004280 execute( TC_rsl_protocol_error() );
4281 execute( TC_rsl_mand_ie_error() );
4282 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01004283 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01004284 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01004285 execute( TC_si_sched_2bis() );
4286 execute( TC_si_sched_2ter() );
4287 execute( TC_si_sched_2ter_2bis() );
4288 execute( TC_si_sched_2quater() );
4289 execute( TC_si_sched_13() );
4290 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01004291 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01004292 execute( TC_ipa_crcx_twice_not_active() );
4293 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01004294 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01004295 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01004296
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01004297 if (mp_pcu_socket != "") {
4298 execute( TC_pcu_act_req() );
4299 execute( TC_pcu_act_req_wrong_ts() );
4300 execute( TC_pcu_act_req_wrong_bts() );
4301 execute( TC_pcu_act_req_wrong_trx() );
4302 execute( TC_pcu_deact_req() );
4303 execute( TC_pcu_deact_req_wrong_ts() );
4304 execute( TC_pcu_ver_si13() );
4305 execute( TC_pcu_data_req_wrong_bts() );
4306 execute( TC_pcu_data_req_wrong_trx() );
4307 execute( TC_pcu_data_req_wrong_ts() );
4308 execute( TC_pcu_data_req_ts_inactive() );
4309 execute( TC_pcu_data_req_pdtch() );
4310 execute( TC_pcu_data_req_ptcch() );
4311 execute( TC_pcu_data_req_agch() );
4312 execute( TC_pcu_data_req_imm_ass_pch() );
4313 execute( TC_pcu_rach_content() );
4314 execute( TC_pcu_paging_from_rsl() );
4315 } else {
4316 log("PCU socket path not available, skipping PCU tests");
4317 }
Harald Welte3d04ae62018-04-04 20:29:05 +02004318
4319 execute( TC_dyn_osmo_pdch_act_deact() );
4320 execute( TC_dyn_osmo_pdch_unsol_deact() );
4321 execute( TC_dyn_osmo_pdch_double_act() );
4322 execute( TC_dyn_osmo_pdch_tchf_act() );
4323 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02004324 execute( TC_dyn_ipa_pdch_act_deact() );
4325 execute( TC_dyn_ipa_pdch_tchf_act() );
4326 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
4327 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01004328
4329 execute( TC_rll_est_ind() );
4330 execute( TC_rll_est_req_DCCH_3() );
4331 execute( TC_rll_est_req_ACCH_3() );
4332 execute( TC_rll_rel_ind_DCCH_0() );
4333 execute( TC_rll_rel_ind_DCCH_3() );
4334 execute( TC_rll_rel_ind_ACCH_0() );
4335 execute( TC_rll_rel_ind_ACCH_3() );
4336 execute( TC_rll_rel_req() );
4337 execute( TC_rll_unit_data_req_DCCH() );
4338 execute( TC_rll_unit_data_req_ACCH() );
4339 execute( TC_rll_unit_data_ind_DCCH() );
4340 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02004341
4342 execute( TC_chan_act_a51() );
4343 execute( TC_chan_act_a52() );
4344 execute( TC_chan_act_a53() );
4345 execute( TC_encr_cmd_a51() );
4346 execute( TC_encr_cmd_a52() );
4347 execute( TC_encr_cmd_a53() );
4348
4349 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02004350
4351 execute( TC_tch_sign_l2_fill_frame() );
4352 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004353
4354 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004355 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01004356}
4357
4358
4359}