blob: 64c251047568c8f17633e7410f83386086b3ff48 [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;
Harald Weltea4d8f352018-03-01 15:47:20 +010053 charstring mp_bb_trxc_ip := "127.0.0.1";
Harald Welteef3e1c92018-02-28 23:40:14 +010054 integer mp_bb_trxc_port := 6701;
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;
Harald Welte70767382018-02-21 12:16:40 +010066}
67
Harald Welte629cc6b2018-03-11 17:19:05 +010068type record of RslChannelNr ChannelNrs;
69
Harald Welte70767382018-02-21 12:16:40 +010070type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010071 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010072 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010073 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010074 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010075 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010076 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010077
78 /* L1CTL port (for classic tests) */
79 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010080
Harald Welte54a2a2d2018-02-26 09:14:05 +010081 /* TRXC port (for classic tests) */
82 port TRXC_CODEC_PT BB_TRXC;
83 var integer g_bb_trxc_conn_id;
84
Harald Weltef50e3ae2018-09-10 10:27:56 +020085 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010086 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +020087 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +010088
Harald Welte883340c2018-02-28 18:59:29 +010089 /* PCU Interface of BTS */
90 port PCUIF_CODEC_PT PCU;
91 var integer g_pcu_conn_id;
92 /* Last PCU INFO IND we received */
93 var PCUIF_Message g_pcu_last_info;
94
Harald Welte48494ca2018-02-25 16:59:50 +010095 /* SI configuration */
96 var SystemInformationConfig si_cfg := {
97 bcch_extended := false,
98 si1_present := false,
99 si2bis_present := false,
100 si2ter_present := false,
101 si2quater_present := false,
102 si7_present := false,
103 si8_present := false,
104 si9_present := false,
105 si13_present := false,
106 si13alt_present := false,
107 si15_present := false,
108 si16_present := false,
109 si17_present := false,
110 si2n_present := false,
111 si21_present := false,
112 si22_present := false
113 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100114
115 /* all logical channels available on the BTS */
116 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100117 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100118}
119
120/* an individual call / channel */
121type component ConnHdlr extends RSL_DchanHdlr {
122 port L1CTL_PT L1CTL;
123
124 port TRXC_CODEC_PT BB_TRXC;
125 var integer g_bb_trxc_conn_id;
126
127 timer g_Tguard;
128 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
129
130 var ConnHdlrPars g_pars;
131 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100132 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200133
134 /* PCU Interface of BTS */
135 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100136}
137
138function f_init_rsl(charstring id) runs on test_CT {
139 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
140 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
141
142 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
143 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
144 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
145
146 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
147 vc_RSL.start(RSL_Emulation.main(false));
148}
149
150type record ConnHdlrPars {
151 RslChannelNr chan_nr,
152 RSL_IE_ChannelMode chan_mode,
153 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100154 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200155 TestSpecUnion spec optional,
156 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100157}
158
159/* Test-specific parameters */
160type union TestSpecUnion {
161 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100162}
163
Harald Welte82ccef72018-02-25 16:17:33 +0100164template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100165 max_retrans := RACH_MAX_RETRANS_7,
166 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100167 cell_barr_access := false,
168 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100169 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100170};
171
Harald Weltef10153f2018-02-25 16:34:05 +0100172template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100173 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200174 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100175 acs := '0'B,
176 neci := true,
177 rxlev_access_min := 0
178}
179
180template (value) LocationAreaIdentification ts_LAI_default := {
181 mcc_mnc := '262F42'H,
182 lac := 42
183}
184
Harald Welte7484fc42018-02-24 14:09:45 +0100185/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100186template (value) SystemInformation ts_SI3_default := {
187 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100188 payload := {
189 si3 := {
190 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100191 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100192 ctrl_chan_desc := {
193 msc_r99 := true,
194 att := true,
195 bs_ag_blks_res := 1,
196 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100197 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100198 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
199 spare := '00'B,
200 bs_pa_mfrms := 0, /* 2 multiframes */
201 t3212 := 1 /* 6 minutes */
202 },
Harald Welte82ccef72018-02-25 16:17:33 +0100203 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100204 dn_ind := false,
205 pwrc := false,
206 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100207 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100208 },
Harald Weltef10153f2018-02-25 16:34:05 +0100209 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100210 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100211 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100212 }
213 }
214}
Harald Welte70767382018-02-21 12:16:40 +0100215
Harald Weltef8df4cb2018-03-10 15:15:08 +0100216template (value) SystemInformation ts_SI2_default := {
217 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100218 payload := {
219 si2 := {
220 bcch_freq_list := '00000000000000000000000000000000'O,
221 ncc_permitted := '11111111'B,
222 rach_control := ts_RachCtrl_default
223 }
224 }
225}
226
Harald Weltef8df4cb2018-03-10 15:15:08 +0100227template (value) SystemInformation ts_SI4_default := {
228 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100229 payload := {
230 si4 := {
231 lai := ts_LAI_default,
232 cell_sel_par := ts_CellSelPar_default,
233 rach_control := ts_RachCtrl_default,
234 cbch_chan_desc := omit,
235 cbch_mobile_alloc := omit,
236 rest_octets := ''O
237 }
238 }
239}
240
241function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
242runs on test_CT {
243 log("Setting ", rsl_si_type, ": ", si_enc);
244 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
245}
246
247function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
248runs on test_CT {
249 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
250 log("Setting ", rsl_si_type, ": ", si_dec);
251 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
252}
253
Harald Welte8da48242018-02-27 20:41:32 +0100254private function f_init_vty(charstring id) runs on test_CT {
255 map(self:BTSVTY, system:BTSVTY);
256 f_vty_set_prompts(BTSVTY);
257 f_vty_transceive(BTSVTY, "enable");
258}
259
Harald Weltef50e3ae2018-09-10 10:27:56 +0200260private function f_init_vty_bsc() runs on test_CT {
261 map(self:BSCVTY, system:BSCVTY);
262 f_vty_set_prompts(BSCVTY, "OsmoBSC");
263 f_vty_transceive(BSCVTY, "enable");
264}
265
Harald Welte883340c2018-02-28 18:59:29 +0100266/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200267private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
268 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100269 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200270 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
271 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100272 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200273 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100275 }
276}
277
Harald Weltef26de0b2018-04-04 20:28:05 +0200278private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
279 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100280 timer T := 2.0;
281 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100282 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200283 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100284 return;
285 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200286 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100287
288 T.start;
289 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200290 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100291 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100293 }
294 }
295}
296
Harald Welte70767382018-02-21 12:16:40 +0100297/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100298function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte83f6dbf2018-06-03 18:26:50 +0200299 timer T := 10.0;
Harald Welte629cc6b2018-03-11 17:19:05 +0100300 g_AllChannels := {
301 /* TS 1..4: TCH/F */
302 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
303 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
304 /* TS 5: TCH/H */
305 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
306 /* TS 0: SDCCH/4 */
307 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
308 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
309 /* TS 6: SDCCH/8 */
310 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
311 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
312 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
313 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
314 };
315
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200316 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
317 if (mp_bb_trxc_port != -1) {
318 g_AllChanTypes := {
319 /* TS 1..4: TCH/F */
320 valueof(ts_RslChanNr_Bm(1)),
321 /* TS 5: TCH/H */
322 valueof(ts_RslChanNr_Lm(5,1)),
323 /* TS 0: SDCCH/4 */
324 valueof(ts_RslChanNr_SDCCH4(0,2)),
325 /* TS 6: SDCCH/8 */
326 valueof(ts_RslChanNr_SDCCH8(6,4))
327 };
328 } else {
329 g_AllChanTypes := {
330 /* TS 1..4: TCH/F */
331 valueof(ts_RslChanNr_Bm(1)),
332 /* TS 0: SDCCH/4 */
333 valueof(ts_RslChanNr_SDCCH4(0,2)),
334 /* TS 6: SDCCH/8 */
335 valueof(ts_RslChanNr_SDCCH8(6,4))
336 };
337 }
Harald Welte70767382018-02-21 12:16:40 +0100338 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200339 T.start;
340 alt {
341 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
342 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200344 }
345 }
Harald Welte2d142592018-02-25 13:19:44 +0100346 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100347 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200348 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100349
350 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100351 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
352 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
353 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
354 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100355
Harald Weltef26de0b2018-04-04 20:28:05 +0200356 map(self:PCU, system:PCU);
357 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100358
Harald Welte84271622018-03-10 17:21:03 +0100359 if (mp_bb_trxc_port != -1) {
360 var TrxcMessage ret;
361 /* start with a default moderate timing offset equalling TA=2 */
362 f_main_trxc_connect();
363 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
364 }
Harald Welte70767382018-02-21 12:16:40 +0100365}
366
Harald Welte68e495b2018-02-25 00:05:57 +0100367/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
368function f_init_l1ctl() runs on test_CT {
369 map(self:L1CTL, system:L1CTL);
370 f_connect_reset(L1CTL);
371}
372
Harald Welte70767382018-02-21 12:16:40 +0100373type function void_fn(charstring id) runs on ConnHdlr;
374
375/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200376function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100377runs on test_CT return ConnHdlr {
378 var charstring id := testcasename();
379 var ConnHdlr vc_conn;
380
381 vc_conn := ConnHdlr.create(id);
382 /* connect to RSL Emulation main component */
383 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
384 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200385 if (pcu_comp) {
386 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
387 * it from the test_CT and connect it to the component. This obviously only
388 * works for one component, i.e. no concurrency */
389 unmap(self:PCU, system:PCU);
390 map(vc_conn:PCU, system:PCU);
391 }
Harald Welte70767382018-02-21 12:16:40 +0100392
393 vc_conn.start(f_handler_init(fn, id, pars));
394 return vc_conn;
395}
396
Harald Welte7484fc42018-02-24 14:09:45 +0100397template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
398 streamId := sid,
399 rsl := rsl
400}
401
402template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
403 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
404 streamId := sid,
405 rsl := rsl
406}
407
Harald Welte70767382018-02-21 12:16:40 +0100408private altstep as_Tguard() runs on ConnHdlr {
409 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100411 }
412}
413
Harald Welte68e495b2018-02-25 00:05:57 +0100414private function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200415 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100416}
417
418private function f_trxc_connect() runs on ConnHdlr {
419 map(self:BB_TRXC, system:BB_TRXC);
420 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100421 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
422 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200423 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 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 +0200425 }
Harald Welte70767382018-02-21 12:16:40 +0100426 g_bb_trxc_conn_id := res.connId;
427}
428
429private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100430 var TrxcMessage ret;
431 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100432}
433
434private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100435 var TrxcMessage ret;
436 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100437}
438
439/* first function started in ConnHdlr component */
440private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
441runs on ConnHdlr {
442 g_pars := pars;
443 g_chan_nr := pars.chan_nr;
444
445 map(self:L1CTL, system:L1CTL);
446 f_connect_reset(L1CTL);
447
Harald Welte84271622018-03-10 17:21:03 +0100448 if (mp_bb_trxc_port != -1) {
449 f_trxc_connect();
450 }
Harald Welte70767382018-02-21 12:16:40 +0100451
452 g_Tguard.start(pars.t_guard);
453 activate(as_Tguard());
454
455 f_rslem_register(0, pars.chan_nr);
456
457 /* call the user-supplied test case function */
458 fn.apply(id);
459}
460
Harald Welteb1726c92018-03-30 11:56:38 +0200461function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
462 boolean ignore_other := false)
463runs on ConnHdlr return RSL_Message {
464 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100465 timer T := 3.0;
466 RSL.send(tx);
467 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100468 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200469 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100470 T.stop;
471 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100472 }
Harald Welte1eba3742018-02-25 12:48:14 +0100473 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100475 }
Harald Welte21240e62018-03-11 21:43:35 +0100476 [not ignore_other] as_l1_sacch();
477 [not ignore_other] as_meas_res();
478 [not ignore_other] as_l1_dcch();
479 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100481 }
Harald Welte21240e62018-03-11 21:43:35 +0100482 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100483 }
Harald Welteb1726c92018-03-30 11:56:38 +0200484 return rx;
485}
486
487function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
488 boolean ignore_other := false)
489runs on ConnHdlr {
490 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100491}
492
Harald Weltee613f962018-04-18 22:38:16 +0200493function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false)
494runs on ConnHdlr {
495 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
496 if (encr_enable) {
497 /* append encryption related IEs, if requested */
498 var RSL_IE_EncryptionInfo encr_info;
499 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
500 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
501encr_info})) };
502 }
503 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100504}
505
Harald Welte70767382018-02-21 12:16:40 +0100506function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100507 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 +0100508 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100509}
510
Harald Welte70767382018-02-21 12:16:40 +0100511private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
512 template RSL_IE_ChannelMode chan_mode,
513 float t_guard := 20.0) := {
514 chan_nr := valueof(chan_nr),
515 chan_mode := valueof(chan_mode),
516 t_guard := t_guard,
517 l1_pars := {
518 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100519 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100520 meas_ul := {
521 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200522 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100523 rxqual := 0
524 },
525 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200526 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100527 rxqual := 0
528 }
529 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200530 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100531 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200532 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200533 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100534 },
Harald Weltee613f962018-04-18 22:38:16 +0200535 spec := omit,
536 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100537}
538
Harald Welte93640c62018-02-25 16:59:33 +0100539/***********************************************************************
540 * Channel Activation / Deactivation
541 ***********************************************************************/
542
Harald Welte70767382018-02-21 12:16:40 +0100543/* Stress test: Do 500 channel activations/deactivations in rapid succession */
544function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
545 for (var integer i := 0; i < 500; i := i+1) {
546 f_rsl_chan_act(g_pars.chan_mode);
547 f_rsl_chan_deact();
548 }
549 setverdict(pass);
550}
551testcase TC_chan_act_stress() runs on test_CT {
552 var ConnHdlr vc_conn;
553 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
554 f_init(testcasename());
555 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
556 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100558}
559
560/* Test if re-activation of an already active channel fails as expected */
561function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
562 f_rsl_chan_act(g_pars.chan_mode);
563 /* attempt to activate the same lchan again -> expect reject */
564 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
565 alt {
566 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100568 }
569 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
570 setverdict(pass);
571 }
572 }
573 f_rsl_chan_deact();
574}
575testcase TC_chan_act_react() runs on test_CT {
576 var ConnHdlr vc_conn;
577 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100578 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100579 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
580 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100582}
583
584/* Attempt to de-activate a channel that's not active */
585function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
586 timer T := 3.0;
587 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
588 T.start;
589 alt {
590 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
591 setverdict(pass);
592 }
593 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100595 }
596 }
597}
598testcase TC_chan_deact_not_active() runs on test_CT {
599 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100600 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100601 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
602 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100604}
605
606/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
607function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
608 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
609 alt {
610 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100612 }
613 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
614 setverdict(pass);
615 }
616 }
617}
618private type record WrongChanNrCase {
619 RslChannelNr chan_nr,
620 charstring description
621}
622private type record of WrongChanNrCase WrongChanNrCases;
623private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
624 chan_nr := chan_nr,
625 description := desc
626}
627
628testcase TC_chan_act_wrong_nr() runs on test_CT {
629 var ConnHdlr vc_conn;
630 var ConnHdlrPars pars;
631
Harald Welte294b0a22018-03-10 23:26:48 +0100632 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100633
634 var WrongChanNrCases wrong := {
635 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
636 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
637 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
638 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
639 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
640 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
641 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
642 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
643 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
644 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
645 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
646 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
647 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
648 };
649
650 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
651 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
652 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
653 vc_conn.done;
654 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100656}
657
Harald Weltee613f962018-04-18 22:38:16 +0200658/* execute the same callback function on a variety of logical channels */
659private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
660 var ConnHdlr vc_conn;
661 f_init(testcasename());
662
663 /* test on each of the channels we have */
664 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
665 pars.chan_nr := valueof(g_AllChanTypes[i]);
666
667 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
668 vc_conn := f_start_handler(fn, pars);
669 vc_conn.done;
670 }
671
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200673}
674
Harald Welte93640c62018-02-25 16:59:33 +0100675/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100676 * SACCH handling
677 ***********************************************************************/
678
679private function f_exp_sacch(boolean exp) runs on ConnHdlr {
680 timer T_sacch := 3.0;
681 T_sacch.start;
682 alt {
683 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100685 }
686 [not exp] T_sacch.timeout {
687 setverdict(pass);
688 }
689 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
690 setverdict(pass);
691 }
692 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100694 }
695 [] L1CTL.receive { repeat; }
696 [] RSL.receive { repeat; }
697 }
698}
699
700/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
701private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
702 f_l1_tune(L1CTL);
703 RSL.clear;
704
705 /* activate the logical channel */
706 f_est_dchan();
707 L1CTL.clear;
708
709 /* check that SACCH actually are received as expected */
710 f_exp_sacch(true);
711
712 /* deactivate SACCH on the logical channel */
713 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
714 f_sleep(1.0);
715 L1CTL.clear;
716
717 /* check that no SACCH are received anymore */
718 f_exp_sacch(false);
719
720 /* release the channel */
721 f_rsl_chan_deact();
722 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
723}
724testcase TC_deact_sacch() runs on test_CT {
725 var ConnHdlr vc_conn;
726 var ConnHdlrPars pars;
727 f_init();
728 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
729 //for (var integer i := 0; i < 1; i := i+1) {
730 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
731 log(testcasename(), ": Starting for ", g_AllChannels[i]);
732 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
733 vc_conn.done;
734 }
735 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100737}
738
Harald Welte55700662018-03-12 13:15:43 +0100739/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100740private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
741 var L1ctlDlMessage dl;
742 /* check that the specified SI5 value is actually sent */
743 timer T_sacch := 3.0;
744 L1CTL.clear;
745 T_sacch.start;
746 alt {
747 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
748 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
749 if (match(l3, l3_exp)) {
750 setverdict(pass);
751 } else {
752 repeat;
753 }
754 }
755 [] L1CTL.receive { repeat; }
756 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100758 }
759 }
760}
761
Harald Welte55700662018-03-12 13:15:43 +0100762/* verify that given SACCH payload is not present */
763private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
764 var L1ctlDlMessage dl;
765 /* check that the specified SI5 value is actually sent */
766 timer T_sacch := 3.0;
767 L1CTL.clear;
768 T_sacch.start;
769 alt {
770 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
771 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
772 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100774 } else {
775 repeat;
776 }
777 }
778 [] L1CTL.receive { repeat; }
779 [] T_sacch.timeout {
780 setverdict(pass);
781 }
782 }
783}
784
Harald Welte629cc6b2018-03-11 17:19:05 +0100785/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100786private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
787 /* Set a known default SACCH filling for SI5 */
788 var octetstring si5 := f_rnd_octstring(19);
789 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
790
791 f_l1_tune(L1CTL);
792 RSL.clear;
793
794 /* activate the logical channel */
795 f_est_dchan();
796
797 /* check that the specified SI5 value is actually sent */
798 f_sacch_present(si5);
799
800 /* release the channel */
801 RSL.clear;
802 f_rsl_chan_deact();
803 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
804}
805testcase TC_sacch_filling() runs on test_CT {
806 var ConnHdlr vc_conn;
807 var ConnHdlrPars pars;
808 f_init();
809 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
810 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
811 log(testcasename(), ": Starting for ", g_AllChannels[i]);
812 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
813 vc_conn.done;
814 }
815 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100817}
818
Harald Welte629cc6b2018-03-11 17:19:05 +0100819/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100820private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
821 /* Set a known default SACCH filling for SI5 */
822 var octetstring si5 := f_rnd_octstring(19);
823 var octetstring si5_diff := f_rnd_octstring(19);
824 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
825
826 f_l1_tune(L1CTL);
827 RSL.clear;
828
829 log("Activating channel, expecting standard SI5");
830 /* activate the logical channel */
831 f_est_dchan();
832 /* check that the specified SI5 value is actually sent */
833 f_sacch_present(si5);
834
835 /* set channel-specific different SI5 */
836 log("Setting channel specific SACCH INFO, expecting it");
837 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
838 /* check that the specified lchan-specific value is now used */
839 f_sacch_present(si5_diff);
840
841 /* deactivate the channel and re-activate it, this should result in default SI5 */
842 log("De-activating and re-activating channel, expecting standard SI5");
843 f_rsl_chan_deact();
844 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
845 /* Verify that the TRX-wide default SACCH filling is present again */
846 f_sacch_present(si5);
847
848 /* release the channel */
849 RSL.clear;
850 f_rsl_chan_deact();
851 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
852}
853testcase TC_sacch_info_mod() runs on test_CT {
854 var ConnHdlr vc_conn;
855 var ConnHdlrPars pars;
856 f_init();
857 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
858 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
859 log(testcasename(), ": Starting for ", g_AllChannels[i]);
860 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
861 vc_conn.done;
862 }
863 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100865}
866
Harald Welte075d84c2018-03-12 13:07:24 +0100867/* Test SACCH scheduling of multiple different SI message types */
868private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
869 var octetstring si5 := f_rnd_octstring(19);
870 var octetstring si5bis := f_rnd_octstring(19);
871 var octetstring si5ter := f_rnd_octstring(19);
872 var octetstring si6 := f_rnd_octstring(19);
873
874 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
875 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
876 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
877 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
878
879 f_l1_tune(L1CTL);
880 RSL.clear;
881
882 /* activate the logical channel */
883 f_est_dchan();
884 L1CTL.clear;
885
886 /* check that SACCH actually are received as expected */
887 f_sacch_present(si5);
888 f_sacch_present(si5bis);
889 f_sacch_present(si5ter);
890 f_sacch_present(si6);
891
892 /* release the channel */
893 f_rsl_chan_deact();
894 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
895}
896testcase TC_sacch_multi() runs on test_CT {
897 var ConnHdlr vc_conn;
898 var ConnHdlrPars pars;
899 f_init();
900 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
901 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
902 log(testcasename(), ": Starting for ", g_AllChannels[i]);
903 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
904 vc_conn.done;
905 }
906 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100908}
909
Harald Welte55700662018-03-12 13:15:43 +0100910/* Test if SACH information is modified as expected */
911private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
912 var octetstring si5 := f_rnd_octstring(19);
913 var octetstring si6 := f_rnd_octstring(19);
914
915 /* First, configure both SI5 and SI6 to be transmitted */
916 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
917 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
918
919 f_l1_tune(L1CTL);
920 RSL.clear;
921
922 /* activate the logical channel */
923 f_est_dchan();
924 L1CTL.clear;
925
926 /* check that SACCH actually are received as expected */
927 f_sacch_present(si5);
928 f_sacch_present(si6);
929
930 /* disable SI6 */
931 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
932
933 /* check that SI5 is still transmitted */
934 f_sacch_present(si5);
935 /* check if SI6 is now gone */
936 f_sacch_missing(si6);
937
938 /* release the channel */
939 f_rsl_chan_deact();
940 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
941}
942testcase TC_sacch_multi_chg() runs on test_CT {
943 var ConnHdlr vc_conn;
944 var ConnHdlrPars pars;
945 f_init();
946 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
947 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
948 log(testcasename(), ": Starting for ", g_AllChannels[i]);
949 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
950 vc_conn.done;
951 }
952 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100954}
955
Harald Welte075d84c2018-03-12 13:07:24 +0100956/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
957/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100958
959
960/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100961 * RACH Handling
962 ***********************************************************************/
963
Harald Welte8c24c2b2018-02-26 08:31:31 +0100964/* like L1SAP_IS_PACKET_RACH */
965private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100966 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100967 return true;
968 }
969 return false;
970}
971
972/* generate a random RACH for circuit-switched */
973private function f_rnd_ra_cs() return OCT1 {
974 var OCT1 ra;
975 do {
976 ra := f_rnd_octstring(1);
977 } while (ra_is_ps(ra));
978 return ra;
979}
980
Harald Welte883340c2018-02-28 18:59:29 +0100981/* generate a random RACH for packet-switched */
982private function f_rnd_ra_ps() return OCT1 {
983 var OCT1 ra;
984 do {
985 ra := f_rnd_octstring(1);
986 } while (not ra_is_ps(ra));
987 return ra;
988}
989
Harald Welte8c24c2b2018-02-26 08:31:31 +0100990/* Send 1000 RACH requests and check their RA+FN on the RSL side */
991testcase TC_rach_content() runs on test_CT {
992 f_init(testcasename());
993 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100994 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100995
Harald Welte8c24c2b2018-02-26 08:31:31 +0100996 var GsmFrameNumber fn_last := 0;
997 for (var integer i := 0; i < 1000; i := i+1) {
998 var OCT1 ra := f_rnd_ra_cs();
999 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1000 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001002 }
1003 fn_last := fn;
1004
1005 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001006 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001007 alt {
1008 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1009 T.stop;
1010 }
1011 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001013 }
1014 [] RSL_CCHAN.receive { repeat; }
1015 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001017 }
1018 }
1019 }
1020 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001022}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001023
1024/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1025testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001026 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001027 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001028 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001029 f_l1_tune(L1CTL);
1030
1031 var GsmFrameNumber fn_last := 0;
1032 for (var integer i := 0; i < 1000; i := i+1) {
1033 var OCT1 ra := f_rnd_ra_cs();
1034 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1035 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001037 }
1038 fn_last := fn;
1039 }
1040 var integer rsl_chrqd := 0;
1041 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001042 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001043 alt {
1044 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1045 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001046 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001047 repeat;
1048 }
1049 [] RSL_CCHAN.receive { repeat; }
1050 [] T.timeout { }
1051 }
1052 if (rsl_chrqd == 1000) {
1053 setverdict(pass);
1054 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001056 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001057 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001058}
1059
Harald Welte54a2a2d2018-02-26 09:14:05 +01001060private function f_main_trxc_connect() runs on test_CT {
1061 map(self:BB_TRXC, system:BB_TRXC);
1062 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +01001063 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
1064 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001065 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001066 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 +02001067 }
Harald Welte54a2a2d2018-02-26 09:14:05 +01001068 g_bb_trxc_conn_id := res.connId;
1069}
1070
1071private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001072 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001073 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +01001074 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001075 f_sleep(0.5);
1076
1077 /* Transmit RACH request + wait for confirmation */
1078 var OCT1 ra := f_rnd_ra_cs();
1079 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1080
1081 /* Check for expected result */
1082 timer T := 1.5;
1083 T.start;
1084 alt {
1085 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1086 setverdict(pass);
1087 }
1088 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001090 }
1091 [] RSL_CCHAN.receive { repeat; }
1092 [not expect_pass] T.timeout {
1093 setverdict(pass);
1094 }
1095 [expect_pass] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for CHAN RQD");
Harald Welte54a2a2d2018-02-26 09:14:05 +01001097 }
1098 }
1099}
1100
1101/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1102testcase TC_rach_max_ta() runs on test_CT {
1103 f_init(testcasename());
1104 f_init_l1ctl();
1105 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001106 f_sleep(1.0);
1107
1108 /* default max-ta is 63 (full range of GSM timing advance */
1109
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001110 /* We allow early arrival up to 2 symbols */
1111 f_rach_toffs(-1*256, true);
1112 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001113 f_rach_toffs(-10*256, false);
1114
1115 /* 0 / 32 / 63 bits is legal / permitted */
1116 f_rach_toffs(0, true);
1117 f_rach_toffs(32*256, true);
1118 f_rach_toffs(63*256, true);
1119
1120 /* more than 63 bits is not legal / permitted */
1121 f_rach_toffs(64*256, false);
1122 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001124}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001125
Harald Welte93640c62018-02-25 16:59:33 +01001126/***********************************************************************
1127 * Measurement Processing / Reporting
1128 ***********************************************************************/
1129
Harald Welte70767382018-02-21 12:16:40 +01001130template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1131 spare := '0'B,
1132 lpd := 0,
1133 sapi := sapi,
1134 c_r := c_r,
1135 ea := true
1136}
1137
Harald Welted879bd92018-03-12 15:01:23 +01001138template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001139 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001140 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001141 len := 0, /* overwritten */
1142 m := false,
1143 el := 1,
1144 payload := pl
1145}
1146
1147/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1148altstep as_l1_sacch() runs on ConnHdlr {
1149 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001150 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001151 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001152 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 +01001153 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001154 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001155
1156 var L1ctlDataReq data_req := {
1157 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1158 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1159 }
1160 log("Sending Measurement Report: ", data_req);
1161 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001162 repeat;
1163 }
1164}
1165
1166altstep as_l1_dcch() runs on ConnHdlr {
1167 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001168 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001169 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1170 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001171 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1172 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001173 repeat;
1174 }
1175}
1176
1177type record MeasElem {
1178 uint6_t rxlev,
1179 uint3_t rxqual
1180}
1181
1182type record MeasElemFS {
1183 MeasElem full,
1184 MeasElem sub
1185}
1186
1187type record ConnL1Pars {
1188 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001189 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001190 MeasElemFS meas_ul,
1191 int16_t timing_offset_256syms,
1192 uint5_t bs_power_level,
1193 uint5_t ms_power_level,
1194 uint8_t ms_actual_ta
1195}
1196
1197/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1198private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1199 return 63 + (toffs256s/256);
1200}
1201
Harald Welted5684392018-03-10 18:22:04 +01001202private function f_max(integer a, integer b) return integer {
1203 if (a > b) {
1204 return a;
1205 } else {
1206 return b;
1207 }
1208}
1209
1210private function f_min(integer a, integer b) return integer {
1211 if (a < b) {
1212 return a;
1213 } else {
1214 return b;
1215 }
1216}
1217
1218/* compute negative tolerance val-tolerance, ensure >= min */
1219private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1220 val := val - tolerance;
1221 return f_max(val, min);
1222}
1223
1224/* compute positive tolerance val+tolerance, ensure <= max */
1225private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1226 val := val + tolerance;
1227 return f_min(val, max);
1228}
1229
1230/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1231private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1232return template integer {
1233 var template integer ret;
1234 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1235 return ret;
1236}
1237
1238
Harald Welte70767382018-02-21 12:16:40 +01001239/* build a template for matching measurement results against */
1240private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1241 var ConnL1Pars l1p := g_pars.l1_pars;
1242 var template RSL_IE_UplinkMeas ul_meas := {
1243 len := 3,
1244 rfu := '0'B,
1245 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001246 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001247 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001248 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001249 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001250 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1251 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001252 supp_meas_info := omit
1253 };
Harald Welte685d5982018-02-27 20:42:05 +01001254 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001255 ul_meas.len := (3+8);
1256 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001257 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001258 toa256_min := ?,
1259 toa256_max := ?,
1260 toa256_std_dev := ?
1261 }
Harald Welte685d5982018-02-27 20:42:05 +01001262 }
Harald Welte70767382018-02-21 12:16:40 +01001263 var template RSL_IE_BS_Power bs_power := {
1264 reserved := 0,
1265 epc := false,
1266 fpc := false,
1267 power_level := l1p.bs_power_level
1268 };
1269 var template RSL_IE_L1Info l1_info := {
1270 ms_power_lvl := l1p.ms_power_level,
1271 fpc := false,
1272 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001273 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001274 };
1275 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001276 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001277 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1278 ?, t_toffs);
1279}
1280
1281/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001282altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001283 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001284 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001285 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1286 /* increment counter of next to-be-expected meas rep */
1287 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1288 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001289 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001290 repeat;
1291 }
1292 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001293 /* increment counter of next to-be-expected meas rep */
1294 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1295 if (g_first_meas_res) {
1296 g_first_meas_res := false;
1297 repeat;
1298 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001300 }
Harald Welte70767382018-02-21 12:16:40 +01001301 }
1302 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001304 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001305 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001307 }
1308}
1309
Harald Weltee613f962018-04-18 22:38:16 +02001310private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1311 select (rsl_alg_id) {
1312 case (RSL_ALG_ID_A5_0) { return 0; }
1313 case (RSL_ALG_ID_A5_1) { return 1; }
1314 case (RSL_ALG_ID_A5_2) { return 2; }
1315 case (RSL_ALG_ID_A5_3) { return 3; }
1316 case (RSL_ALG_ID_A5_4) { return 4; }
1317 case (RSL_ALG_ID_A5_5) { return 5; }
1318 case (RSL_ALG_ID_A5_6) { return 6; }
1319 case (RSL_ALG_ID_A5_7) { return 7; }
1320 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1322 /* Make compiler happy by calling mtc.stop here. It is already
1323 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001324 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001325 }
1326 }
1327}
1328
1329private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1330 select (rsl_alg_id) {
1331 case (RSL_ALG_ID_A5_1) { return '000'B; }
1332 case (RSL_ALG_ID_A5_2) { return '001'B; }
1333 case (RSL_ALG_ID_A5_3) { return '010'B; }
1334 case (RSL_ALG_ID_A5_4) { return '011'B; }
1335 case (RSL_ALG_ID_A5_5) { return '100'B; }
1336 case (RSL_ALG_ID_A5_6) { return '101'B; }
1337 case (RSL_ALG_ID_A5_7) { return '110'B; }
1338 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1340 /* Make compiler happy by calling mtc.stop here. It is already
1341 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001342 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001343 }
1344 }
1345}
1346
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001347/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1348private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1349 var GsmFrameNumber fn;
1350 timer T := 8.0;
1351
1352 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1353 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1354
1355 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1356 /* Send the actual RACH */
1357 fn := f_L1CTL_RACH(L1CTL, ra);
1358
1359 T.start;
1360 alt {
1361 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1362 [] T.timeout {
1363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1364 }
1365 }
1366 T.stop
1367 return fn;
1368}
Harald Weltee613f962018-04-18 22:38:16 +02001369
Harald Welte70767382018-02-21 12:16:40 +01001370/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001371private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001372 var GsmFrameNumber fn;
1373 var ImmediateAssignment imm_ass;
1374 var integer ra := 23;
1375
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001376 /* Send RACH request and wait for ChanReq */
1377 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001378
1379 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001380 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001381
1382 /* Send IMM.ASS via CCHAN */
1383 var ChannelDescription ch_desc := {
1384 chan_nr := g_pars.chan_nr,
1385 tsc := 7,
1386 h := false,
1387 arfcn := mp_trx0_arfcn,
1388 maio_hsn := omit
1389 };
1390 var MobileAllocation ma := {
1391 len := 0,
1392 ma := ''B
1393 };
1394 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1395 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1396
1397 /* receive IMM.ASS on MS side */
1398 var ImmediateAssignment ia_um;
1399 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1400 /* enable dedicated mode */
1401 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001402 /* enable encryption, if requested */
1403 if (encr_enable) {
1404 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1405 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1406 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001407
1408 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001409}
1410
1411/* establish DChan, verify existance + contents of measurement reports */
1412function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001413 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001414 RSL.clear;
1415
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001416 if (mp_bb_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001417 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001418 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1419 }
Harald Welte70767382018-02-21 12:16:40 +01001420
1421 f_est_dchan();
1422
1423 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1424 * RSL measurement reports on Abis side */
1425 timer T := 8.0;
1426 T.start;
1427 alt {
1428 [] as_l1_sacch();
1429 [] as_meas_res();
1430 [] as_l1_dcch();
1431 [] L1CTL.receive { repeat; }
1432 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001434 * of any earlier errors, so if we reach this timeout, we're good */
1435 setverdict(pass);
1436 }
1437 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001439 }
1440 }
1441 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001442 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001443}
Harald Welte0472ab42018-03-12 15:02:26 +01001444
Harald Welte70767382018-02-21 12:16:40 +01001445testcase TC_meas_res_sign_tchf() runs on test_CT {
1446 var ConnHdlr vc_conn;
1447 var ConnHdlrPars pars;
1448 f_init(testcasename());
1449 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1450 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1451 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1452 vc_conn.done;
1453 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001455}
1456testcase TC_meas_res_sign_tchh() runs on test_CT {
1457 var ConnHdlr vc_conn;
1458 var ConnHdlrPars pars;
1459 f_init(testcasename());
1460 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1461 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1462 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1463 vc_conn.done;
1464 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001466}
1467testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1468 var ConnHdlr vc_conn;
1469 var ConnHdlrPars pars;
1470 f_init(testcasename());
1471 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1472 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1473 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1474 vc_conn.done;
1475 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001477}
1478testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1479 var ConnHdlr vc_conn;
1480 var ConnHdlrPars pars;
1481 f_init(testcasename());
1482 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1483 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1484 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1485 vc_conn.done;
1486 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001488}
Harald Welte685d5982018-02-27 20:42:05 +01001489testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1490 var ConnHdlr vc_conn;
1491 var ConnHdlrPars pars;
1492 f_init(testcasename());
1493 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1494 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1495 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1496 pars.l1_pars.toa256_enabled := true;
1497 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1498 vc_conn.done;
1499 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001501}
1502
Harald Welte70767382018-02-21 12:16:40 +01001503
Harald Welte0472ab42018-03-12 15:02:26 +01001504/* 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 +01001505private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001506 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001507 RSL.clear;
1508
1509 f_est_dchan();
1510 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001511 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001512
1513 timer T := 40.0;
1514 T.start;
1515 alt {
1516 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1517 setverdict(pass)
1518 }
1519 [] RSL.receive { repeat };
1520 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001522 }
1523 }
1524 f_rsl_chan_deact();
1525}
1526testcase TC_conn_fail_crit() runs on test_CT {
1527 var ConnHdlr vc_conn;
1528 var ConnHdlrPars pars;
1529 f_init(testcasename());
1530 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1531 pars.t_guard := 60.0;
1532 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1533 vc_conn.done;
1534}
1535
Harald Welte93640c62018-02-25 16:59:33 +01001536/***********************************************************************
1537 * Paging
1538 ***********************************************************************/
1539
Harald Welte68e495b2018-02-25 00:05:57 +01001540function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1541 if (tmsi == 'FFFFFFFF'O) {
1542 return true;
1543 } else {
1544 return false;
1545 }
1546}
Harald Welte70767382018-02-21 12:16:40 +01001547
Philipp Maier82cb0b12018-08-31 14:41:39 +02001548type record allowedFn { integer frame_nr }
1549template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
1550template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
1551template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
1552template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
1553template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
1554template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
1555template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
1556template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
1557function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
1558{
1559 var integer frame_nr_51;
1560 frame_nr_51 := frame_nr mod 51
1561
1562 var allowedFn fn_check;
1563 fn_check.frame_nr := frame_nr_51;
1564
1565 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001567 return;
1568 }
1569
1570 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
1571 return;
1572 }
1573 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
1574 return;
1575 }
1576 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
1577 return;
1578 }
1579 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
1580 return;
1581 }
1582 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
1583 return;
1584 }
1585 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
1586 return;
1587 }
1588 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
1589 return;
1590 }
1591 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
1592 return;
1593 }
1594
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001596 return;
1597}
1598
1599altstep 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 +01001600runs on test_CT {
1601 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001602 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001603 repeat;
1604 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001605 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001606 var octetstring without_plen :=
1607 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1608 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02001609
1610 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
1611
Harald Welte68e495b2018-02-25 00:05:57 +01001612 if (match(rr, tr_PAGING_REQ1)) {
1613 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1614 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1615 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1616 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1617 }
1618 } else if (match(rr, tr_PAGING_REQ2)) {
1619 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1620 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1621 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1622 }
1623 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1624 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1625 }
1626 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1627 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1628 }
1629 } else if (match(rr, tr_PAGING_REQ3)) {
1630 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1631 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1632 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1633 }
1634 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1635 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1636 }
1637 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1638 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1639 }
1640 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1641 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1642 }
1643 }
1644 repeat;
1645 }
1646}
1647
1648type record PagingTestCfg {
1649 boolean combined_ccch,
1650 integer bs_ag_blks_res,
1651 float load_factor,
1652 boolean exp_load_ind,
1653 boolean exp_overload,
1654 boolean use_tmsi
1655}
1656
1657type record PagingTestState {
1658 integer num_paging_sent,
1659 integer num_paging_rcv_msgs,
1660 integer num_paging_rcv_ids,
1661 integer num_overload
1662}
1663
1664/* receive + ignore RSL RF RES IND */
1665altstep as_rsl_res_ind() runs on test_CT {
1666 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1667 repeat;
1668 }
1669}
1670
1671/* Helper function for paging related testing */
1672private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1673 f_init(testcasename());
1674 f_init_l1ctl();
1675 f_l1_tune(L1CTL);
1676
1677 var PagingTestState st := {
1678 num_paging_sent := 0,
1679 num_paging_rcv_msgs := 0,
1680 num_paging_rcv_ids := 0,
1681 num_overload := 0
1682 };
1683
1684 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1685 var float max_pch_imsi_per_sec;
1686 if (cfg.use_tmsi) {
1687 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1688 } else {
1689 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1690 }
1691 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1692 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001693 var float time_total := 20.0;
1694 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
1695 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01001696
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001697 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
1698 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01001699
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001700 timer T_itv := 0.0;
1701 T_itv.start;
1702 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01001703 alt {
1704 /* check for presence of CCCH LOAD IND (paging load) */
1705 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1706 st.num_overload := st.num_overload + 1;
1707 repeat;
1708 }
1709 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01001711 }
1712 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1713 log("Rx LOAD_IND");
1714 /* FIXME: analyze/verify interval + contents */
1715 repeat;
1716 }
1717 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02001718 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001719 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001720 [] T_itv.timeout {
1721 /* Send paging cmds based on elapsed time */
1722 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
1723 while (st.num_paging_sent < new_sent) {
1724 /* build mobile Identity */
1725 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1726 if (cfg.use_tmsi) {
1727 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1728 } else {
1729 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
1730 }
1731 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1732 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1733
1734 /* Send RSL PAGING COMMAND */
1735 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
1736
1737 st.num_paging_sent := st.num_paging_sent + 1;
1738 }
1739 if (st.num_paging_sent < pkt_total) {
1740 /* Wait for interval to next PAGING COMMAND */
1741 var float time_now := T_total.read;
1742 var float next_sched := int2float(st.num_paging_sent)*interval;
1743 if (next_sched > time_now) {
1744 T_itv.start(next_sched - time_now);
1745 } else {
1746 T_itv.start(0.0);
1747 }
1748 } else {
1749 /* We are done, no need to keep counting */
1750 T_total.stop;
1751 }
1752 }
1753 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01001754 [] as_rsl_res_ind();
1755 }
1756 }
1757
1758 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1759 timer T_wait := 18.0;
1760 T_wait.start;
1761 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02001762 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001763 [] L1CTL.receive { repeat; }
1764 /* 65535 == empty paging queue, we can terminate*/
1765 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1766 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1767 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01001769 }
1770 [] as_rsl_res_ind();
1771 }
1772
1773 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1774 " rcvd_ids=", st.num_paging_rcv_ids);
1775 return st;
1776}
1777
1778/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1779 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1780 * - that CCCH LOAD IND (PCH) are being generated
1781 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1782testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001783 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001784 var PagingTestCfg cfg := {
1785 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001786 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001787 load_factor := 0.8,
1788 exp_load_ind := true,
1789 exp_overload := false,
1790 use_tmsi := false
1791 };
1792 var PagingTestState st := f_TC_paging(cfg);
1793 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1795 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001796 } else {
1797 setverdict(pass);
1798 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001800}
1801
1802/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1803 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1804 * - that CCCH LOAD IND (PCH) are being generated
1805 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1806testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001807 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001808 var PagingTestCfg cfg := {
1809 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001810 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001811 load_factor := 0.8,
1812 exp_load_ind := true,
1813 exp_overload := false,
1814 use_tmsi := true
1815 };
1816 var PagingTestState st := f_TC_paging(cfg);
1817 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1819 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001820 } else {
1821 setverdict(pass);
1822 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001824}
1825
1826/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1827 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1828 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1829 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1830testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001831 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001832 var PagingTestCfg cfg := {
1833 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001834 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001835 load_factor := 2.0,
1836 exp_load_ind := true,
1837 exp_overload := true,
1838 use_tmsi := false
1839 };
1840 var PagingTestState st := f_TC_paging(cfg);
1841 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1842 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001843 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001844 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001845 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 +01001846 } else {
1847 setverdict(pass);
1848 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001850}
1851
1852/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1853 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1854 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1855 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1856testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001857 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001858 var PagingTestCfg cfg := {
1859 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001860 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001861 load_factor := 2.0,
1862 exp_load_ind := true,
1863 exp_overload := true,
1864 use_tmsi := true
1865 };
1866 var PagingTestState st := f_TC_paging(cfg);
1867 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1868 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001869 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001870 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001871 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 +01001872 } else {
1873 setverdict(pass);
1874 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001876}
1877
1878
Harald Welte93640c62018-02-25 16:59:33 +01001879/***********************************************************************
1880 * Immediate Assignment / AGCH
1881 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001882const MobileAllocation c_MA_null := {
1883 len := 0,
1884 ma := ''B
1885}
Harald Welte93640c62018-02-25 16:59:33 +01001886
Harald Weltee8d750e2018-06-10 21:41:35 +02001887template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1888 uint12_t arfcn := 871) := {
1889 chan_nr := chan_nr,
1890 tsc := tsc,
1891 h := false,
1892 arfcn := arfcn,
1893 maio_hsn := omit
1894}
1895
1896private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1897 return int2str(num_tx) & " sent, "
1898 & int2str(num_rx) & " received, "
1899 & int2str(num_del) & " deleted";
1900}
1901
1902private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1903 var L1ctlDlMessage l1_dl;
1904 timer T := 10.0;
1905 var integer num_tx := 0;
1906 var integer num_rx := 0;
1907 var integer num_del := 0;
1908 var charstring res_str;
1909 var float rx_ratio;
1910
Harald Welte68e495b2018-02-25 00:05:57 +01001911 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001912 f_init_l1ctl();
1913 f_l1_tune(L1CTL);
1914
1915 for (var integer i := 0; i < num_total; i := i+1) {
1916 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1917 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1918 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001919 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001920 num_tx := num_tx+1;
1921 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001922 }
1923 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02001924 T.start;
1925 alt {
1926 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
1927 num_del := num_del+1;
1928 repeat;
1929 }
1930 [] RSL_CCHAN.receive {
1931 repeat;
1932 }
1933 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
1934 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1935 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
1936 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
1937 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001938 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02001939 } else {
1940 num_rx := num_rx+1;
1941 }
1942 repeat;
1943 }
1944 [] L1CTL.receive { repeat; }
1945 [] T.timeout { }
1946 }
1947 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
1948 log("AGCH test: " & res_str);
1949 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02001951 }
1952 rx_ratio := int2float(num_rx) / int2float(num_tx);
1953 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001954 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 +02001955 } else {
1956 setverdict(pass);
1957 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001959}
1960
Harald Weltee8d750e2018-06-10 21:41:35 +02001961/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
1962testcase TC_imm_ass_1000_20ms() runs on test_CT {
1963 f_TC_imm_ass(1000, 0.02, 0.25);
1964}
1965
1966/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
1967testcase TC_imm_ass_200_0ms() runs on test_CT {
1968 f_TC_imm_ass(200, 0.0, 0.05);
1969}
1970
1971/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
1972testcase TC_imm_ass_200_76ms() runs on test_CT {
1973 f_TC_imm_ass(150, 0.076, 1.00);
1974}
1975
1976
1977
Harald Welte48494ca2018-02-25 16:59:50 +01001978/***********************************************************************
1979 * BCCH
1980 ***********************************************************************/
1981
1982/* tuple of Frame Number + decoded SI */
1983type record SystemInformationFn {
1984 GsmFrameNumber frame_number,
1985 SystemInformation si
1986}
1987
1988/* an arbitrary-length vector of decoded SI + gsmtap header */
1989type record of SystemInformationFn SystemInformationVector;
1990
1991/* an array of SI-vectors indexed by TC value */
1992type SystemInformationVector SystemInformationVectorPerTc[8];
1993
1994/* determine if a given SI vector contains given SI type at least once */
1995function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1996 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1997 var integer fn_mod51 := arr[i].frame_number mod 51;
1998 if (not bcch_ext and fn_mod51 == 2 or
1999 bcch_ext and fn_mod51 == 6) {
2000 if (arr[i].si.header.message_type == key) {
2001 return true;
2002 }
2003 }
2004 }
2005 return false;
2006}
2007
2008/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2009function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2010 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002012 }
2013}
2014
2015/* check if a given SI vector contains given SI type at least once on any TC */
2016function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2017 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2018 if (f_si_vecslot_contains(arr[tc], key) or
2019 f_si_vecslot_contains(arr[tc], key, true)) {
2020 return true;
2021 }
2022 }
2023 return false;
2024}
2025
2026/* determine if a given SI vector contains given SI type at least N of M times */
2027function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2028 var integer count := 0;
2029 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002031 }
2032 for (var integer i:= 0; i < m; i := i + 1) {
2033 var integer fn_mod51 := arr[i].frame_number mod 51;
2034 if (not bcch_ext and fn_mod51 == 2 or
2035 bcch_ext and fn_mod51 == 6) {
2036 if (arr[i].si.header.message_type == key) {
2037 count := count + 1;
2038 }
2039 }
2040 }
2041 if (count >= n) {
2042 return true;
2043 } else {
2044 return false;
2045 }
2046}
2047
2048/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2049function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2050 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002052 }
2053}
2054
2055/* determine if a given SI vector contains given SI type at least once */
2056function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2057 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2058 var integer fn_mod51 := arr[i].frame_number mod 51;
2059 if (not bcch_ext and fn_mod51 == 2 or
2060 bcch_ext and fn_mod51 == 6) {
2061 if (arr[i].si.header.message_type != key) {
2062 return false;
2063 }
2064 }
2065 }
2066 return true;
2067}
2068
2069/* ensure a given TC slot of the SI vector contains only given SI type */
2070function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2071 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002073 }
2074}
2075
2076/* SI configuration of cell, against which we validate actual SI messages */
2077type set SystemInformationConfig {
2078 boolean bcch_extended,
2079 boolean si1_present,
2080 boolean si2bis_present,
2081 boolean si2ter_present,
2082 boolean si2quater_present,
2083 boolean si7_present,
2084 boolean si8_present,
2085 boolean si9_present,
2086 boolean si13_present,
2087 boolean si13alt_present,
2088 boolean si15_present,
2089 boolean si16_present,
2090 boolean si17_present,
2091 boolean si2n_present,
2092 boolean si21_present,
2093 boolean si22_present
2094}
2095
2096/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2097function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2098 var integer i;
2099 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2100 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002102 }
2103 }
2104 if (cfg.si1_present) {
2105 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2106 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2107 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2108 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2109 /* make sure *ALL* contain SI1 */
2110 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2111 }
2112 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2113 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2114 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2115 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2116 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2117 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2118
2119 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2120 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2121 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2122 * consecutive occurrences of TC = 4. */
2123 if (cfg.si2bis_present and not cfg.si2ter_present) {
2124 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2125 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2126 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2127 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2128 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2129 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2130 }
2131
2132 if (cfg.si7_present or cfg.si8_present) {
2133 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2134 * if System Information type 4 does not contain all information needed for cell
2135 * selection and reselection. */
2136 if (not cfg.bcch_extended) {
2137 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2138 }
2139 if (cfg.si7_present) {
2140 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2141 }
2142 if (cfg.si8_present) {
2143 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2144 }
2145 }
2146
2147 if (cfg.si2quater_present) {
2148 /* iii) System information type 2 quater is sent if needed, as determined by the system
2149 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2150 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2151 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2152 * within any of 4 consecutive occurrences of TC = 5. */
2153 if (not (cfg.bcch_extended)) {
2154 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2155 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2156 } else {
2157 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2158 }
2159 } else {
2160 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2161 }
2162 }
2163 if (cfg.si9_present) {
2164 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2165 * in system information type 3 as defined in 3GPP TS 44.018. */
2166 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2167 }
2168 if (cfg.si13_present) {
2169 /* vii) System Information type 13 is only related to the GPRS service. System Information
2170 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2171 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2172 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2173 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2174 * within any of 4 consecutive occurrences of TC=4. */
2175 if (not cfg.bcch_extended) {
2176 log("not-bccch-extended");
2177 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2178 } else {
2179 log("bccch-extended");
2180 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2181 }
2182 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002184 }
2185 }
2186 if (cfg.si16_present or cfg.si17_present) {
2187 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2188 * should not be sent in a cell where network sharing is used (see rule xv). */
2189 if (cfg.si22_present) {
2190 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2191 }
2192 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002194 }
2195 if (not cfg.bcch_extended) {
2196 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2197 }
2198 if (cfg.si16_present) {
2199 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2200 }
2201 if (cfg.si17_present) {
2202 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2203 }
2204 }
2205
2206 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2207 * broadcast information. The frequency with which they are sent is determined by the
2208 * system operator. System Information type 9 identifies the scheduling of System
2209 * Information type 18 and 20 messages. */
2210
2211 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2212 * Information Type 19 is present, then its scheduling shall be indicated in System
2213 * Information Type 9. */
2214
2215 if (cfg.si15_present) {
2216 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2217 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2218 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2219 * 4 consecutive occurrences of TC = 1. */
2220 if (not cfg.bcch_extended) {
2221 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2222 } else {
2223 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2224 }
2225 }
2226 if (cfg.si13alt_present) {
2227 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2228 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2229 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2230 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2231 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2232 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2233 * of TC = 4. */
2234 if (cfg.si13_present) {
2235 testcase.stop("Error: Cannot have SI13alt and SI13");
2236 }
2237 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002239 }
2240 if (not cfg.bcch_extended) {
2241 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2242 } else {
2243 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2244 }
2245 }
2246 if (cfg.si2n_present) {
2247 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2248 * as determined by the system operator. In the case that the message is sent on the
2249 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2250 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2251 * consecutive occurrences of TC = 4. */
2252 if (not cfg.bcch_extended) {
2253 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2254 } else {
2255 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2256 }
2257 }
2258 if (cfg.si21_present) {
2259 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2260 * determined by the system operator. If Extended Access Barring is in use in the cell
2261 * then this message is sent at least once within any of 4 consecutive occurrences of
2262 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2263 * cell then this message shall only be sent on BCCH Ext. */
2264 if (not cfg.bcch_extended) {
2265 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2266 } else {
2267 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2268 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002269 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002270 }
2271 }
2272 }
2273 if (cfg.si22_present) {
2274 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2275 * should not be sent in a cell where SoLSA is used (see rule viii). System
2276 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2277 * =2 and TC=6. */
2278 if (cfg.si16_present or cfg.si17_present) {
2279 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2280 }
2281 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2282 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002284 }
2285 if (not cfg.bcch_extended) {
2286 testcase.stop("Error: SI22 requires BCCH Extd!");
2287 } else {
2288 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2289 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2290 }
2291 }
2292}
2293
2294/* sample Systme Information for specified duration via L1CTL */
2295function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2296 timer T := duration;
2297 var SystemInformationVectorPerTc si_per_tc;
2298 var L1ctlDlMessage l1_dl;
2299
2300 /* initialize all per-TC vectors empty */
2301 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2302 si_per_tc[i] := {};
2303 }
2304
2305 /* flush all previous L1 queued msgs */
2306 pt.clear;
2307
2308 T.start;
2309 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002310 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002311 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2312 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2313 log("Ignoring non-RR SI ", l1_dl);
2314 repeat;
2315 }
2316 var SystemInformationFn sig := {
2317 frame_number := l1_dl.dl_info.frame_nr,
2318 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2319 }
2320 var integer tc := f_gsm_compute_tc(sig.frame_number);
2321 log("SI received at TC=", tc, ": ", sig.si);
2322 /* append to the per-TC bucket */
2323 si_per_tc[tc] := si_per_tc[tc] & { sig };
2324 repeat;
2325 }
2326 [] pt.receive { repeat; }
2327 [] T.timeout { }
2328 }
2329
2330 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2331 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2332 }
2333 log("si_per_tc=", si_per_tc);
2334 return si_per_tc;
2335}
2336
2337/* helper function: Set given SI via RSL + validate scheduling.
2338 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2339function f_TC_si_sched() runs on test_CT {
2340 var SystemInformationVectorPerTc si_per_tc;
2341 f_init_l1ctl();
2342 f_l1_tune(L1CTL);
2343
2344 /* Sample + Validate Scheduling */
2345 si_per_tc := f_l1_sample_si(L1CTL);
2346 f_validate_si_scheduling(si_cfg, si_per_tc);
2347
2348 setverdict(pass);
2349}
2350
2351testcase TC_si_sched_default() runs on test_CT {
2352 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002353 /* 2+3+4 are mandatory and set in f_init() */
2354 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002356}
2357
2358testcase TC_si_sched_1() runs on test_CT {
2359 f_init();
2360 si_cfg.si1_present := true;
2361 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002362 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002364}
2365
2366testcase TC_si_sched_2bis() runs on test_CT {
2367 f_init();
2368 si_cfg.si2bis_present := true;
2369 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2370 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002372}
2373
2374testcase TC_si_sched_2ter() runs on test_CT {
2375 f_init();
2376 si_cfg.si2ter_present := true;
2377 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2378 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002380}
2381
2382testcase TC_si_sched_2ter_2bis() runs on test_CT {
2383 f_init();
2384 si_cfg.si2bis_present := true;
2385 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2386 si_cfg.si2ter_present := true;
2387 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2388 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002390}
2391
2392testcase TC_si_sched_2quater() runs on test_CT {
2393 f_init();
2394 si_cfg.si2quater_present := true;
2395 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2396 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002398}
2399
2400testcase TC_si_sched_13() runs on test_CT {
2401 f_init();
2402 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002403 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002404 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002406}
2407
2408testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2409 f_init();
2410 si_cfg.si2bis_present := true;
2411 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2412 si_cfg.si2ter_present := true;
2413 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2414 si_cfg.si2quater_present := true;
2415 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2416 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002417 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002418 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002420}
2421
2422
Harald Welte68e495b2018-02-25 00:05:57 +01002423testcase TC_bcch_info() runs on test_CT {
2424 f_init(testcasename());
2425 /* FIXME: enable / disable individual BCCH info */
2426 //ts_RSL_BCCH_INFO(si_type, info);
2427 /* expect no ERROR REPORT after either of them *
2428 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002430}
2431
Harald Welte93640c62018-02-25 16:59:33 +01002432/***********************************************************************
2433 * Low-Level Protocol Errors / ERROR REPORT
2434 ***********************************************************************/
2435
Harald Welte01d982c2018-02-25 01:31:40 +01002436private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2437 timer T := 5.0;
2438 T.start;
2439 alt {
2440 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2441 setverdict(pass);
2442 }
2443 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002445 }
2446 [] RSL_CCHAN.receive {
2447 repeat;
2448 }
2449 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002451 }
2452 }
2453}
2454
2455/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2456testcase TC_rsl_protocol_error() runs on test_CT {
2457 f_init(testcasename());
2458 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2459 rsl.ies := omit;
2460 RSL_CCHAN.send(ts_RSL_UD(rsl));
2461
2462 f_exp_err_rep(RSL_ERR_PROTO);
2463}
2464
2465/* Provoke a mandatory IE error and match on ERROR REPORT */
2466testcase TC_rsl_mand_ie_error() runs on test_CT {
2467 f_init(testcasename());
2468
2469 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2470 rsl.ies := { rsl.ies[0] };
2471 RSL_CCHAN.send(ts_RSL_UD(rsl));
2472
2473 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2474}
2475
2476/* Provoke an IE content error and match on ERROR REPORT */
2477testcase TC_rsl_ie_content_error() runs on test_CT {
2478 f_init(testcasename());
2479 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2480 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2481 RSL_CCHAN.send(ts_RSL_UD(rsl));
2482
2483 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2484}
2485
Harald Welte93640c62018-02-25 16:59:33 +01002486/***********************************************************************
2487 * IPA CRCX/MDCX/DLCS media stream handling
2488 ***********************************************************************/
2489
Harald Weltea871a382018-02-25 02:03:14 +01002490/* Send IPA DLCX to inactive lchan */
2491function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002492 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2493 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002494}
2495testcase TC_ipa_dlcx_not_active() runs on test_CT {
2496 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2497 f_init(testcasename());
2498 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2499 vc_conn.done;
2500}
Harald Welte68e495b2018-02-25 00:05:57 +01002501
Harald Weltea3f1df92018-02-25 12:49:55 +01002502/* Send IPA CRCX twice to inactive lchan */
2503function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2504 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2505 "IPA CRCX ACK");
2506 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2507 "IPA CRCX NACK");
2508}
2509testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2510 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2511 f_init(testcasename());
2512 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2513 vc_conn.done;
2514}
2515
2516/* Regular sequence of CRCX/MDCX/DLCX */
2517function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2518 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2519 "IPA CRCX ACK");
2520 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2521 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2522 var uint7_t rtp_pt2 := f_rnd_int(127);
2523 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2524 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2525 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2526 "IPA MDCX ACK");
2527 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2528 "IPA DLCX ACK");
2529}
2530testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2531 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2532 f_init(testcasename());
2533 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2534 vc_conn.done;
2535}
2536
Harald Welte3ae11da2018-02-25 13:36:06 +01002537/* Sequence of CRCX, 2x MDCX, DLCX */
2538function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2539 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2540 "IPA CRCX ACK");
2541 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2542 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2543 var uint7_t rtp_pt2 := f_rnd_int(127);
2544 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2545 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2546 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2547 "IPA MDCX ACK");
2548 /* Second MDCX */
2549 remote_ip := f_rnd_int(c_UINT32_MAX);
2550 remote_port := f_rnd_int(c_UINT16_MAX);
2551 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2552 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2553 "IPA MDCX ACK");
2554 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2555 "IPA DLCX ACK");
2556}
2557testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2558 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2559 f_init(testcasename());
2560 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2561 vc_conn.done;
2562}
2563
Harald Welte9912eb52018-02-25 13:30:15 +01002564/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2565function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2566 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2567 "IPA CRCX NACK");
2568}
2569testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2570 var ConnHdlrPars pars;
2571 var ConnHdlr vc_conn;
2572 f_init(testcasename());
2573
2574 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2575 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2576 vc_conn.done;
2577
2578 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2579 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2580 vc_conn.done;
2581}
2582
Harald Weltea3f1df92018-02-25 12:49:55 +01002583
Harald Welte883340c2018-02-28 18:59:29 +01002584/***********************************************************************
2585 * PCU Socket related tests
2586 ***********************************************************************/
2587
2588private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2589runs on test_CT {
2590 timer T := 3.0;
2591
2592 /* we don't expect any RTS.req before PDCH are active */
2593 T.start;
2594 alt {
2595 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01002597 }
2598 [] PCU.receive { repeat; }
2599 [] T.timeout { }
2600 }
2601
2602 /* Send PDCH activate request for known PDCH timeslot */
2603 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2604
2605 /* we now expect RTS.req for this timeslot (only) */
2606 T.start;
2607 alt {
2608 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2609 setverdict(pass);
2610 }
2611 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2612 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01002614 }
2615 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01002617 }
2618 [] PCU.receive { repeat; }
2619 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002621 }
2622 [not exp_success] T.timeout {
2623 setverdict(pass);
2624 }
2625 }
2626}
2627
2628private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2629runs on test_CT {
2630 timer T := 3.0;
2631
2632 /* Send PDCH activate request for known PDCH timeslot */
2633 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2634
2635 PCU.clear;
2636 /* we now expect no RTS.req for this timeslot */
2637 T.start;
2638 alt {
2639 [] 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 +02002640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002641 }
2642 [] PCU.receive { repeat; }
2643 [] T.timeout {
2644 setverdict(pass);
2645 }
2646 }
2647}
2648
2649/* PDCH activation via PCU socket; check for presence of RTS.req */
2650testcase TC_pcu_act_req() runs on test_CT {
2651 f_init();
2652 f_TC_pcu_act_req(0, 0, 7, true);
2653}
2654
2655/* PDCH activation via PCU socket on non-PDCU timeslot */
2656testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2657 f_init();
2658 f_TC_pcu_act_req(0, 0, 1, false);
2659}
2660
2661/* PDCH activation via PCU socket on wrong BTS */
2662testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2663 f_init();
2664 f_TC_pcu_act_req(23, 0, 7, false);
2665}
2666
2667/* PDCH activation via PCU socket on wrong TRX */
2668testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2669 f_init();
2670 f_TC_pcu_act_req(0, 23, 7, false);
2671}
2672
2673/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2674testcase TC_pcu_deact_req() runs on test_CT {
2675 f_init();
2676 /* Activate PDCH */
2677 f_TC_pcu_act_req(0, 0, 7, true);
2678 f_sleep(1.0);
2679 /* and De-Activate again */
2680 f_TC_pcu_deact_req(0, 0, 7);
2681}
2682
2683/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2684testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2685 f_init();
2686 f_TC_pcu_deact_req(0, 0, 1);
2687}
2688
2689/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2690testcase TC_pcu_ver_si13() runs on test_CT {
2691 const octetstring si13 := '00010203040506070909'O;
2692 var PCUIF_send_data sd;
2693 timer T:= 3.0;
2694 f_init();
2695
2696 /* Set SI13 via RSL */
2697 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2698 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2699 T.start;
2700 alt {
2701 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2702 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2703 setverdict(pass);
2704 } else {
2705 repeat;
2706 }
2707 }
2708 [] PCU.receive { repeat; }
2709 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01002711 }
2712 }
2713}
2714
2715private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2716
2717/* helper function to send a PCU DATA.req */
2718private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2719 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2720runs on test_CT
2721{
2722 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2723 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2724}
2725
2726/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2727private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2728 PCUIF_Sapi sapi, octetstring data)
2729runs on test_CT
2730{
2731 var PCUIF_send_data sd;
2732
2733 timer T := 3.0;
2734 T.start;
2735 alt {
2736 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2737 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2738 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2739 sd.data.u.rts_req.fn, sapi, data);
2740 }
2741 [] PCU.receive { repeat; }
2742 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01002744 }
2745 }
2746}
2747
2748/* Send DATA.req on invalid BTS */
2749testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2750 f_init();
2751 f_TC_pcu_act_req(0, 0, 7, true);
2752 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2753 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2754 f_sleep(10.0);
2755}
2756
2757/* Send DATA.req on invalid TRX */
2758testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2759 f_init();
2760 f_TC_pcu_act_req(0, 0, 7, true);
2761 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2762 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2763 f_sleep(10.0);
2764}
2765
2766/* Send DATA.req on invalid timeslot */
2767testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2768 f_init();
2769 f_TC_pcu_act_req(0, 0, 7, true);
2770 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2771 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2772 f_sleep(10.0);
2773}
2774
2775/* Send DATA.req on timeslot that hasn't been activated */
2776testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2777 f_init();
2778 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2779 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2780 f_sleep(2.0);
2781}
2782
2783testcase TC_pcu_data_req_pdtch() runs on test_CT {
2784 f_init();
2785 f_TC_pcu_act_req(0, 0, 7, true);
2786 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2787 /* FIXME: how to check this was actually sent */
2788 f_sleep(2.0);
2789}
2790
2791testcase TC_pcu_data_req_ptcch() runs on test_CT {
2792 f_init();
2793 f_TC_pcu_act_req(0, 0, 7, true);
2794 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2795 /* FIXME: how to check this was actually sent */
2796 f_sleep(2.0);
2797}
2798
2799/* Send AGCH from PCU; check it appears on Um side */
2800testcase TC_pcu_data_req_agch() runs on test_CT {
2801 timer T := 3.0;
2802 f_init();
2803 f_init_l1ctl();
2804 f_l1_tune(L1CTL);
2805
2806 f_TC_pcu_act_req(0, 0, 7, true);
2807 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2808
2809 T.start;
2810 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002811 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002812 setverdict(pass);
2813 }
2814 [] L1CTL.receive { repeat; }
2815 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002817 }
2818 }
2819}
2820
2821/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2822testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2823 var octetstring imm_ass := f_rnd_octstring(23);
2824 f_init();
2825 f_init_l1ctl();
2826 f_l1_tune(L1CTL);
2827
2828 /* append 3 last imsi digits so BTS can compute pagng group */
2829 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2830
2831 timer T := 0.5;
2832 T.start;
2833 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002834 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002835 /* TODO: verify paging group */
2836 setverdict(pass);
2837 }
2838 [] L1CTL.receive { repeat; }
2839 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01002841 }
2842 }
2843}
2844
2845/* Send RACH from Um side, expect it to show up on PCU socket */
2846testcase TC_pcu_rach_content() runs on test_CT {
2847 f_init();
2848 f_init_l1ctl();
2849 f_l1_tune(L1CTL);
2850
2851 var GsmFrameNumber fn_last := 0;
2852 for (var integer i := 0; i < 1000; i := i+1) {
2853 var OCT1 ra := f_rnd_ra_ps();
2854 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2855 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01002857 }
2858 fn_last := fn;
2859
2860 timer T := 2.0;
2861 T.start;
2862 alt {
2863 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2864 T.stop;
2865 }
2866 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002868 }
2869 [] PCU.receive { repeat; }
2870 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01002872 }
2873 }
2874 }
2875 setverdict(pass);
2876}
2877
2878private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2879 var integer strlen := lengthof(str);
2880 for (var integer i := 0; i < len-strlen; i := i+1) {
2881 str := str & pad;
2882 }
2883 return str;
2884}
2885
2886/* Send PAGING via RSL, expect it to shw up on PCU socket */
2887testcase TC_pcu_paging_from_rsl() runs on test_CT {
2888 f_init();
2889
2890 for (var integer i := 0; i < 100; i := i+1) {
2891 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2892 timer T := 3.0;
2893 if (i < 50) {
2894 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2895 } else {
2896 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2897 }
2898 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2899 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2900 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2901
2902 /* Send RSL PAGING COMMAND */
2903 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2904 T.start;
2905 alt {
2906 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2907 }
2908 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01002910 }
2911 [] PCU.receive { repeat; }
2912 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01002914 }
2915 }
2916 }
2917 setverdict(pass);
2918}
2919
Harald Welte3d04ae62018-04-04 20:29:05 +02002920/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002921 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002922 ***********************************************************************/
2923
2924private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2925runs on ConnHdlr {
2926 var PCUIF_send_data sd;
2927 /* Expect BTS to immediately acknowledge activation as PDCH */
2928 PCU.clear;
2929 f_rsl_chan_act(g_pars.chan_mode);
2930 /* expect INFO_IND on PCU interface listing TS as PDCH */
2931 alt {
2932 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2933 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 +02002934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02002935 }
2936 }
2937 [] PCU.receive { repeat; }
2938 }
2939 /* try to activate this PDCH from the PCU point of view */
2940 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2941 /* FIXME: is there a response? */
2942}
2943
2944private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2945runs on ConnHdlr {
2946 var PCUIF_send_data sd;
2947 /* Send RSL CHAN REL (deactivate) */
2948 PCU.clear;
2949 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2950 /* expect BTS to ask PCU to deactivate the channel */
2951 alt {
2952 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2953 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 +02002954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02002955 }
2956 }
2957 [] PCU.receive { repeat; }
2958 }
2959 /* Emulate PCU asking BTS to deactivate PDCH */
2960 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2961 alt {
2962 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2963 setverdict(pass);
2964 }
2965 [] RSL.receive { repeat; }
2966 }
2967}
2968
2969/* Activate Osmocom-style dynamic PDCH from BSC side */
2970function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2971 var PCUIF_Message first_info;
2972 var integer ts_nr := g_chan_nr.tn;
2973 var integer trx_nr := 0;
2974 var integer bts_nr := 0;
2975 var integer pcu_conn_id := -1;
2976
2977 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2978
2979 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2980 f_sleep(3.0);
2981 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2982 setverdict(pass);
2983}
2984testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2985 var ConnHdlrPars pars;
2986 var ConnHdlr vc_conn;
2987 f_init(testcasename());
2988
2989 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2990 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2991 vc_conn.done;
2992}
2993
2994/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2995function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2996 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002997 var integer pcu_conn_id := -1;
2998
2999 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3000
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003001 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3002 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3003 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003004 setverdict(pass);
3005}
3006testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3007 var ConnHdlrPars pars;
3008 var ConnHdlr vc_conn;
3009 f_init(testcasename());
3010
3011 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3012 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3013 vc_conn.done;
3014}
3015
3016/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3017function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3018 var PCUIF_Message first_info;
3019 var integer ts_nr := g_chan_nr.tn;
3020 var integer trx_nr := 0;
3021 var integer bts_nr := 0;
3022 var integer pcu_conn_id := -1;
3023
3024 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3025
3026 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003027 /* Send a second Chan Activ and expect it to be NACKed */
3028 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3029 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003030 setverdict(pass);
3031}
3032testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3033 var ConnHdlrPars pars;
3034 var ConnHdlr vc_conn;
3035 f_init(testcasename());
3036
3037 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3038 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3039 vc_conn.done;
3040}
3041
3042/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3043function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3044 var PCUIF_Message first_info;
3045 var integer ts_nr := g_chan_nr.tn;
3046 var integer trx_nr := 0;
3047 var integer bts_nr := 0;
3048 var integer pcu_conn_id := -1;
3049 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3050
3051 /* register for the TCH/F channel number */
3052 f_rslem_register(0, chan_nr);
3053
3054 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3055
3056 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3057 "RSL CHAN ACT");
3058 setverdict(pass);
3059}
3060testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3061 var ConnHdlrPars pars;
3062 var ConnHdlr vc_conn;
3063 f_init(testcasename());
3064
3065 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3066 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3067 vc_conn.done;
3068}
3069
3070/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3071function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3072 var PCUIF_Message first_info;
3073 var integer ts_nr := g_chan_nr.tn;
3074 var integer trx_nr := 0;
3075 var integer bts_nr := 0;
3076 var integer pcu_conn_id := -1;
3077 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3078 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3079
3080 /* register for the TCH/H channel numbers */
3081 f_rslem_register(0, chan_nr[0]);
3082 f_rslem_register(0, chan_nr[1]);
3083
3084 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3085
3086 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3087 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3088 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3089 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3090 setverdict(pass);
3091}
3092testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3093 var ConnHdlrPars pars;
3094 var ConnHdlr vc_conn;
3095 f_init(testcasename());
3096
3097 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3098 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3099 vc_conn.done;
3100}
3101
Harald Welte9bbbfb52018-04-05 09:33:19 +02003102/***********************************************************************
3103 * IPA Style Dynamic Timeslot Support
3104 ***********************************************************************/
3105
3106private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3107runs on ConnHdlr {
3108 var PCUIF_send_data sd;
3109 /* Expect BTS to immediately acknowledge activation as PDCH */
3110 PCU.clear;
3111 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3112 /* expect INFO_IND on PCU interface listing TS as PDCH */
3113 alt {
3114 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3115 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 +02003116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003117 }
3118 }
3119 [] PCU.receive { repeat; }
3120 }
3121 /* try to activate this PDCH from the PCU point of view */
3122 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3123 /* FIXME: is there a response? */
3124
3125 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3126}
3127
3128private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3129runs on ConnHdlr {
3130 var PCUIF_send_data sd;
3131 /* Send RSL CHAN REL (deactivate) */
3132 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3133 PCU.clear;
3134 /* expect BTS to ask PCU to deactivate the channel */
3135 alt {
3136 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3137 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 +02003138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003139 }
3140 }
3141 [] PCU.receive { repeat; }
3142 }
3143 /* Emulate PCU asking BTS to deactivate PDCH */
3144 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3145 alt {
3146 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3147 setverdict(pass);
3148 }
3149 [] RSL.receive { repeat; }
3150 }
3151}
3152
3153/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3154function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3155 var PCUIF_Message first_info;
3156 var integer ts_nr := g_chan_nr.tn;
3157 var integer trx_nr := 0;
3158 var integer bts_nr := 0;
3159 var integer pcu_conn_id := -1;
3160
3161 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3162
3163 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3164 f_sleep(3.0);
3165 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3166
3167 setverdict(pass);
3168
3169}
3170testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3171 var ConnHdlrPars pars;
3172 var ConnHdlr vc_conn;
3173 f_init();
3174
3175 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3176 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3177 vc_conn.done;
3178}
3179
3180/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3181function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3182 var PCUIF_Message first_info;
3183 var integer ts_nr := g_chan_nr.tn;
3184 var integer trx_nr := 0;
3185 var integer bts_nr := 0;
3186 var integer pcu_conn_id := -1;
3187
3188 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3189
3190 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3191 "RSL CHAN ACT");
3192 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3193 "RF CHAN REL", true);
3194 setverdict(pass);
3195}
3196testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3197 var ConnHdlrPars pars;
3198 var ConnHdlr vc_conn;
3199 f_init(testcasename());
3200
3201 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3202 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3203 vc_conn.done;
3204}
3205
3206/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3207function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3208 var PCUIF_Message first_info;
3209 var integer ts_nr := g_chan_nr.tn;
3210 var integer trx_nr := 0;
3211 var integer bts_nr := 0;
3212 var integer pcu_conn_id := -1;
3213
3214 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3215
3216 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3217 "RSL CHAN ACT");
3218
3219 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3220 alt {
3221 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3222 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003224 }
3225 [] RSL.receive { repeat; }
3226 }
3227
3228 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3229 "RF CHAN REL", true);
3230 setverdict(pass);
3231}
3232testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3233 var ConnHdlrPars pars;
3234 var ConnHdlr vc_conn;
3235 f_init(testcasename());
3236
3237 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3238 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3239 vc_conn.done;
3240}
3241
3242/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3243function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3244 var PCUIF_Message first_info;
3245 var integer ts_nr := g_chan_nr.tn;
3246 var integer trx_nr := 0;
3247 var integer bts_nr := 0;
3248 var integer pcu_conn_id := -1;
3249
3250 /* register for the TCH/F channel number */
3251 f_rslem_register(0, g_chan_nr);
3252
3253 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3254
3255 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3256
3257 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3258 "RSL CHAN ACT");
3259
3260 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3261
3262 setverdict(pass);
3263}
3264testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3265 var ConnHdlrPars pars;
3266 var ConnHdlr vc_conn;
3267 f_init(testcasename());
3268
3269 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3270 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3271 vc_conn.done;
3272}
3273
3274
Harald Welte0472ab42018-03-12 15:02:26 +01003275/***********************************************************************
3276 * LAPDm / RLL related
3277 ***********************************************************************/
3278
3279private function f_tx_lapdm(template (value) LapdmFrame l,
3280 template (value) RslLinkId link_id) runs on ConnHdlr {
3281 var octetstring l2 := enc_LapdmFrame(valueof(l));
3282 if (valueof(link_id.c) == SACCH) {
3283 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02003284 var L1ctlDataReq l1hl2 := {
3285 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
3286 l2_payload := f_pad_oct(l2, 21, '2B'O)
3287 }
3288 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
3289 } else {
3290 /* If required, pad L2 frame with constant 0x2b filling */
3291 l2 := f_pad_oct(l2, 23, '2B'O);
3292
3293 log("encoding ", l, " to ", l2);
3294 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01003295 }
Harald Welte0472ab42018-03-12 15:02:26 +01003296}
3297
3298type record RllTestCase {
3299 uint3_t sapi,
3300 RslLinkId link_id,
3301 octetstring l3,
3302 boolean exp
3303}
3304type record of RllTestCase RllTestCases;
3305template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3306 sapi := sapi,
3307 link_id := id,
3308 l3 := l3,
3309 exp := exp
3310}
3311
3312/* execute the same callback function with a set of different parameters (tcs) on a
3313 * variety of logical channels */
3314private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3315 var ConnHdlrPars pars;
3316 var ConnHdlr vc_conn;
3317 f_init(testcasename());
3318
3319 /* test on each of the channels we have */
3320 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3321 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3322
3323 /* test each of the test cases on the current channel */
3324 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3325 pars.spec.rll := tcs[j];
3326 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3327 vc_conn := f_start_handler(fn, pars);
3328 vc_conn.done;
3329 }
3330 }
3331
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01003333}
3334
3335/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3336private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3337 var RllTestCase tc := g_pars.spec.rll;
3338 timer T := 3.0;
3339
3340 f_l1_tune(L1CTL);
3341 RSL.clear;
3342
3343 /* activate the logical channel */
3344 f_est_dchan();
3345 L1CTL.clear;
3346
3347 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3348 T.start;
3349 alt {
3350 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3351 if (tc.exp) {
3352 setverdict(pass);
3353 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003355 }
3356 }
3357 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3358 if (tc.exp) {
3359 setverdict(pass);
3360 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003362 }
3363 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003364 /* We also expect to receive the measurements */
3365 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003366 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003368 }
3369 [not tc.exp] T.timeout {
3370 setverdict(pass);
3371 }
3372 }
3373
3374 f_rsl_chan_deact();
3375 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3376 f_rslem_unregister(0, g_chan_nr);
3377}
3378testcase TC_rll_est_ind() runs on test_CT {
3379 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003380 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003381 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003382 /* normal SAPI0 establishment */
3383 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003384 /* SAPI 3 doesn't support contention resolution */
3385 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3386 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3387 /* normal SAPI3 establishment on main DCCH */
3388 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3389 /* normal SAPI3 establishment on SACCH */
3390 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3391 };
3392 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3393}
3394
3395/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3396private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3397 var RllTestCase tc := g_pars.spec.rll;
3398 var L1ctlDlMessage dl;
3399 timer T := 3.0;
3400
3401 f_l1_tune(L1CTL);
3402 RSL.clear;
3403
3404 /* activate the logical channel */
3405 f_est_dchan();
3406 L1CTL.clear;
3407
3408 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3409 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3410 T.start;
3411 alt {
3412 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3413 var LapdmFrame lapdm;
3414 var octetstring l2 := dl.payload.data_ind.payload;
3415 if (dl.dl_info.link_id.c == SACCH) {
3416 /* remove L1 header */
3417 l2 := substr(l2, 2, lengthof(l2)-2);
3418 }
3419 lapdm.ab := dec_LapdmFrameAB(l2);
3420 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3421 setverdict(pass);
3422 } else {
3423 repeat;
3424 }
3425 }
3426 [] L1CTL.receive { repeat; }
3427 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01003429 }
3430 }
3431
3432 f_rsl_chan_deact();
3433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3434 f_rslem_unregister(0, g_chan_nr);
3435}
3436testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3437 var RllTestCases tcs := {
3438 /* normal SAPI3 establishment on main DCCH */
3439 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3440 };
3441 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3442}
3443testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3444 var RllTestCases tcs := {
3445 /* normal SAPI3 establishment on SACCH */
3446 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3447 }
3448 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3449}
3450
3451/* altstep to receive a LAPDm frame matching the given template */
3452private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3453 var L1ctlDlMessage dl;
3454 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3455 var LapdmFrame lapdm;
3456 var octetstring l2 := dl.payload.data_ind.payload;
3457 if (dl.dl_info.link_id.c == SACCH) {
3458 /* remove L1 header */
3459 l2 := substr(l2, 2, lengthof(l2)-2);
3460 }
3461 if (ischosen(exp.ab)) {
3462 lapdm.ab := dec_LapdmFrameAB(l2);
3463 } else if (ischosen(exp.b4)) {
3464 lapdm.b4 := dec_LapdmFrameB4(l2);
3465 } else if (ischosen(exp.bbis)) {
3466 lapdm.bbis := dec_LapdmFrameBbis(l2);
3467 }
3468 log("Rx LAPDm ", lapdm);
3469 if (match(lapdm, exp)) {
3470 setverdict(pass);
3471 } else {
3472 repeat;
3473 }
3474 }
3475 [] L1CTL.receive { repeat; }
3476}
3477private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3478 timer T := t;
3479 T.start;
3480 alt {
3481 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01003483 }
3484 [] as_l1_exp_lapdm(exp);
3485 }
3486}
3487
3488/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3489private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3490 /* send SABM from MS -> BTS */
3491 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3492 /* expect RLL EST IND on Abis */
3493 alt {
3494 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3495 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3496 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003498 }
3499 [] RSL.receive { repeat; }
3500 }
3501 /* expect UA from BTS -> MS */
3502 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3503}
3504
3505/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3506private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3507 var RllTestCase tc := g_pars.spec.rll;
3508
3509 f_l1_tune(L1CTL);
3510 RSL.clear;
3511
3512 /* activate the logical channel */
3513 f_est_dchan();
3514 L1CTL.clear;
3515
3516 /* first establish the link-layer */
3517 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3518
3519 /* then send the DISC */
3520 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3521 /* ... and expect the REL IND on the RSL side */
3522 alt {
3523 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3524 setverdict(pass);
3525 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003526 /* We also expect to receive the measurements */
3527 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003528 }
3529
3530 /* release the channel */
3531 f_rsl_chan_deact();
3532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3533 f_rslem_unregister(0, g_chan_nr);
3534}
3535testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3536 var RllTestCases tcs := {
3537 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3538 };
3539 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3540}
3541
3542testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3543 var RllTestCases tcs := {
3544 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3545 };
3546 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3547}
3548testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3549 var RllTestCases tcs := {
3550 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3551 };
3552 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3553}
3554testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3555 var RllTestCases tcs := {
3556 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3557 };
3558 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3559}
3560
3561/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3562private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3563 var RllTestCase tc := g_pars.spec.rll;
3564 f_l1_tune(L1CTL);
3565 RSL.clear;
3566
3567 /* activate the logical channel */
3568 f_est_dchan();
3569 L1CTL.clear;
3570
3571 /* first establish the link-layer */
3572 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3573
3574 /* then send the REL REQ via RSL */
3575 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3576 /* ... and expect the DISC on the Um side */
3577 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003578 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003579 /* FIXME: send a UA in resposne to the DISC */
3580 }
3581 }
3582
3583 /* release the channel */
3584 f_rsl_chan_deact();
3585 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3586 f_rslem_unregister(0, g_chan_nr);
3587}
3588testcase TC_rll_rel_req() runs on test_CT {
3589 var RllTestCases tcs := {
3590 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3591 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3592 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3593 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3594 };
3595 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3596}
3597
3598/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3599testcase TC_rll_data_req() runs on test_CT {
3600}
3601
3602/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3603testcase TC_rll_data_ind() runs on test_CT {
3604}
3605
3606/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3607private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3608 var RllTestCase tc := g_pars.spec.rll;
3609
3610 f_l1_tune(L1CTL);
3611 RSL.clear;
3612
3613 f_est_dchan();
3614 L1CTL.clear;
3615
3616 /* Send UNITDATA REQ on RSL side */
3617 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3618 /* Expect it to arrive on the other side */
3619 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003620 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003621 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003622 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003623 }
3624
3625 /* release the channel */
3626 f_rsl_chan_deact();
3627 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3628 f_rslem_unregister(0, g_chan_nr);
3629}
3630testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3631 var octetstring l3 := f_rnd_octstring(15);
3632 var RllTestCases tcs := {
3633 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3634 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3635 };
3636 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3637}
3638testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3639 var octetstring l3 := f_rnd_octstring(19);
3640 var RllTestCases tcs := {
3641 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3642 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3643 };
3644 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3645}
3646
3647/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3648private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3649 var RllTestCase tc := g_pars.spec.rll;
3650
3651 f_l1_tune(L1CTL);
3652 RSL.clear;
3653
3654 f_est_dchan();
3655 L1CTL.clear;
3656
3657 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003658 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003659 /* Expdct RLL UNITDATA IND on RSL side */
3660 alt {
3661 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3662 setverdict(pass);
3663 }
3664 [] RSL.receive { repeat; }
3665 }
3666
3667 /* release the channel */
3668 f_rsl_chan_deact();
3669 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3670 f_rslem_unregister(0, g_chan_nr);
3671}
3672testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02003673 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01003674 var RllTestCases tcs := {
3675 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3676 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3677 };
3678 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3679}
3680testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3681 var octetstring l3 := f_rnd_octstring(18);
3682 var RllTestCases tcs := {
3683 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3684 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3685 };
3686 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3687}
3688
Harald Weltee613f962018-04-18 22:38:16 +02003689/***********************************************************************
3690 * Encryption Related
3691 ***********************************************************************/
3692
3693/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3694function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3695 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3696 if (link_id.c == SACCH) {
3697 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3698 } else {
3699 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3700 }
3701}
3702
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003703/* Expect (or not expect) other kinds of messages */
3704private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
3705 [exp_any] RSL.receive { repeat; }
3706 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003708 }
3709}
3710
Harald Weltee613f962018-04-18 22:38:16 +02003711/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07003712private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003713 RslLinkId link_id,
3714 octetstring l3,
3715 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003716 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07003717) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02003718 timer T := 3.0;
3719 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3720 T.start;
3721 /* Expect RLL UNITDATA IND on RSL side */
3722 alt {
3723 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3724 setverdict(pass);
3725 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003726 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07003727 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02003728 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02003730 }
Harald Weltee613f962018-04-18 22:38:16 +02003731 }
3732}
3733
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003734/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
3735private function f_data_mo(
3736 RslLinkId link_id,
3737 boolean p, uint3_t nr, uint3_t ns,
3738 octetstring l3,
3739 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07003740 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003741) runs on ConnHdlr {
3742 timer T := 3.0;
3743 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
3744 T.start;
3745 /* Expect RLL DATA IND on RSL side */
3746 alt {
3747 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
3748 setverdict(pass);
3749 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07003750 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003751 [] as_rsl_any_ind(exp_any);
3752 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003754 }
3755 }
3756}
3757
Harald Weltee613f962018-04-18 22:38:16 +02003758/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3759function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3760 f_l1_tune(L1CTL);
3761 f_est_dchan(true);
3762
3763 /* now we actually need to transmit some data both ways to check if the encryption works */
3764 var L1ctlDlMessage dl;
3765
Stefan Sperling603d98e2018-07-25 16:47:28 +02003766 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02003767 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3768
3769 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3770 f_unitdata_mt(link_id, l3);
3771
3772 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3773 f_unitdata_mo(link_id, l3);
3774
3775 /* release the channel */
3776 f_rsl_chan_deact();
3777 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3778 f_rslem_unregister(0, g_chan_nr);
3779}
3780testcase TC_chan_act_a51() runs on test_CT {
3781 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3782 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3783 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3784}
3785testcase TC_chan_act_a52() runs on test_CT {
3786 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3787 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3788 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3789}
3790testcase TC_chan_act_a53() runs on test_CT {
3791 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3792 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3793 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3794}
3795
3796
3797/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3798function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3799 /* L3 payload doesn't matter, as it is passed transparently */
3800 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3801 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3802 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3803
3804 f_l1_tune(L1CTL);
3805
3806 /* first establish a dedicated channel in the clear */
3807 f_est_dchan(false);
3808
3809 /* Establish ABM */
3810 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3811
3812 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3813 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3814 /* expect the L3 to arrive still unencrypted on the MS side */
3815 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3816
3817 /* configure L1 to apply ciphering */
3818 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3819 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3820
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07003821 /* send first ciphered I-frame in response and expect it on RSL */
3822 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02003823
3824 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3825 * and hence enable encryption also on the downlink */
3826
3827 /* expect bi-directional communication work in encrypted mode */
3828 f_unitdata_mo(link_id, f_rnd_octstring(15));
3829 f_unitdata_mt(link_id, f_rnd_octstring(15));
3830
3831 /* release the channel */
3832 f_rsl_chan_deact();
3833 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3834 f_rslem_unregister(0, g_chan_nr);
3835}
3836testcase TC_encr_cmd_a51() runs on test_CT {
3837 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3838 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3839 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3840}
3841testcase TC_encr_cmd_a52() runs on test_CT {
3842 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3843 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3844 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3845}
3846testcase TC_encr_cmd_a53() runs on test_CT {
3847 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3848 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3849 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3850}
3851
3852private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3853 var LapdmFrame lf;
3854 var octetstring reenc;
3855
3856 /* decode the LAPDm frame */
3857 if (ischosen(exp_match.ab)) {
3858 lf.ab := dec_LapdmFrameAB(enc);
3859 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02003861 }
3862
3863 /* check if decoder result matches expectation */
3864 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003866 } else {
3867 log(name, ": matched");
3868 setverdict(pass);
3869 }
3870
3871 /* test if re-encoded frame equals original input */
3872 reenc := enc_LapdmFrame(lf);
3873 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02003875 } else {
3876 setverdict(pass);
3877 }
3878}
3879
3880testcase TC_lapdm_selftest() runs on test_CT {
3881 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3882 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3883 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3884 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3885 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3886 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3887 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3888}
3889
Stefan Sperling4880be42018-08-07 18:12:59 +02003890/***********************************************************************
3891 * DTX Related (see GSM 05.08, section 8.3)
3892 ***********************************************************************/
3893
3894/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
3895function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
3896 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
3897 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
3898 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
3899 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
3900}
3901function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
3902 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
3903 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
3904}
3905function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
3906 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
3907 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
3908 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
3909 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
3910}
3911function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
3912 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
3913 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
3914 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
3915 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
3916 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
3917 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
3918 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
3919 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
3920}
3921
3922function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
3923 var L1ctlDlMessage dl;
3924 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
3925 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
3926 var GsmFrameNumber first_fn;
3927 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003928 var integer nfill_frames_sacch := 0;
3929 var integer nfill_frames_nonsacch := 0;
3930 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02003931 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
3932 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003933 const integer frame_dtx_tchf_mod := 104;
3934 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
3935 * which operates in terms of blocks rather than frames. */
3936 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
3937 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02003938 timer T := 5.0;
3939
3940 f_l1_tune(L1CTL);
3941 RSL.clear;
3942 L1CTL.clear;
3943
3944 /* activate TCHF signalling channel */
3945 f_est_dchan(false);
3946
3947 T.start;
3948 alt {
3949 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3950 var GsmFrameNumber fn := dl.dl_info.frame_nr;
3951 var octetstring l2 := dl.payload.data_ind.payload;
3952
3953 if (is_first_frame) {
3954 is_first_frame := false;
3955 first_fn := dl.dl_info.frame_nr;
3956 }
3957
3958 if (dl.dl_info.link_id.c == SACCH) {
3959 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
3960 if (not match(l2_fill_frame_sacch, l2)) {
3961 repeat;
3962 }
3963 } else if (not match(l2_fill_frame, l2)) {
3964 repeat;
3965 }
3966
3967 if (dtxd) {
3968 if (not f_g_chan_is_tchf()) {
3969 T.stop;
3970 f_rsl_chan_deact();
3971 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003972 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 +02003973 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003974 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02003975 T.stop;
3976 f_rsl_chan_deact();
3977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003978
3979 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
3980 * 2 SACCH, 1 TCH/F */
3981 expected_fill_frames := 3;
3982
3983 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
3984 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
3985 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02003987 } else {
3988 setverdict(pass);
3989 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003990 } else {
3991 if (dl.dl_info.link_id.c == SACCH) {
3992 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02003993 repeat;
3994 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02003995 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
3996 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
3997 * we should only see the subset of frames numbers which correspond to a block boundary.
3998 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
3999 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4000 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4001 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4002 repeat;
4003 }
4004 }
4005 log("Received DTX TCH fill frame with bad frame number: ", fn,
4006 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4007 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4008 f_rsl_chan_deact();
4009 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004011 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004012 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004013 if (dl.dl_info.link_id.c == SACCH) {
4014 nfill_frames_sacch := nfill_frames_sacch + 1;
4015 } else {
4016 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4017 }
4018 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004019 T.stop;
4020 if (f_g_chan_is_tchf()) {
4021 /* Without DTX we can expect 25 fill frames for every 104 frames.
4022 * (24 FACCH + 1 SACCH filling) */
4023 expected_fill_frames := 25;
4024 } else if (f_g_chan_is_tchh()) {
4025 /* We can expect 2 fill frames for every 104 frames. */
4026 expected_fill_frames := 2;
4027 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4028 /* We can expect 5 fill frames for every 104 frames. */
4029 expected_fill_frames := 5;
4030 } else {
4031 f_rsl_chan_deact();
4032 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004034 }
4035
4036 f_rsl_chan_deact();
4037 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004038
4039 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004040 setverdict(pass);
4041 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004042 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4043 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004045 }
4046 } else {
4047 repeat;
4048 }
4049 }
4050 }
4051 [] L1CTL.receive { repeat; }
4052 [] T.timeout {
4053 f_rsl_chan_deact();
4054 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004056 }
4057 }
4058}
4059
4060function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4061 f_test_l2_fill_frames(false);
4062}
4063
4064function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4065 f_test_l2_fill_frames(true);
4066}
4067
4068function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4069 var ConnHdlr vc_conn;
4070 var ConnHdlrPars pars;
4071 pars.t_guard := 60.0;
4072 f_init(testcasename());
4073 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4074 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4075 if (dtxd) {
4076 if (i >= 4) { /* DTX is only allowed on TCH/F */
4077 break;
4078 }
4079 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4080 } else {
4081 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4082 }
4083 vc_conn.done;
4084 }
4085}
4086
4087/* Verify that L2 fill frames are sent on TCH in signaling mode if
4088 * there is nothing to transmit while DTX is disabled on downlink. */
4089testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4090 f_tch_sign_l2_fill_frame(false);
4091}
4092
4093/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4094 * there is nothing to transmit while DTX is enabled on downlink. */
4095testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4096 f_tch_sign_l2_fill_frame(true);
4097}
Harald Welte0472ab42018-03-12 15:02:26 +01004098
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004099testcase TC_chopped_ipa_ping() runs on test_CT {
4100 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4101}
4102
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004103testcase TC_chopped_ipa_payload() runs on test_CT {
4104 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4105}
4106
Harald Welte0472ab42018-03-12 15:02:26 +01004107/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4108/* protocol error as per 44.006 */
4109/* link layer failure (repetition of I-frame N200 times without ACK */
4110/* repetition of SABM or DISC N200 times without ACK */
4111/* receptiom of SABM in multi-frame established state */
4112
4113
4114
4115
Harald Welte883340c2018-02-28 18:59:29 +01004116
Harald Welte68e495b2018-02-25 00:05:57 +01004117/* TODO Areas:
4118
4119* channel activation
4120** with BS_Power / MS_Power, bypassing power control loop
4121** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004122** with timing advance from initial activation on
4123* mode modify
4124** encryption
4125** multirate
4126* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01004127** unsupported algorithm
4128* handover detection
4129* MS Power Control
4130* BS Power Control
4131* Physical Context
Harald Welte43c54642018-09-15 17:47:04 +03004132* CCCH Load Indication for RACH
Harald Welte68e495b2018-02-25 00:05:57 +01004133* SMS Broadcast Req / Cmd / CBCH LOad Ind
4134* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01004135* error handling
Harald Welte43c54642018-09-15 17:47:04 +03004136** discriminator error
Harald Welte68e495b2018-02-25 00:05:57 +01004137** type error
4138** sequence error
4139** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01004140* PCU interface
4141** TIME_IND from BTS->PCU
4142** DATA_IND from BTS->PCU
4143** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01004144
4145*/
Harald Welte70767382018-02-21 12:16:40 +01004146
4147control {
4148 execute( TC_chan_act_stress() );
4149 execute( TC_chan_act_react() );
4150 execute( TC_chan_deact_not_active() );
4151 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01004152 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01004153 execute( TC_sacch_filling() );
4154 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01004155 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01004156 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01004157 execute( TC_rach_content() );
4158 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01004159 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01004160 execute( TC_meas_res_sign_tchf() );
4161 execute( TC_meas_res_sign_tchh() );
4162 execute( TC_meas_res_sign_sdcch4() );
4163 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01004164 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01004165 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01004166 execute( TC_paging_imsi_80percent() );
4167 execute( TC_paging_tmsi_80percent() );
4168 execute( TC_paging_imsi_200percent() );
4169 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01004170 execute( TC_rsl_protocol_error() );
4171 execute( TC_rsl_mand_ie_error() );
4172 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01004173 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01004174 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01004175 execute( TC_si_sched_2bis() );
4176 execute( TC_si_sched_2ter() );
4177 execute( TC_si_sched_2ter_2bis() );
4178 execute( TC_si_sched_2quater() );
4179 execute( TC_si_sched_13() );
4180 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01004181 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01004182 execute( TC_ipa_crcx_twice_not_active() );
4183 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01004184 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01004185 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01004186
4187 execute( TC_pcu_act_req() );
4188 execute( TC_pcu_act_req_wrong_ts() );
4189 execute( TC_pcu_act_req_wrong_bts() );
4190 execute( TC_pcu_act_req_wrong_trx() );
4191 execute( TC_pcu_deact_req() );
4192 execute( TC_pcu_deact_req_wrong_ts() );
4193 execute( TC_pcu_ver_si13() );
4194 execute( TC_pcu_data_req_wrong_bts() );
4195 execute( TC_pcu_data_req_wrong_trx() );
4196 execute( TC_pcu_data_req_wrong_ts() );
4197 execute( TC_pcu_data_req_ts_inactive() );
4198 execute( TC_pcu_data_req_pdtch() );
4199 execute( TC_pcu_data_req_ptcch() );
4200 execute( TC_pcu_data_req_agch() );
4201 execute( TC_pcu_data_req_imm_ass_pch() );
4202 execute( TC_pcu_rach_content() );
4203 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02004204
4205 execute( TC_dyn_osmo_pdch_act_deact() );
4206 execute( TC_dyn_osmo_pdch_unsol_deact() );
4207 execute( TC_dyn_osmo_pdch_double_act() );
4208 execute( TC_dyn_osmo_pdch_tchf_act() );
4209 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02004210 execute( TC_dyn_ipa_pdch_act_deact() );
4211 execute( TC_dyn_ipa_pdch_tchf_act() );
4212 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
4213 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01004214
4215 execute( TC_rll_est_ind() );
4216 execute( TC_rll_est_req_DCCH_3() );
4217 execute( TC_rll_est_req_ACCH_3() );
4218 execute( TC_rll_rel_ind_DCCH_0() );
4219 execute( TC_rll_rel_ind_DCCH_3() );
4220 execute( TC_rll_rel_ind_ACCH_0() );
4221 execute( TC_rll_rel_ind_ACCH_3() );
4222 execute( TC_rll_rel_req() );
4223 execute( TC_rll_unit_data_req_DCCH() );
4224 execute( TC_rll_unit_data_req_ACCH() );
4225 execute( TC_rll_unit_data_ind_DCCH() );
4226 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02004227
4228 execute( TC_chan_act_a51() );
4229 execute( TC_chan_act_a52() );
4230 execute( TC_chan_act_a53() );
4231 execute( TC_encr_cmd_a51() );
4232 execute( TC_encr_cmd_a52() );
4233 execute( TC_encr_cmd_a53() );
4234
4235 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02004236
4237 execute( TC_tch_sign_l2_fill_frame() );
4238 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004239
4240 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004241 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01004242}
4243
4244
4245}