blob: 0ee3cd4b7208c60ffd29f3ad61c745c51d5e0b5d [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +01004import from General_Types all;
5import from GSM_Types all;
6import from GSM_RR_Types all;
7import from Osmocom_Types all;
8import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +01009import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010010import from L1CTL_PortType all;
11import from L1CTL_Types all;
12import from LAPDm_Types all;
13import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020014import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010015
16import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010017import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010018import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020019import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010020import from RSL_Emulation all;
21
22import from IPL4asp_Types all;
23import from TRXC_Types all;
24import from TRXC_CodecPort all;
25import from TRXC_CodecPort_CtrlFunct all;
26
Harald Welte883340c2018-02-28 18:59:29 +010027import from PCUIF_Types all;
28import from PCUIF_CodecPort all;
29
Harald Welte7484fc42018-02-24 14:09:45 +010030import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010031import from MobileL3_RRM_Types all;
32import from MobileL3_Types all;
33import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010034
Harald Welte8da48242018-02-27 20:41:32 +010035import from Osmocom_VTY_Functions all;
36import from TELNETasp_PortType all;
37
Harald Welte70767382018-02-21 12:16:40 +010038/* The tests assume a BTS with the following timeslot configuration:
39 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020040 * TS1 : TCH/F
41 * TS2 : TCH/F
42 * TS3 : TCH/F_PDCH (IPA Style)
43 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010044 * TS5 : TCH/H
45 * TS6 : SDCCH/8
46 * TS7 : PDCH
47 */
48
49modulepar {
50 charstring mp_rsl_ip := "127.0.0.2";
51 integer mp_rsl_port := 3003;
52 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070053 charstring mp_bts_trxc_ip := "127.0.0.1";
54 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010055 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020056 charstring mp_ctrl_ip := "127.0.0.1";
57 integer mp_ctrl_port := 4238;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020058 integer mp_tolerance_rxqual := 1;
59 integer mp_tolerance_rxlev := 3;
60 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020061 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020062 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020063 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020064 integer mp_ms_actual_ta_exp := 0;
65 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010066 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020067 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020068 float mp_ipa_up_delay := 0.0;
Harald Welte70767382018-02-21 12:16:40 +010069}
70
Harald Welte629cc6b2018-03-11 17:19:05 +010071type record of RslChannelNr ChannelNrs;
72
Harald Welte70767382018-02-21 12:16:40 +010073type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010074 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010075 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010076 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010077 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010078 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010079 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010080
81 /* L1CTL port (for classic tests) */
82 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010083
Harald Welte54a2a2d2018-02-26 09:14:05 +010084 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070085 port TRXC_CODEC_PT BTS_TRXC;
86 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +010087
Harald Weltef50e3ae2018-09-10 10:27:56 +020088 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010089 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +020090 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +010091
Harald Welte883340c2018-02-28 18:59:29 +010092 /* PCU Interface of BTS */
93 port PCUIF_CODEC_PT PCU;
94 var integer g_pcu_conn_id;
95 /* Last PCU INFO IND we received */
96 var PCUIF_Message g_pcu_last_info;
97
Harald Welte48494ca2018-02-25 16:59:50 +010098 /* SI configuration */
99 var SystemInformationConfig si_cfg := {
100 bcch_extended := false,
101 si1_present := false,
102 si2bis_present := false,
103 si2ter_present := false,
104 si2quater_present := false,
105 si7_present := false,
106 si8_present := false,
107 si9_present := false,
108 si13_present := false,
109 si13alt_present := false,
110 si15_present := false,
111 si16_present := false,
112 si17_present := false,
113 si2n_present := false,
114 si21_present := false,
115 si22_present := false
116 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100117
118 /* all logical channels available on the BTS */
119 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100120 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
123/* an individual call / channel */
124type component ConnHdlr extends RSL_DchanHdlr {
125 port L1CTL_PT L1CTL;
126
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700127 port TRXC_CODEC_PT BTS_TRXC;
128 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100129
130 timer g_Tguard;
131 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
132
133 var ConnHdlrPars g_pars;
134 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100135 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200136
137 /* PCU Interface of BTS */
138 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100139}
140
141function f_init_rsl(charstring id) runs on test_CT {
142 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
143 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
144
145 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
146 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
147 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
148
149 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
150 vc_RSL.start(RSL_Emulation.main(false));
151}
152
153type record ConnHdlrPars {
154 RslChannelNr chan_nr,
155 RSL_IE_ChannelMode chan_mode,
156 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100157 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200158 TestSpecUnion spec optional,
159 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100160}
161
162/* Test-specific parameters */
163type union TestSpecUnion {
164 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100165}
166
Harald Welte82ccef72018-02-25 16:17:33 +0100167template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100168 max_retrans := RACH_MAX_RETRANS_7,
169 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100170 cell_barr_access := false,
171 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100172 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100173};
174
Harald Weltef10153f2018-02-25 16:34:05 +0100175template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100176 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200177 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100178 acs := '0'B,
179 neci := true,
180 rxlev_access_min := 0
181}
182
183template (value) LocationAreaIdentification ts_LAI_default := {
184 mcc_mnc := '262F42'H,
185 lac := 42
186}
187
Harald Welte7484fc42018-02-24 14:09:45 +0100188/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100189template (value) SystemInformation ts_SI3_default := {
190 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100191 payload := {
192 si3 := {
193 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100194 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100195 ctrl_chan_desc := {
196 msc_r99 := true,
197 att := true,
198 bs_ag_blks_res := 1,
199 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100200 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100201 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
202 spare := '00'B,
203 bs_pa_mfrms := 0, /* 2 multiframes */
204 t3212 := 1 /* 6 minutes */
205 },
Harald Welte82ccef72018-02-25 16:17:33 +0100206 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100207 dn_ind := false,
208 pwrc := false,
209 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100210 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100211 },
Harald Weltef10153f2018-02-25 16:34:05 +0100212 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100213 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100214 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100215 }
216 }
217}
Harald Welte70767382018-02-21 12:16:40 +0100218
Harald Weltef8df4cb2018-03-10 15:15:08 +0100219template (value) SystemInformation ts_SI2_default := {
220 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100221 payload := {
222 si2 := {
223 bcch_freq_list := '00000000000000000000000000000000'O,
224 ncc_permitted := '11111111'B,
225 rach_control := ts_RachCtrl_default
226 }
227 }
228}
229
Harald Weltef8df4cb2018-03-10 15:15:08 +0100230template (value) SystemInformation ts_SI4_default := {
231 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100232 payload := {
233 si4 := {
234 lai := ts_LAI_default,
235 cell_sel_par := ts_CellSelPar_default,
236 rach_control := ts_RachCtrl_default,
237 cbch_chan_desc := omit,
238 cbch_mobile_alloc := omit,
239 rest_octets := ''O
240 }
241 }
242}
243
244function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
245runs on test_CT {
246 log("Setting ", rsl_si_type, ": ", si_enc);
247 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
248}
249
250function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
251runs on test_CT {
252 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
253 log("Setting ", rsl_si_type, ": ", si_dec);
254 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
255}
256
Harald Welte8da48242018-02-27 20:41:32 +0100257private function f_init_vty(charstring id) runs on test_CT {
258 map(self:BTSVTY, system:BTSVTY);
259 f_vty_set_prompts(BTSVTY);
260 f_vty_transceive(BTSVTY, "enable");
261}
262
Harald Weltef50e3ae2018-09-10 10:27:56 +0200263private function f_init_vty_bsc() runs on test_CT {
264 map(self:BSCVTY, system:BSCVTY);
265 f_vty_set_prompts(BSCVTY, "OsmoBSC");
266 f_vty_transceive(BSCVTY, "enable");
267}
268
Harald Welte883340c2018-02-28 18:59:29 +0100269/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200270private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
271 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100272 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200273 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
274 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100275 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200276 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100278 }
279}
280
Harald Weltef26de0b2018-04-04 20:28:05 +0200281private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
282 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100283 timer T := 2.0;
284 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100285 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200286 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100287 return;
288 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200289 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100290
291 T.start;
292 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200293 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100294 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100296 }
297 }
298}
299
Harald Welte70767382018-02-21 12:16:40 +0100300/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100301function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100302 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100303 g_AllChannels := {
304 /* TS 1..4: TCH/F */
305 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
306 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
307 /* TS 5: TCH/H */
308 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
309 /* TS 0: SDCCH/4 */
310 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
311 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
312 /* TS 6: SDCCH/8 */
313 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
314 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
315 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
316 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
317 };
318
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200319 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700320 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200321 g_AllChanTypes := {
322 /* TS 1..4: TCH/F */
323 valueof(ts_RslChanNr_Bm(1)),
324 /* TS 5: TCH/H */
325 valueof(ts_RslChanNr_Lm(5,1)),
326 /* TS 0: SDCCH/4 */
327 valueof(ts_RslChanNr_SDCCH4(0,2)),
328 /* TS 6: SDCCH/8 */
329 valueof(ts_RslChanNr_SDCCH8(6,4))
330 };
331 } else {
332 g_AllChanTypes := {
333 /* TS 1..4: TCH/F */
334 valueof(ts_RslChanNr_Bm(1)),
335 /* TS 0: SDCCH/4 */
336 valueof(ts_RslChanNr_SDCCH4(0,2)),
337 /* TS 6: SDCCH/8 */
338 valueof(ts_RslChanNr_SDCCH8(6,4))
339 };
340 }
Harald Welte70767382018-02-21 12:16:40 +0100341 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200342 T.start;
343 alt {
344 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
345 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200347 }
348 }
Harald Welte2d142592018-02-25 13:19:44 +0100349 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100350 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200351 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100352
353 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100354 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
355 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
356 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
357 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100358
Harald Weltef26de0b2018-04-04 20:28:05 +0200359 map(self:PCU, system:PCU);
360 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100361
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700362 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100363 var TrxcMessage ret;
364 /* start with a default moderate timing offset equalling TA=2 */
365 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700366 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte84271622018-03-10 17:21:03 +0100367 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200368
369 /* Wait some extra time to make sure the BTS emits a stable carrier.
370 * (this is only relevant when running the tests with a physical BTS.) */
371 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100372}
373
Harald Welte68e495b2018-02-25 00:05:57 +0100374/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
375function f_init_l1ctl() runs on test_CT {
376 map(self:L1CTL, system:L1CTL);
377 f_connect_reset(L1CTL);
378}
379
Harald Welte70767382018-02-21 12:16:40 +0100380type function void_fn(charstring id) runs on ConnHdlr;
381
382/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200383function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100384runs on test_CT return ConnHdlr {
385 var charstring id := testcasename();
386 var ConnHdlr vc_conn;
387
388 vc_conn := ConnHdlr.create(id);
389 /* connect to RSL Emulation main component */
390 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
391 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200392 if (pcu_comp) {
393 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
394 * it from the test_CT and connect it to the component. This obviously only
395 * works for one component, i.e. no concurrency */
396 unmap(self:PCU, system:PCU);
397 map(vc_conn:PCU, system:PCU);
398 }
Harald Welte70767382018-02-21 12:16:40 +0100399
400 vc_conn.start(f_handler_init(fn, id, pars));
401 return vc_conn;
402}
403
Harald Welte7484fc42018-02-24 14:09:45 +0100404template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
405 streamId := sid,
406 rsl := rsl
407}
408
409template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
410 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
411 streamId := sid,
412 rsl := rsl
413}
414
Harald Welte70767382018-02-21 12:16:40 +0100415private altstep as_Tguard() runs on ConnHdlr {
416 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100418 }
419}
420
Harald Welte68e495b2018-02-25 00:05:57 +0100421private function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200422 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100423}
424
425private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700426 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100427 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700428 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100429 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200430 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200431 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 +0200432 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700433 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100434}
435
436private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100437 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700438 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100439}
440
441private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100442 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700443 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100444}
445
446/* first function started in ConnHdlr component */
447private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
448runs on ConnHdlr {
449 g_pars := pars;
450 g_chan_nr := pars.chan_nr;
451
452 map(self:L1CTL, system:L1CTL);
453 f_connect_reset(L1CTL);
454
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700455 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100456 f_trxc_connect();
457 }
Harald Welte70767382018-02-21 12:16:40 +0100458
459 g_Tguard.start(pars.t_guard);
460 activate(as_Tguard());
461
462 f_rslem_register(0, pars.chan_nr);
463
464 /* call the user-supplied test case function */
465 fn.apply(id);
466}
467
Harald Welteb1726c92018-03-30 11:56:38 +0200468function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
469 boolean ignore_other := false)
470runs on ConnHdlr return RSL_Message {
471 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100472 timer T := 3.0;
473 RSL.send(tx);
474 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100475 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200476 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100477 T.stop;
478 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100479 }
Harald Welte1eba3742018-02-25 12:48:14 +0100480 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100482 }
Harald Welte21240e62018-03-11 21:43:35 +0100483 [not ignore_other] as_l1_sacch();
484 [not ignore_other] as_meas_res();
485 [not ignore_other] as_l1_dcch();
486 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100488 }
Harald Welte21240e62018-03-11 21:43:35 +0100489 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100490 }
Harald Welteb1726c92018-03-30 11:56:38 +0200491 return rx;
492}
493
494function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
495 boolean ignore_other := false)
496runs on ConnHdlr {
497 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100498}
499
Harald Weltec8d363c2019-05-19 20:36:48 +0200500function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {})
Harald Weltee613f962018-04-18 22:38:16 +0200501runs on ConnHdlr {
502 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
503 if (encr_enable) {
504 /* append encryption related IEs, if requested */
505 var RSL_IE_EncryptionInfo encr_info;
506 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
507 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
508encr_info})) };
509 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200510 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200511 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100512}
513
Harald Welte70767382018-02-21 12:16:40 +0100514function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100515 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 +0100516 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100517}
518
Harald Welte70767382018-02-21 12:16:40 +0100519private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
520 template RSL_IE_ChannelMode chan_mode,
521 float t_guard := 20.0) := {
522 chan_nr := valueof(chan_nr),
523 chan_mode := valueof(chan_mode),
524 t_guard := t_guard,
525 l1_pars := {
526 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100527 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100528 meas_ul := {
529 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200530 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100531 rxqual := 0
532 },
533 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200534 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100535 rxqual := 0
536 }
537 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200538 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100539 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200540 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200541 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100542 },
Harald Weltee613f962018-04-18 22:38:16 +0200543 spec := omit,
544 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100545}
546
Harald Welte93640c62018-02-25 16:59:33 +0100547/***********************************************************************
548 * Channel Activation / Deactivation
549 ***********************************************************************/
550
Harald Welte70767382018-02-21 12:16:40 +0100551/* Stress test: Do 500 channel activations/deactivations in rapid succession */
552function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
553 for (var integer i := 0; i < 500; i := i+1) {
554 f_rsl_chan_act(g_pars.chan_mode);
555 f_rsl_chan_deact();
556 }
557 setverdict(pass);
558}
559testcase TC_chan_act_stress() runs on test_CT {
560 var ConnHdlr vc_conn;
561 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
562 f_init(testcasename());
563 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
564 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100566}
567
568/* Test if re-activation of an already active channel fails as expected */
569function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
570 f_rsl_chan_act(g_pars.chan_mode);
571 /* attempt to activate the same lchan again -> expect reject */
572 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
573 alt {
574 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100576 }
577 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
578 setverdict(pass);
579 }
580 }
581 f_rsl_chan_deact();
582}
583testcase TC_chan_act_react() runs on test_CT {
584 var ConnHdlr vc_conn;
585 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100586 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100587 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
588 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100590}
591
592/* Attempt to de-activate a channel that's not active */
593function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
594 timer T := 3.0;
595 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
596 T.start;
597 alt {
598 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
599 setverdict(pass);
600 }
601 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100603 }
604 }
605}
606testcase TC_chan_deact_not_active() runs on test_CT {
607 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100608 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100609 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
610 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100612}
613
614/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
615function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
616 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
617 alt {
618 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100620 }
621 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
622 setverdict(pass);
623 }
624 }
625}
626private type record WrongChanNrCase {
627 RslChannelNr chan_nr,
628 charstring description
629}
630private type record of WrongChanNrCase WrongChanNrCases;
631private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
632 chan_nr := chan_nr,
633 description := desc
634}
635
636testcase TC_chan_act_wrong_nr() runs on test_CT {
637 var ConnHdlr vc_conn;
638 var ConnHdlrPars pars;
639
Harald Welte294b0a22018-03-10 23:26:48 +0100640 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100641
642 var WrongChanNrCases wrong := {
643 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
644 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
645 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
646 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
647 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
648 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
649 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
650 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
651 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
652 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
653 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
654 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
655 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
656 };
657
658 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
659 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
660 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
661 vc_conn.done;
662 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100664}
665
Harald Weltee613f962018-04-18 22:38:16 +0200666/* execute the same callback function on a variety of logical channels */
667private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
668 var ConnHdlr vc_conn;
669 f_init(testcasename());
670
671 /* test on each of the channels we have */
672 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
673 pars.chan_nr := valueof(g_AllChanTypes[i]);
674
675 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
676 vc_conn := f_start_handler(fn, pars);
677 vc_conn.done;
678 }
679
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200681}
682
Harald Welte93640c62018-02-25 16:59:33 +0100683/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100684 * SACCH handling
685 ***********************************************************************/
686
687private function f_exp_sacch(boolean exp) runs on ConnHdlr {
688 timer T_sacch := 3.0;
689 T_sacch.start;
690 alt {
691 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100693 }
694 [not exp] T_sacch.timeout {
695 setverdict(pass);
696 }
697 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
698 setverdict(pass);
699 }
700 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100702 }
703 [] L1CTL.receive { repeat; }
704 [] RSL.receive { repeat; }
705 }
706}
707
708/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
709private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
710 f_l1_tune(L1CTL);
711 RSL.clear;
712
713 /* activate the logical channel */
714 f_est_dchan();
715 L1CTL.clear;
716
717 /* check that SACCH actually are received as expected */
718 f_exp_sacch(true);
719
720 /* deactivate SACCH on the logical channel */
721 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
722 f_sleep(1.0);
723 L1CTL.clear;
724
725 /* check that no SACCH are received anymore */
726 f_exp_sacch(false);
727
728 /* release the channel */
729 f_rsl_chan_deact();
730 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
731}
732testcase TC_deact_sacch() runs on test_CT {
733 var ConnHdlr vc_conn;
734 var ConnHdlrPars pars;
735 f_init();
736 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
737 //for (var integer i := 0; i < 1; i := i+1) {
738 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
739 log(testcasename(), ": Starting for ", g_AllChannels[i]);
740 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
741 vc_conn.done;
742 }
743 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100745}
746
Harald Welte55700662018-03-12 13:15:43 +0100747/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100748private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
749 var L1ctlDlMessage dl;
750 /* check that the specified SI5 value is actually sent */
751 timer T_sacch := 3.0;
752 L1CTL.clear;
753 T_sacch.start;
754 alt {
755 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
756 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
757 if (match(l3, l3_exp)) {
758 setverdict(pass);
759 } else {
760 repeat;
761 }
762 }
763 [] L1CTL.receive { repeat; }
764 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100766 }
767 }
768}
769
Harald Welte55700662018-03-12 13:15:43 +0100770/* verify that given SACCH payload is not present */
771private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
772 var L1ctlDlMessage dl;
773 /* check that the specified SI5 value is actually sent */
774 timer T_sacch := 3.0;
775 L1CTL.clear;
776 T_sacch.start;
777 alt {
778 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
779 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
780 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100782 } else {
783 repeat;
784 }
785 }
786 [] L1CTL.receive { repeat; }
787 [] T_sacch.timeout {
788 setverdict(pass);
789 }
790 }
791}
792
Harald Welte629cc6b2018-03-11 17:19:05 +0100793/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100794private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
795 /* Set a known default SACCH filling for SI5 */
796 var octetstring si5 := f_rnd_octstring(19);
797 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
798
799 f_l1_tune(L1CTL);
800 RSL.clear;
801
802 /* activate the logical channel */
803 f_est_dchan();
804
805 /* check that the specified SI5 value is actually sent */
806 f_sacch_present(si5);
807
808 /* release the channel */
809 RSL.clear;
810 f_rsl_chan_deact();
811 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
812}
813testcase TC_sacch_filling() runs on test_CT {
814 var ConnHdlr vc_conn;
815 var ConnHdlrPars pars;
816 f_init();
817 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
818 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
819 log(testcasename(), ": Starting for ", g_AllChannels[i]);
820 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
821 vc_conn.done;
822 }
823 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100825}
826
Harald Welte629cc6b2018-03-11 17:19:05 +0100827/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100828private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
829 /* Set a known default SACCH filling for SI5 */
830 var octetstring si5 := f_rnd_octstring(19);
831 var octetstring si5_diff := f_rnd_octstring(19);
832 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
833
834 f_l1_tune(L1CTL);
835 RSL.clear;
836
837 log("Activating channel, expecting standard SI5");
838 /* activate the logical channel */
839 f_est_dchan();
840 /* check that the specified SI5 value is actually sent */
841 f_sacch_present(si5);
842
843 /* set channel-specific different SI5 */
844 log("Setting channel specific SACCH INFO, expecting it");
845 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
846 /* check that the specified lchan-specific value is now used */
847 f_sacch_present(si5_diff);
848
849 /* deactivate the channel and re-activate it, this should result in default SI5 */
850 log("De-activating and re-activating channel, expecting standard SI5");
851 f_rsl_chan_deact();
852 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
853 /* Verify that the TRX-wide default SACCH filling is present again */
854 f_sacch_present(si5);
855
856 /* release the channel */
857 RSL.clear;
858 f_rsl_chan_deact();
859 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
860}
861testcase TC_sacch_info_mod() runs on test_CT {
862 var ConnHdlr vc_conn;
863 var ConnHdlrPars pars;
864 f_init();
865 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
866 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
867 log(testcasename(), ": Starting for ", g_AllChannels[i]);
868 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
869 vc_conn.done;
870 }
871 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100873}
874
Harald Welte075d84c2018-03-12 13:07:24 +0100875/* Test SACCH scheduling of multiple different SI message types */
876private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
877 var octetstring si5 := f_rnd_octstring(19);
878 var octetstring si5bis := f_rnd_octstring(19);
879 var octetstring si5ter := f_rnd_octstring(19);
880 var octetstring si6 := f_rnd_octstring(19);
881
882 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
883 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
884 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
885 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
886
887 f_l1_tune(L1CTL);
888 RSL.clear;
889
890 /* activate the logical channel */
891 f_est_dchan();
892 L1CTL.clear;
893
894 /* check that SACCH actually are received as expected */
895 f_sacch_present(si5);
896 f_sacch_present(si5bis);
897 f_sacch_present(si5ter);
898 f_sacch_present(si6);
899
900 /* release the channel */
901 f_rsl_chan_deact();
902 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
903}
904testcase TC_sacch_multi() runs on test_CT {
905 var ConnHdlr vc_conn;
906 var ConnHdlrPars pars;
907 f_init();
908 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
909 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
910 log(testcasename(), ": Starting for ", g_AllChannels[i]);
911 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
912 vc_conn.done;
913 }
914 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100916}
917
Harald Welte55700662018-03-12 13:15:43 +0100918/* Test if SACH information is modified as expected */
919private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
920 var octetstring si5 := f_rnd_octstring(19);
921 var octetstring si6 := f_rnd_octstring(19);
922
923 /* First, configure both SI5 and SI6 to be transmitted */
924 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
925 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
926
927 f_l1_tune(L1CTL);
928 RSL.clear;
929
930 /* activate the logical channel */
931 f_est_dchan();
932 L1CTL.clear;
933
934 /* check that SACCH actually are received as expected */
935 f_sacch_present(si5);
936 f_sacch_present(si6);
937
938 /* disable SI6 */
939 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
940
941 /* check that SI5 is still transmitted */
942 f_sacch_present(si5);
943 /* check if SI6 is now gone */
944 f_sacch_missing(si6);
945
946 /* release the channel */
947 f_rsl_chan_deact();
948 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
949}
950testcase TC_sacch_multi_chg() runs on test_CT {
951 var ConnHdlr vc_conn;
952 var ConnHdlrPars pars;
953 f_init();
954 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
955 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
956 log(testcasename(), ": Starting for ", g_AllChannels[i]);
957 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
958 vc_conn.done;
959 }
960 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100962}
963
Harald Weltec8d363c2019-05-19 20:36:48 +0200964/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
965private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
966 var octetstring si5 := f_rnd_octstring(19);
967 var octetstring si6 := f_rnd_octstring(19);
968 var octetstring si5_specific := f_rnd_octstring(19);
969 var octetstring si6_specific := f_rnd_octstring(19);
970
971 /* First, configure both SI5 and SI6 to be transmitted */
972 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
973 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
974
975 f_l1_tune(L1CTL);
976 RSL.clear;
977
978 /* activate channel with different SACCH filling */
979 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
980 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
981 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
982 }));
983 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
984 RSL_IE_Body:{sacch_info := sacch_info})) };
985 f_est_dchan(more_ies := addl_ies);
986
987 /* check that SACCH actually are received as expected */
988 f_sacch_present(si5_specific);
989 f_sacch_present(si6_specific);
990
991 /* release the channel */
992 f_rsl_chan_deact();
993 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
994}
995testcase TC_sacch_chan_act() runs on test_CT {
996 var ConnHdlr vc_conn;
997 var ConnHdlrPars pars;
998 f_init();
999
1000 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1001 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1002 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1003 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1004 vc_conn.done;
1005 }
1006 /* TODO: do the above in parallel, rather than sequentially? */
1007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1008}
1009
Harald Welte075d84c2018-03-12 13:07:24 +01001010/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +01001011
1012
1013/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001014 * RACH Handling
1015 ***********************************************************************/
1016
Harald Welte8c24c2b2018-02-26 08:31:31 +01001017/* like L1SAP_IS_PACKET_RACH */
1018private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001019 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001020 return true;
1021 }
1022 return false;
1023}
1024
1025/* generate a random RACH for circuit-switched */
1026private function f_rnd_ra_cs() return OCT1 {
1027 var OCT1 ra;
1028 do {
1029 ra := f_rnd_octstring(1);
1030 } while (ra_is_ps(ra));
1031 return ra;
1032}
1033
Harald Welte883340c2018-02-28 18:59:29 +01001034/* generate a random RACH for packet-switched */
1035private function f_rnd_ra_ps() return OCT1 {
1036 var OCT1 ra;
1037 do {
1038 ra := f_rnd_octstring(1);
1039 } while (not ra_is_ps(ra));
1040 return ra;
1041}
1042
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001043/* generate a random 11-bit RA (packet-switched only) */
1044private function f_rnd_ra11_ps() return BIT11 {
1045 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1046 return int2bit(ra11, 11);
1047}
1048
Harald Welte8c24c2b2018-02-26 08:31:31 +01001049/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1050testcase TC_rach_content() runs on test_CT {
1051 f_init(testcasename());
1052 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001053 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001054
Harald Welte8c24c2b2018-02-26 08:31:31 +01001055 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001056 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001057 for (var integer i := 0; i < 1000; i := i+1) {
1058 var OCT1 ra := f_rnd_ra_cs();
1059 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1060 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001062 }
1063 fn_last := fn;
1064
1065 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001066 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001067 alt {
1068 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1069 T.stop;
1070 }
1071 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001073 }
1074 [] RSL_CCHAN.receive { repeat; }
1075 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001076 test_failed := true;
1077 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001078 }
1079 }
1080 }
Maxba06feb2019-03-05 10:52:46 +01001081 if (test_failed) {
1082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001083 }
Maxba06feb2019-03-05 10:52:46 +01001084 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001086}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001087
1088/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1089testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001090 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001091 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001092 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001093 f_l1_tune(L1CTL);
1094
1095 var GsmFrameNumber fn_last := 0;
1096 for (var integer i := 0; i < 1000; i := i+1) {
1097 var OCT1 ra := f_rnd_ra_cs();
1098 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1099 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001101 }
1102 fn_last := fn;
1103 }
1104 var integer rsl_chrqd := 0;
1105 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001106 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001107 alt {
1108 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1109 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001110 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001111 repeat;
1112 }
1113 [] RSL_CCHAN.receive { repeat; }
1114 [] T.timeout { }
1115 }
1116 if (rsl_chrqd == 1000) {
1117 setverdict(pass);
1118 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001120 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001122}
1123
Harald Welte54a2a2d2018-02-26 09:14:05 +01001124private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001125 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001126 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001127 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001128 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001129 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001130 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 +02001131 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001132 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001133}
1134
1135private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001136 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001137 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001138 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001139 f_sleep(0.5);
1140
1141 /* Transmit RACH request + wait for confirmation */
1142 var OCT1 ra := f_rnd_ra_cs();
1143 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1144
1145 /* Check for expected result */
1146 timer T := 1.5;
1147 T.start;
1148 alt {
1149 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1150 setverdict(pass);
1151 }
1152 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001154 }
1155 [] RSL_CCHAN.receive { repeat; }
1156 [not expect_pass] T.timeout {
1157 setverdict(pass);
1158 }
1159 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001161 }
1162 }
1163}
1164
1165/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1166testcase TC_rach_max_ta() runs on test_CT {
1167 f_init(testcasename());
1168 f_init_l1ctl();
1169 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001170 f_sleep(1.0);
1171
1172 /* default max-ta is 63 (full range of GSM timing advance */
1173
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001174 /* We allow early arrival up to 2 symbols */
1175 f_rach_toffs(-1*256, true);
1176 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001177 f_rach_toffs(-10*256, false);
1178
1179 /* 0 / 32 / 63 bits is legal / permitted */
1180 f_rach_toffs(0, true);
1181 f_rach_toffs(32*256, true);
1182 f_rach_toffs(63*256, true);
1183
1184 /* more than 63 bits is not legal / permitted */
1185 f_rach_toffs(64*256, false);
1186 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001188}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001189
Harald Welte93640c62018-02-25 16:59:33 +01001190/***********************************************************************
1191 * Measurement Processing / Reporting
1192 ***********************************************************************/
1193
Harald Welte70767382018-02-21 12:16:40 +01001194template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1195 spare := '0'B,
1196 lpd := 0,
1197 sapi := sapi,
1198 c_r := c_r,
1199 ea := true
1200}
1201
Harald Welted879bd92018-03-12 15:01:23 +01001202template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001203 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001204 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001205 len := 0, /* overwritten */
1206 m := false,
1207 el := 1,
1208 payload := pl
1209}
1210
1211/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1212altstep as_l1_sacch() runs on ConnHdlr {
1213 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001214 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001215 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001216 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 +01001217 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001218 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001219
1220 var L1ctlDataReq data_req := {
1221 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1222 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1223 }
1224 log("Sending Measurement Report: ", data_req);
1225 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001226 repeat;
1227 }
1228}
1229
1230altstep as_l1_dcch() runs on ConnHdlr {
1231 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001232 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001233 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1234 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001235 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1236 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001237 repeat;
1238 }
1239}
1240
1241type record MeasElem {
1242 uint6_t rxlev,
1243 uint3_t rxqual
1244}
1245
1246type record MeasElemFS {
1247 MeasElem full,
1248 MeasElem sub
1249}
1250
1251type record ConnL1Pars {
1252 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001253 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001254 MeasElemFS meas_ul,
1255 int16_t timing_offset_256syms,
1256 uint5_t bs_power_level,
1257 uint5_t ms_power_level,
1258 uint8_t ms_actual_ta
1259}
1260
1261/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1262private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1263 return 63 + (toffs256s/256);
1264}
1265
Harald Welted5684392018-03-10 18:22:04 +01001266private function f_max(integer a, integer b) return integer {
1267 if (a > b) {
1268 return a;
1269 } else {
1270 return b;
1271 }
1272}
1273
1274private function f_min(integer a, integer b) return integer {
1275 if (a < b) {
1276 return a;
1277 } else {
1278 return b;
1279 }
1280}
1281
1282/* compute negative tolerance val-tolerance, ensure >= min */
1283private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1284 val := val - tolerance;
1285 return f_max(val, min);
1286}
1287
1288/* compute positive tolerance val+tolerance, ensure <= max */
1289private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1290 val := val + tolerance;
1291 return f_min(val, max);
1292}
1293
1294/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1295private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1296return template integer {
1297 var template integer ret;
1298 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1299 return ret;
1300}
1301
1302
Harald Welte70767382018-02-21 12:16:40 +01001303/* build a template for matching measurement results against */
1304private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1305 var ConnL1Pars l1p := g_pars.l1_pars;
1306 var template RSL_IE_UplinkMeas ul_meas := {
1307 len := 3,
1308 rfu := '0'B,
1309 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001310 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001311 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001312 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001313 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001314 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1315 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001316 supp_meas_info := omit
1317 };
Harald Welte685d5982018-02-27 20:42:05 +01001318 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001319 ul_meas.len := (3+8);
1320 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001321 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001322 toa256_min := ?,
1323 toa256_max := ?,
1324 toa256_std_dev := ?
1325 }
Harald Welte685d5982018-02-27 20:42:05 +01001326 }
Harald Welte70767382018-02-21 12:16:40 +01001327 var template RSL_IE_BS_Power bs_power := {
1328 reserved := 0,
1329 epc := false,
1330 fpc := false,
1331 power_level := l1p.bs_power_level
1332 };
1333 var template RSL_IE_L1Info l1_info := {
1334 ms_power_lvl := l1p.ms_power_level,
1335 fpc := false,
1336 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001337 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001338 };
1339 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001340 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001341 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1342 ?, t_toffs);
1343}
1344
1345/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001346altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001347 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001348 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001349 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1350 /* increment counter of next to-be-expected meas rep */
1351 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1352 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001353 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001354 repeat;
1355 }
1356 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001357 /* increment counter of next to-be-expected meas rep */
1358 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1359 if (g_first_meas_res) {
1360 g_first_meas_res := false;
1361 repeat;
1362 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001364 }
Harald Welte70767382018-02-21 12:16:40 +01001365 }
1366 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001368 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001369 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001371 }
1372}
1373
Harald Weltee613f962018-04-18 22:38:16 +02001374private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1375 select (rsl_alg_id) {
1376 case (RSL_ALG_ID_A5_0) { return 0; }
1377 case (RSL_ALG_ID_A5_1) { return 1; }
1378 case (RSL_ALG_ID_A5_2) { return 2; }
1379 case (RSL_ALG_ID_A5_3) { return 3; }
1380 case (RSL_ALG_ID_A5_4) { return 4; }
1381 case (RSL_ALG_ID_A5_5) { return 5; }
1382 case (RSL_ALG_ID_A5_6) { return 6; }
1383 case (RSL_ALG_ID_A5_7) { return 7; }
1384 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1386 /* Make compiler happy by calling mtc.stop here. It is already
1387 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001388 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001389 }
1390 }
1391}
1392
1393private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1394 select (rsl_alg_id) {
1395 case (RSL_ALG_ID_A5_1) { return '000'B; }
1396 case (RSL_ALG_ID_A5_2) { return '001'B; }
1397 case (RSL_ALG_ID_A5_3) { return '010'B; }
1398 case (RSL_ALG_ID_A5_4) { return '011'B; }
1399 case (RSL_ALG_ID_A5_5) { return '100'B; }
1400 case (RSL_ALG_ID_A5_6) { return '101'B; }
1401 case (RSL_ALG_ID_A5_7) { return '110'B; }
1402 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1404 /* Make compiler happy by calling mtc.stop here. It is already
1405 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001406 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001407 }
1408 }
1409}
1410
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001411/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1412private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1413 var GsmFrameNumber fn;
1414 timer T := 8.0;
1415
1416 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1417 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1418
1419 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1420 /* Send the actual RACH */
1421 fn := f_L1CTL_RACH(L1CTL, ra);
1422
1423 T.start;
1424 alt {
1425 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1426 [] T.timeout {
1427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1428 }
1429 }
1430 T.stop
1431 return fn;
1432}
Harald Weltee613f962018-04-18 22:38:16 +02001433
Harald Welte70767382018-02-21 12:16:40 +01001434/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001435private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001436 var GsmFrameNumber fn;
1437 var ImmediateAssignment imm_ass;
1438 var integer ra := 23;
1439
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001440 /* Send RACH request and wait for ChanReq */
1441 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001442
1443 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001444 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001445
1446 /* Send IMM.ASS via CCHAN */
1447 var ChannelDescription ch_desc := {
1448 chan_nr := g_pars.chan_nr,
1449 tsc := 7,
1450 h := false,
1451 arfcn := mp_trx0_arfcn,
1452 maio_hsn := omit
1453 };
1454 var MobileAllocation ma := {
1455 len := 0,
1456 ma := ''B
1457 };
1458 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1459 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1460
1461 /* receive IMM.ASS on MS side */
1462 var ImmediateAssignment ia_um;
1463 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1464 /* enable dedicated mode */
1465 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001466 /* enable encryption, if requested */
1467 if (encr_enable) {
1468 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1469 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1470 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001471
1472 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001473}
1474
1475/* establish DChan, verify existance + contents of measurement reports */
1476function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001477 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001478 RSL.clear;
1479
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001480 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001481 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001482 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1483 }
Harald Welte70767382018-02-21 12:16:40 +01001484
1485 f_est_dchan();
1486
1487 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1488 * RSL measurement reports on Abis side */
1489 timer T := 8.0;
1490 T.start;
1491 alt {
1492 [] as_l1_sacch();
1493 [] as_meas_res();
1494 [] as_l1_dcch();
1495 [] L1CTL.receive { repeat; }
1496 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001497 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001498 * of any earlier errors, so if we reach this timeout, we're good */
1499 setverdict(pass);
1500 }
1501 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001503 }
1504 }
1505 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001506 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001507}
Harald Welte0472ab42018-03-12 15:02:26 +01001508
Harald Welte70767382018-02-21 12:16:40 +01001509testcase TC_meas_res_sign_tchf() runs on test_CT {
1510 var ConnHdlr vc_conn;
1511 var ConnHdlrPars pars;
1512 f_init(testcasename());
1513 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1514 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1515 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1516 vc_conn.done;
1517 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001519}
1520testcase TC_meas_res_sign_tchh() runs on test_CT {
1521 var ConnHdlr vc_conn;
1522 var ConnHdlrPars pars;
1523 f_init(testcasename());
1524 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1525 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1526 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1527 vc_conn.done;
1528 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001530}
1531testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1532 var ConnHdlr vc_conn;
1533 var ConnHdlrPars pars;
1534 f_init(testcasename());
1535 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1536 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1537 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1538 vc_conn.done;
1539 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001541}
1542testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1543 var ConnHdlr vc_conn;
1544 var ConnHdlrPars pars;
1545 f_init(testcasename());
1546 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1547 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1548 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1549 vc_conn.done;
1550 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001552}
Harald Welte685d5982018-02-27 20:42:05 +01001553testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1554 var ConnHdlr vc_conn;
1555 var ConnHdlrPars pars;
1556 f_init(testcasename());
1557 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1558 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1559 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1560 pars.l1_pars.toa256_enabled := true;
1561 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1562 vc_conn.done;
1563 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001565}
1566
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001567/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1568 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1569function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1570 var L1ctlDlMessage l1_dl;
1571 var RSL_IE_MS_Power ms_power;
1572 var RSL_Message rsl;
1573 var uint5_t power_level := 0;
1574
1575 f_l1_tune(L1CTL);
1576 RSL.clear;
1577
1578 f_est_dchan();
1579
1580 ms_power.reserved := 0;
1581 ms_power.fpc_epc := false;
1582
1583 /* Send the first power control command. This will disable any BTS/TRX
1584 * internal power control and switch the MS (which is not in scope of
1585 * this test) to a constant power level. We start with a power level
1586 * of 0 */
1587 ms_power.power_level := power_level;
1588 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1589 RSL.send(rsl);
1590
1591 alt {
1592
1593 /* Pick all SACCH blocks for checking */
1594 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1595
1596 /* The first byte of the L1 header contains the power level.
1597 * The reserved bits and the fpc bit is set to 0, so we may
1598 * compare directly. */
1599 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1600 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1601 }
1602
1603 /* Signal a new power level via RSL for the next turn. */
1604 if (power_level < 31) {
1605 power_level := power_level + 1;
1606 ms_power.power_level := power_level;
1607 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1608 RSL.send(rsl);
1609 repeat;
1610 }
1611
1612 }
1613
1614 /* Ignore all other blocks */
1615 [] L1CTL.receive { repeat; }
1616
1617 }
1618
1619 f_rsl_chan_deact();
1620 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1621
1622 setverdict(pass);
1623}
1624
1625testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1626 var ConnHdlr vc_conn;
1627 var ConnHdlrPars pars;
1628 f_init(testcasename());
1629
1630 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1631 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1632 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1633 vc_conn.done;
1634 }
1635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1636}
Harald Welte70767382018-02-21 12:16:40 +01001637
Harald Welte0472ab42018-03-12 15:02:26 +01001638/* 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 +01001639private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001640 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001641 RSL.clear;
1642
1643 f_est_dchan();
1644 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001645 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001646
1647 timer T := 40.0;
1648 T.start;
1649 alt {
1650 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1651 setverdict(pass)
1652 }
1653 [] RSL.receive { repeat };
1654 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001656 }
1657 }
1658 f_rsl_chan_deact();
1659}
1660testcase TC_conn_fail_crit() runs on test_CT {
1661 var ConnHdlr vc_conn;
1662 var ConnHdlrPars pars;
1663 f_init(testcasename());
1664 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1665 pars.t_guard := 60.0;
1666 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1667 vc_conn.done;
1668}
1669
Harald Welte93640c62018-02-25 16:59:33 +01001670/***********************************************************************
1671 * Paging
1672 ***********************************************************************/
1673
Harald Welte68e495b2018-02-25 00:05:57 +01001674function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1675 if (tmsi == 'FFFFFFFF'O) {
1676 return true;
1677 } else {
1678 return false;
1679 }
1680}
Harald Welte70767382018-02-21 12:16:40 +01001681
Philipp Maier82cb0b12018-08-31 14:41:39 +02001682type record allowedFn { integer frame_nr }
1683template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
1684template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
1685template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
1686template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
1687template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
1688template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
1689template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
1690template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
1691function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
1692{
1693 var integer frame_nr_51;
1694 frame_nr_51 := frame_nr mod 51
1695
1696 var allowedFn fn_check;
1697 fn_check.frame_nr := frame_nr_51;
1698
1699 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001701 return;
1702 }
1703
1704 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
1705 return;
1706 }
1707 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
1708 return;
1709 }
1710 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
1711 return;
1712 }
1713 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
1714 return;
1715 }
1716 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
1717 return;
1718 }
1719 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
1720 return;
1721 }
1722 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
1723 return;
1724 }
1725 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
1726 return;
1727 }
1728
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02001730 return;
1731}
1732
1733altstep 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 +01001734runs on test_CT {
1735 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001736 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001737 repeat;
1738 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001739 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001740 var octetstring without_plen :=
1741 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1742 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02001743
1744 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
1745
Harald Welte68e495b2018-02-25 00:05:57 +01001746 if (match(rr, tr_PAGING_REQ1)) {
1747 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1748 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1749 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1750 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1751 }
1752 } else if (match(rr, tr_PAGING_REQ2)) {
1753 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1754 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1755 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1756 }
1757 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1758 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1759 }
1760 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1761 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1762 }
1763 } else if (match(rr, tr_PAGING_REQ3)) {
1764 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1765 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1766 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1767 }
1768 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1769 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1770 }
1771 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1772 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1773 }
1774 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1775 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1776 }
1777 }
1778 repeat;
1779 }
1780}
1781
1782type record PagingTestCfg {
1783 boolean combined_ccch,
1784 integer bs_ag_blks_res,
1785 float load_factor,
1786 boolean exp_load_ind,
1787 boolean exp_overload,
1788 boolean use_tmsi
1789}
1790
1791type record PagingTestState {
1792 integer num_paging_sent,
1793 integer num_paging_rcv_msgs,
1794 integer num_paging_rcv_ids,
1795 integer num_overload
1796}
1797
1798/* receive + ignore RSL RF RES IND */
1799altstep as_rsl_res_ind() runs on test_CT {
1800 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1801 repeat;
1802 }
1803}
1804
1805/* Helper function for paging related testing */
1806private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1807 f_init(testcasename());
1808 f_init_l1ctl();
1809 f_l1_tune(L1CTL);
1810
1811 var PagingTestState st := {
1812 num_paging_sent := 0,
1813 num_paging_rcv_msgs := 0,
1814 num_paging_rcv_ids := 0,
1815 num_overload := 0
1816 };
1817
1818 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1819 var float max_pch_imsi_per_sec;
1820 if (cfg.use_tmsi) {
1821 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1822 } else {
1823 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1824 }
1825 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1826 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001827 var float time_total := 20.0;
1828 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
1829 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01001830
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001831 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
1832 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01001833
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001834 timer T_itv := 0.0;
1835 T_itv.start;
1836 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01001837 alt {
1838 /* check for presence of CCCH LOAD IND (paging load) */
1839 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1840 st.num_overload := st.num_overload + 1;
1841 repeat;
1842 }
1843 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01001845 }
1846 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1847 log("Rx LOAD_IND");
1848 /* FIXME: analyze/verify interval + contents */
1849 repeat;
1850 }
1851 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02001852 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001853 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001854 [] T_itv.timeout {
1855 /* Send paging cmds based on elapsed time */
1856 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
1857 while (st.num_paging_sent < new_sent) {
1858 /* build mobile Identity */
1859 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1860 if (cfg.use_tmsi) {
1861 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1862 } else {
1863 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
1864 }
1865 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1866 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1867
1868 /* Send RSL PAGING COMMAND */
1869 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
1870
1871 st.num_paging_sent := st.num_paging_sent + 1;
1872 }
1873 if (st.num_paging_sent < pkt_total) {
1874 /* Wait for interval to next PAGING COMMAND */
1875 var float time_now := T_total.read;
1876 var float next_sched := int2float(st.num_paging_sent)*interval;
1877 if (next_sched > time_now) {
1878 T_itv.start(next_sched - time_now);
1879 } else {
1880 T_itv.start(0.0);
1881 }
1882 } else {
1883 /* We are done, no need to keep counting */
1884 T_total.stop;
1885 }
1886 }
1887 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01001888 [] as_rsl_res_ind();
1889 }
1890 }
1891
1892 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1893 timer T_wait := 18.0;
1894 T_wait.start;
1895 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02001896 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01001897 [] L1CTL.receive { repeat; }
1898 /* 65535 == empty paging queue, we can terminate*/
1899 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1900 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1901 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01001903 }
1904 [] as_rsl_res_ind();
1905 }
1906
1907 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1908 " rcvd_ids=", st.num_paging_rcv_ids);
1909 return st;
1910}
1911
1912/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1913 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1914 * - that CCCH LOAD IND (PCH) are being generated
1915 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1916testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001917 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001918 var PagingTestCfg cfg := {
1919 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001920 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001921 load_factor := 0.8,
1922 exp_load_ind := true,
1923 exp_overload := false,
1924 use_tmsi := false
1925 };
1926 var PagingTestState st := f_TC_paging(cfg);
1927 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1929 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001930 } else {
1931 setverdict(pass);
1932 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001934}
1935
1936/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1937 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1938 * - that CCCH LOAD IND (PCH) are being generated
1939 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1940testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001941 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001942 var PagingTestCfg cfg := {
1943 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001944 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001945 load_factor := 0.8,
1946 exp_load_ind := true,
1947 exp_overload := false,
1948 use_tmsi := true
1949 };
1950 var PagingTestState st := f_TC_paging(cfg);
1951 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
1953 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01001954 } else {
1955 setverdict(pass);
1956 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001958}
1959
1960/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1961 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1962 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1963 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1964testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001965 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001966 var PagingTestCfg cfg := {
1967 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001968 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001969 load_factor := 2.0,
1970 exp_load_ind := true,
1971 exp_overload := true,
1972 use_tmsi := false
1973 };
1974 var PagingTestState st := f_TC_paging(cfg);
1975 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1976 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02001977 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001978 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001979 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 +01001980 } else {
1981 setverdict(pass);
1982 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01001984}
1985
1986/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1987 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1988 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1989 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1990testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02001991 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01001992 var PagingTestCfg cfg := {
1993 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02001994 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01001995 load_factor := 2.0,
1996 exp_load_ind := true,
1997 exp_overload := true,
1998 use_tmsi := true
1999 };
2000 var PagingTestState st := f_TC_paging(cfg);
2001 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2002 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002003 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002004 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002005 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 +01002006 } else {
2007 setverdict(pass);
2008 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002010}
2011
2012
Harald Welte93640c62018-02-25 16:59:33 +01002013/***********************************************************************
2014 * Immediate Assignment / AGCH
2015 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002016const MobileAllocation c_MA_null := {
2017 len := 0,
2018 ma := ''B
2019}
Harald Welte93640c62018-02-25 16:59:33 +01002020
Harald Weltee8d750e2018-06-10 21:41:35 +02002021template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2022 uint12_t arfcn := 871) := {
2023 chan_nr := chan_nr,
2024 tsc := tsc,
2025 h := false,
2026 arfcn := arfcn,
2027 maio_hsn := omit
2028}
2029
2030private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2031 return int2str(num_tx) & " sent, "
2032 & int2str(num_rx) & " received, "
2033 & int2str(num_del) & " deleted";
2034}
2035
2036private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2037 var L1ctlDlMessage l1_dl;
2038 timer T := 10.0;
2039 var integer num_tx := 0;
2040 var integer num_rx := 0;
2041 var integer num_del := 0;
2042 var charstring res_str;
2043 var float rx_ratio;
2044
Harald Welte68e495b2018-02-25 00:05:57 +01002045 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002046 f_init_l1ctl();
2047 f_l1_tune(L1CTL);
2048
2049 for (var integer i := 0; i < num_total; i := i+1) {
2050 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2051 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2052 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002053 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002054 num_tx := num_tx+1;
2055 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002056 }
2057 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002058 T.start;
2059 alt {
2060 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2061 num_del := num_del+1;
2062 repeat;
2063 }
2064 [] RSL_CCHAN.receive {
2065 repeat;
2066 }
2067 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2068 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2069 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2070 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2071 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002072 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002073 } else {
2074 num_rx := num_rx+1;
2075 }
2076 repeat;
2077 }
2078 [] L1CTL.receive { repeat; }
2079 [] T.timeout { }
2080 }
2081 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2082 log("AGCH test: " & res_str);
2083 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002085 }
2086 rx_ratio := int2float(num_rx) / int2float(num_tx);
2087 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002088 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 +02002089 } else {
2090 setverdict(pass);
2091 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002093}
2094
Harald Weltee8d750e2018-06-10 21:41:35 +02002095/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2096testcase TC_imm_ass_1000_20ms() runs on test_CT {
2097 f_TC_imm_ass(1000, 0.02, 0.25);
2098}
2099
2100/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2101testcase TC_imm_ass_200_0ms() runs on test_CT {
2102 f_TC_imm_ass(200, 0.0, 0.05);
2103}
2104
2105/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2106testcase TC_imm_ass_200_76ms() runs on test_CT {
2107 f_TC_imm_ass(150, 0.076, 1.00);
2108}
2109
2110
2111
Harald Welte48494ca2018-02-25 16:59:50 +01002112/***********************************************************************
2113 * BCCH
2114 ***********************************************************************/
2115
2116/* tuple of Frame Number + decoded SI */
2117type record SystemInformationFn {
2118 GsmFrameNumber frame_number,
2119 SystemInformation si
2120}
2121
2122/* an arbitrary-length vector of decoded SI + gsmtap header */
2123type record of SystemInformationFn SystemInformationVector;
2124
2125/* an array of SI-vectors indexed by TC value */
2126type SystemInformationVector SystemInformationVectorPerTc[8];
2127
2128/* determine if a given SI vector contains given SI type at least once */
2129function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2130 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2131 var integer fn_mod51 := arr[i].frame_number mod 51;
2132 if (not bcch_ext and fn_mod51 == 2 or
2133 bcch_ext and fn_mod51 == 6) {
2134 if (arr[i].si.header.message_type == key) {
2135 return true;
2136 }
2137 }
2138 }
2139 return false;
2140}
2141
2142/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2143function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2144 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002146 }
2147}
2148
2149/* check if a given SI vector contains given SI type at least once on any TC */
2150function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2151 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2152 if (f_si_vecslot_contains(arr[tc], key) or
2153 f_si_vecslot_contains(arr[tc], key, true)) {
2154 return true;
2155 }
2156 }
2157 return false;
2158}
2159
2160/* determine if a given SI vector contains given SI type at least N of M times */
2161function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2162 var integer count := 0;
2163 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002165 }
2166 for (var integer i:= 0; i < m; i := i + 1) {
2167 var integer fn_mod51 := arr[i].frame_number mod 51;
2168 if (not bcch_ext and fn_mod51 == 2 or
2169 bcch_ext and fn_mod51 == 6) {
2170 if (arr[i].si.header.message_type == key) {
2171 count := count + 1;
2172 }
2173 }
2174 }
2175 if (count >= n) {
2176 return true;
2177 } else {
2178 return false;
2179 }
2180}
2181
2182/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2183function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2184 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002186 }
2187}
2188
2189/* determine if a given SI vector contains given SI type at least once */
2190function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2191 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2192 var integer fn_mod51 := arr[i].frame_number mod 51;
2193 if (not bcch_ext and fn_mod51 == 2 or
2194 bcch_ext and fn_mod51 == 6) {
2195 if (arr[i].si.header.message_type != key) {
2196 return false;
2197 }
2198 }
2199 }
2200 return true;
2201}
2202
2203/* ensure a given TC slot of the SI vector contains only given SI type */
2204function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2205 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002207 }
2208}
2209
2210/* SI configuration of cell, against which we validate actual SI messages */
2211type set SystemInformationConfig {
2212 boolean bcch_extended,
2213 boolean si1_present,
2214 boolean si2bis_present,
2215 boolean si2ter_present,
2216 boolean si2quater_present,
2217 boolean si7_present,
2218 boolean si8_present,
2219 boolean si9_present,
2220 boolean si13_present,
2221 boolean si13alt_present,
2222 boolean si15_present,
2223 boolean si16_present,
2224 boolean si17_present,
2225 boolean si2n_present,
2226 boolean si21_present,
2227 boolean si22_present
2228}
2229
2230/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2231function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2232 var integer i;
2233 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2234 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002236 }
2237 }
2238 if (cfg.si1_present) {
2239 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2240 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2241 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2242 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2243 /* make sure *ALL* contain SI1 */
2244 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2245 }
2246 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2247 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2248 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2249 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2250 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2251 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2252
2253 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2254 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2255 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2256 * consecutive occurrences of TC = 4. */
2257 if (cfg.si2bis_present and not cfg.si2ter_present) {
2258 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2259 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2260 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2261 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2262 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2263 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2264 }
2265
2266 if (cfg.si7_present or cfg.si8_present) {
2267 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2268 * if System Information type 4 does not contain all information needed for cell
2269 * selection and reselection. */
2270 if (not cfg.bcch_extended) {
2271 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2272 }
2273 if (cfg.si7_present) {
2274 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2275 }
2276 if (cfg.si8_present) {
2277 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2278 }
2279 }
2280
2281 if (cfg.si2quater_present) {
2282 /* iii) System information type 2 quater is sent if needed, as determined by the system
2283 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2284 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2285 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2286 * within any of 4 consecutive occurrences of TC = 5. */
2287 if (not (cfg.bcch_extended)) {
2288 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2289 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2290 } else {
2291 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2292 }
2293 } else {
2294 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2295 }
2296 }
2297 if (cfg.si9_present) {
2298 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2299 * in system information type 3 as defined in 3GPP TS 44.018. */
2300 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2301 }
2302 if (cfg.si13_present) {
2303 /* vii) System Information type 13 is only related to the GPRS service. System Information
2304 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2305 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2306 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2307 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2308 * within any of 4 consecutive occurrences of TC=4. */
2309 if (not cfg.bcch_extended) {
2310 log("not-bccch-extended");
2311 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2312 } else {
2313 log("bccch-extended");
2314 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2315 }
2316 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002318 }
2319 }
2320 if (cfg.si16_present or cfg.si17_present) {
2321 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2322 * should not be sent in a cell where network sharing is used (see rule xv). */
2323 if (cfg.si22_present) {
2324 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2325 }
2326 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002328 }
2329 if (not cfg.bcch_extended) {
2330 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2331 }
2332 if (cfg.si16_present) {
2333 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2334 }
2335 if (cfg.si17_present) {
2336 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2337 }
2338 }
2339
2340 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2341 * broadcast information. The frequency with which they are sent is determined by the
2342 * system operator. System Information type 9 identifies the scheduling of System
2343 * Information type 18 and 20 messages. */
2344
2345 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2346 * Information Type 19 is present, then its scheduling shall be indicated in System
2347 * Information Type 9. */
2348
2349 if (cfg.si15_present) {
2350 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2351 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2352 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2353 * 4 consecutive occurrences of TC = 1. */
2354 if (not cfg.bcch_extended) {
2355 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2356 } else {
2357 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2358 }
2359 }
2360 if (cfg.si13alt_present) {
2361 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2362 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2363 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2364 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2365 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2366 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2367 * of TC = 4. */
2368 if (cfg.si13_present) {
2369 testcase.stop("Error: Cannot have SI13alt and SI13");
2370 }
2371 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002373 }
2374 if (not cfg.bcch_extended) {
2375 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2376 } else {
2377 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2378 }
2379 }
2380 if (cfg.si2n_present) {
2381 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2382 * as determined by the system operator. In the case that the message is sent on the
2383 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2384 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2385 * consecutive occurrences of TC = 4. */
2386 if (not cfg.bcch_extended) {
2387 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2388 } else {
2389 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2390 }
2391 }
2392 if (cfg.si21_present) {
2393 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2394 * determined by the system operator. If Extended Access Barring is in use in the cell
2395 * then this message is sent at least once within any of 4 consecutive occurrences of
2396 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2397 * cell then this message shall only be sent on BCCH Ext. */
2398 if (not cfg.bcch_extended) {
2399 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2400 } else {
2401 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2402 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002404 }
2405 }
2406 }
2407 if (cfg.si22_present) {
2408 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2409 * should not be sent in a cell where SoLSA is used (see rule viii). System
2410 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2411 * =2 and TC=6. */
2412 if (cfg.si16_present or cfg.si17_present) {
2413 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2414 }
2415 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2416 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002418 }
2419 if (not cfg.bcch_extended) {
2420 testcase.stop("Error: SI22 requires BCCH Extd!");
2421 } else {
2422 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2423 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2424 }
2425 }
2426}
2427
2428/* sample Systme Information for specified duration via L1CTL */
2429function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2430 timer T := duration;
2431 var SystemInformationVectorPerTc si_per_tc;
2432 var L1ctlDlMessage l1_dl;
2433
2434 /* initialize all per-TC vectors empty */
2435 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2436 si_per_tc[i] := {};
2437 }
2438
2439 /* flush all previous L1 queued msgs */
2440 pt.clear;
2441
2442 T.start;
2443 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002444 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002445 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2446 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2447 log("Ignoring non-RR SI ", l1_dl);
2448 repeat;
2449 }
2450 var SystemInformationFn sig := {
2451 frame_number := l1_dl.dl_info.frame_nr,
2452 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2453 }
2454 var integer tc := f_gsm_compute_tc(sig.frame_number);
2455 log("SI received at TC=", tc, ": ", sig.si);
2456 /* append to the per-TC bucket */
2457 si_per_tc[tc] := si_per_tc[tc] & { sig };
2458 repeat;
2459 }
2460 [] pt.receive { repeat; }
2461 [] T.timeout { }
2462 }
2463
2464 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2465 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2466 }
2467 log("si_per_tc=", si_per_tc);
2468 return si_per_tc;
2469}
2470
2471/* helper function: Set given SI via RSL + validate scheduling.
2472 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2473function f_TC_si_sched() runs on test_CT {
2474 var SystemInformationVectorPerTc si_per_tc;
2475 f_init_l1ctl();
2476 f_l1_tune(L1CTL);
2477
2478 /* Sample + Validate Scheduling */
2479 si_per_tc := f_l1_sample_si(L1CTL);
2480 f_validate_si_scheduling(si_cfg, si_per_tc);
2481
2482 setverdict(pass);
2483}
2484
2485testcase TC_si_sched_default() runs on test_CT {
2486 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002487 /* 2+3+4 are mandatory and set in f_init() */
2488 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002490}
2491
2492testcase TC_si_sched_1() runs on test_CT {
2493 f_init();
2494 si_cfg.si1_present := true;
2495 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002496 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002498}
2499
2500testcase TC_si_sched_2bis() runs on test_CT {
2501 f_init();
2502 si_cfg.si2bis_present := true;
2503 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2504 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002506}
2507
2508testcase TC_si_sched_2ter() runs on test_CT {
2509 f_init();
2510 si_cfg.si2ter_present := true;
2511 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2512 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002514}
2515
2516testcase TC_si_sched_2ter_2bis() runs on test_CT {
2517 f_init();
2518 si_cfg.si2bis_present := true;
2519 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2520 si_cfg.si2ter_present := true;
2521 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2522 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002524}
2525
2526testcase TC_si_sched_2quater() runs on test_CT {
2527 f_init();
2528 si_cfg.si2quater_present := true;
2529 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2530 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002532}
2533
2534testcase TC_si_sched_13() runs on test_CT {
2535 f_init();
2536 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002537 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002538 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002540}
2541
2542testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2543 f_init();
2544 si_cfg.si2bis_present := true;
2545 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2546 si_cfg.si2ter_present := true;
2547 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2548 si_cfg.si2quater_present := true;
2549 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2550 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002551 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002552 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002553 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002554}
2555
2556
Harald Welte68e495b2018-02-25 00:05:57 +01002557testcase TC_bcch_info() runs on test_CT {
2558 f_init(testcasename());
2559 /* FIXME: enable / disable individual BCCH info */
2560 //ts_RSL_BCCH_INFO(si_type, info);
2561 /* expect no ERROR REPORT after either of them *
2562 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002564}
2565
Harald Welte93640c62018-02-25 16:59:33 +01002566/***********************************************************************
2567 * Low-Level Protocol Errors / ERROR REPORT
2568 ***********************************************************************/
2569
Harald Welte01d982c2018-02-25 01:31:40 +01002570private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2571 timer T := 5.0;
2572 T.start;
2573 alt {
2574 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2575 setverdict(pass);
2576 }
2577 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002579 }
2580 [] RSL_CCHAN.receive {
2581 repeat;
2582 }
2583 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002585 }
2586 }
2587}
2588
2589/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2590testcase TC_rsl_protocol_error() runs on test_CT {
2591 f_init(testcasename());
2592 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2593 rsl.ies := omit;
2594 RSL_CCHAN.send(ts_RSL_UD(rsl));
2595
2596 f_exp_err_rep(RSL_ERR_PROTO);
2597}
2598
2599/* Provoke a mandatory IE error and match on ERROR REPORT */
2600testcase TC_rsl_mand_ie_error() runs on test_CT {
2601 f_init(testcasename());
2602
2603 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2604 rsl.ies := { rsl.ies[0] };
2605 RSL_CCHAN.send(ts_RSL_UD(rsl));
2606
2607 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2608}
2609
2610/* Provoke an IE content error and match on ERROR REPORT */
2611testcase TC_rsl_ie_content_error() runs on test_CT {
2612 f_init(testcasename());
2613 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2614 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2615 RSL_CCHAN.send(ts_RSL_UD(rsl));
2616
2617 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2618}
2619
Harald Welteee25aae2019-05-19 14:32:37 +02002620/* attempt to activate channel with wrong RSL Message Discriminator IE */
2621function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2622 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2623 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2624 RSL.send(rsl);
2625 f_rslem_unregister(0, g_chan_nr);
2626}
2627testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2628 var ConnHdlr vc_conn;
2629 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2630
2631 f_init(testcasename());
2632
2633 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2634 vc_conn.done;
2635 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2636
2637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2638}
2639
2640/* Send messages with wrong message type */
2641function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2642 var template (value) RSL_Message rsl_tx;
2643 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2644 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2645 RSL.send(rsl_tx);
2646 f_rslem_unregister(0, g_chan_nr);
2647}
2648function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
2649 var template (value) RSL_Message rsl_tx;
2650 /* we first have to activate the dedicated channel */
2651 f_rsl_chan_act(g_pars.chan_mode);
2652 /* ... to then send an invalid RLL message */
2653 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
2654 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
2655 RSL.send(rsl_tx);
2656 f_rslem_unregister(0, g_chan_nr);
2657}
2658testcase TC_err_rep_wrong_msg_type() runs on test_CT {
2659 var ConnHdlr vc_conn;
2660 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2661 var template (value) RSL_Message rsl_tx;
2662
2663 f_init(testcasename());
2664
2665 /* Common Channel with wrong message type */
2666 RSL_CCHAN.clear;
2667 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2668 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
2669 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
2670 f_exp_err_rep(RSL_ERR_MSG_TYPE);
2671
2672 /* TRX Management */
2673 RSL_CCHAN.clear;
2674 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
2675 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
2676 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
2677 f_exp_err_rep(RSL_ERR_MSG_TYPE);
2678
2679 /* Dedicated Channel */
2680 RSL_CCHAN.clear;
2681 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
2682 vc_conn.done;
2683 f_exp_err_rep(RSL_ERR_MSG_TYPE);
2684
2685 /* RLL */
2686 RSL_CCHAN.clear;
2687 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
2688 vc_conn.done;
2689 f_exp_err_rep(RSL_ERR_MSG_TYPE);
2690}
2691
2692/* Send messages in wrong sequence (RLL to an inactive lchan) */
2693function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
2694 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
2695 f_rslem_unregister(0, g_chan_nr);
2696}
2697testcase TC_err_rep_wrong_sequence() runs on test_CT {
2698 var ConnHdlr vc_conn;
2699 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2700
2701 f_init(testcasename());
2702
2703 RSL_CCHAN.clear;
2704 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
2705 vc_conn.done;
2706 f_exp_err_rep(RSL_ERR_MSG_SEQ);
2707}
2708
Harald Welte93640c62018-02-25 16:59:33 +01002709/***********************************************************************
2710 * IPA CRCX/MDCX/DLCS media stream handling
2711 ***********************************************************************/
2712
Harald Weltea871a382018-02-25 02:03:14 +01002713/* Send IPA DLCX to inactive lchan */
2714function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002715 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2716 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002717}
2718testcase TC_ipa_dlcx_not_active() runs on test_CT {
2719 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2720 f_init(testcasename());
2721 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2722 vc_conn.done;
2723}
Harald Welte68e495b2018-02-25 00:05:57 +01002724
Harald Weltea3f1df92018-02-25 12:49:55 +01002725/* Send IPA CRCX twice to inactive lchan */
2726function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2727 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2728 "IPA CRCX ACK");
2729 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2730 "IPA CRCX NACK");
2731}
2732testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2733 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2734 f_init(testcasename());
2735 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2736 vc_conn.done;
2737}
2738
2739/* Regular sequence of CRCX/MDCX/DLCX */
2740function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2741 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2742 "IPA CRCX ACK");
2743 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2744 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2745 var uint7_t rtp_pt2 := f_rnd_int(127);
2746 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2747 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2748 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2749 "IPA MDCX ACK");
2750 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2751 "IPA DLCX ACK");
2752}
2753testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2754 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2755 f_init(testcasename());
2756 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2757 vc_conn.done;
2758}
2759
Harald Welte3ae11da2018-02-25 13:36:06 +01002760/* Sequence of CRCX, 2x MDCX, DLCX */
2761function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2762 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2763 "IPA CRCX ACK");
2764 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2765 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2766 var uint7_t rtp_pt2 := f_rnd_int(127);
2767 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2768 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2769 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2770 "IPA MDCX ACK");
2771 /* Second MDCX */
2772 remote_ip := f_rnd_int(c_UINT32_MAX);
2773 remote_port := f_rnd_int(c_UINT16_MAX);
2774 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2775 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2776 "IPA MDCX ACK");
2777 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2778 "IPA DLCX ACK");
2779}
2780testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2781 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2782 f_init(testcasename());
2783 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2784 vc_conn.done;
2785}
2786
Harald Welte9912eb52018-02-25 13:30:15 +01002787/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2788function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2789 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2790 "IPA CRCX NACK");
2791}
2792testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2793 var ConnHdlrPars pars;
2794 var ConnHdlr vc_conn;
2795 f_init(testcasename());
2796
2797 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2798 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2799 vc_conn.done;
2800
2801 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2802 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2803 vc_conn.done;
2804}
2805
Harald Weltea3f1df92018-02-25 12:49:55 +01002806
Harald Welte883340c2018-02-28 18:59:29 +01002807/***********************************************************************
2808 * PCU Socket related tests
2809 ***********************************************************************/
2810
2811private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2812runs on test_CT {
2813 timer T := 3.0;
2814
2815 /* we don't expect any RTS.req before PDCH are active */
2816 T.start;
2817 alt {
2818 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01002820 }
2821 [] PCU.receive { repeat; }
2822 [] T.timeout { }
2823 }
2824
2825 /* Send PDCH activate request for known PDCH timeslot */
2826 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2827
2828 /* we now expect RTS.req for this timeslot (only) */
2829 T.start;
2830 alt {
2831 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2832 setverdict(pass);
2833 }
2834 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2835 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01002837 }
2838 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01002840 }
2841 [] PCU.receive { repeat; }
2842 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002844 }
2845 [not exp_success] T.timeout {
2846 setverdict(pass);
2847 }
2848 }
2849}
2850
2851private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2852runs on test_CT {
2853 timer T := 3.0;
2854
2855 /* Send PDCH activate request for known PDCH timeslot */
2856 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2857
2858 PCU.clear;
2859 /* we now expect no RTS.req for this timeslot */
2860 T.start;
2861 alt {
2862 [] 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 +02002863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01002864 }
2865 [] PCU.receive { repeat; }
2866 [] T.timeout {
2867 setverdict(pass);
2868 }
2869 }
2870}
2871
Max2c6f5632019-03-18 17:25:17 +01002872private function f_init_pcu_test() runs on test_CT {
2873 f_init();
2874 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
2875}
2876
Harald Welte883340c2018-02-28 18:59:29 +01002877/* PDCH activation via PCU socket; check for presence of RTS.req */
2878testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002879 f_init_pcu_test();
2880
Harald Welte883340c2018-02-28 18:59:29 +01002881 f_TC_pcu_act_req(0, 0, 7, true);
2882}
2883
2884/* PDCH activation via PCU socket on non-PDCU timeslot */
2885testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002886 f_init_pcu_test();
2887
Harald Welte883340c2018-02-28 18:59:29 +01002888 f_TC_pcu_act_req(0, 0, 1, false);
2889}
2890
2891/* PDCH activation via PCU socket on wrong BTS */
2892testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002893 f_init_pcu_test();
2894
Harald Welte883340c2018-02-28 18:59:29 +01002895 f_TC_pcu_act_req(23, 0, 7, false);
2896}
2897
2898/* PDCH activation via PCU socket on wrong TRX */
2899testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002900 f_init_pcu_test();
2901
Harald Welte883340c2018-02-28 18:59:29 +01002902 f_TC_pcu_act_req(0, 23, 7, false);
2903}
2904
2905/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2906testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002907 f_init_pcu_test();
2908
Harald Welte883340c2018-02-28 18:59:29 +01002909 /* Activate PDCH */
2910 f_TC_pcu_act_req(0, 0, 7, true);
2911 f_sleep(1.0);
2912 /* and De-Activate again */
2913 f_TC_pcu_deact_req(0, 0, 7);
2914}
2915
2916/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2917testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002918 f_init_pcu_test();
2919
Harald Welte883340c2018-02-28 18:59:29 +01002920 f_TC_pcu_deact_req(0, 0, 1);
2921}
2922
2923/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2924testcase TC_pcu_ver_si13() runs on test_CT {
2925 const octetstring si13 := '00010203040506070909'O;
2926 var PCUIF_send_data sd;
2927 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01002928 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01002929
2930 /* Set SI13 via RSL */
2931 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01002932
Harald Welte883340c2018-02-28 18:59:29 +01002933 T.start;
2934 alt {
2935 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2936 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2937 setverdict(pass);
2938 } else {
2939 repeat;
2940 }
2941 }
2942 [] PCU.receive { repeat; }
2943 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01002945 }
2946 }
2947}
2948
2949private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2950
2951/* helper function to send a PCU DATA.req */
2952private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2953 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2954runs on test_CT
2955{
2956 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2957 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2958}
2959
2960/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2961private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2962 PCUIF_Sapi sapi, octetstring data)
2963runs on test_CT
2964{
2965 var PCUIF_send_data sd;
2966
2967 timer T := 3.0;
2968 T.start;
2969 alt {
2970 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2971 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2972 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2973 sd.data.u.rts_req.fn, sapi, data);
2974 }
2975 [] PCU.receive { repeat; }
2976 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01002978 }
2979 }
2980}
2981
2982/* Send DATA.req on invalid BTS */
2983testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002984 f_init_pcu_test();
2985
Harald Welte883340c2018-02-28 18:59:29 +01002986 f_TC_pcu_act_req(0, 0, 7, true);
2987 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2988 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2989 f_sleep(10.0);
2990}
2991
2992/* Send DATA.req on invalid TRX */
2993testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01002994 f_init_pcu_test();
2995
Harald Welte883340c2018-02-28 18:59:29 +01002996 f_TC_pcu_act_req(0, 0, 7, true);
2997 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2998 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2999 f_sleep(10.0);
3000}
3001
3002/* Send DATA.req on invalid timeslot */
3003testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003004 f_init_pcu_test();
3005
Harald Welte883340c2018-02-28 18:59:29 +01003006 f_TC_pcu_act_req(0, 0, 7, true);
3007 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3008 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3009 f_sleep(10.0);
3010}
3011
3012/* Send DATA.req on timeslot that hasn't been activated */
3013testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003014 f_init_pcu_test();
3015
Harald Welte883340c2018-02-28 18:59:29 +01003016 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3017 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3018 f_sleep(2.0);
3019}
3020
3021testcase TC_pcu_data_req_pdtch() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003022 f_init_pcu_test();
3023
Harald Welte883340c2018-02-28 18:59:29 +01003024 f_TC_pcu_act_req(0, 0, 7, true);
3025 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3026 /* FIXME: how to check this was actually sent */
3027 f_sleep(2.0);
3028}
3029
3030testcase TC_pcu_data_req_ptcch() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003031 f_init_pcu_test();
3032
Harald Welte883340c2018-02-28 18:59:29 +01003033 f_TC_pcu_act_req(0, 0, 7, true);
3034 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
3035 /* FIXME: how to check this was actually sent */
3036 f_sleep(2.0);
3037}
3038
3039/* Send AGCH from PCU; check it appears on Um side */
3040testcase TC_pcu_data_req_agch() runs on test_CT {
3041 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003042 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003043 f_init_l1ctl();
3044 f_l1_tune(L1CTL);
3045
3046 f_TC_pcu_act_req(0, 0, 7, true);
3047 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3048
3049 T.start;
3050 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003051 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003052 setverdict(pass);
3053 }
3054 [] L1CTL.receive { repeat; }
3055 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003057 }
3058 }
3059}
3060
3061/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3062testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3063 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003064 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003065 f_init_l1ctl();
3066 f_l1_tune(L1CTL);
3067
3068 /* append 3 last imsi digits so BTS can compute pagng group */
3069 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3070
3071 timer T := 0.5;
3072 T.start;
3073 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003074 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003075 /* TODO: verify paging group */
3076 setverdict(pass);
3077 }
3078 [] L1CTL.receive { repeat; }
3079 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003081 }
3082 }
3083}
3084
3085/* Send RACH from Um side, expect it to show up on PCU socket */
3086testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003087 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003088 f_init_l1ctl();
3089 f_l1_tune(L1CTL);
3090
3091 var GsmFrameNumber fn_last := 0;
3092 for (var integer i := 0; i < 1000; i := i+1) {
3093 var OCT1 ra := f_rnd_ra_ps();
3094 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3095 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003097 }
3098 fn_last := fn;
3099
3100 timer T := 2.0;
3101 T.start;
3102 alt {
3103 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3104 T.stop;
3105 }
3106 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003108 }
3109 [] PCU.receive { repeat; }
3110 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003112 }
3113 }
3114 }
3115 setverdict(pass);
3116}
3117
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003118/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3119 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3120testcase TC_pcu_ext_rach_content() runs on test_CT {
3121 var template PCUIF_Message pcu_rach_ind;
3122 var GsmFrameNumber fn_last := 0;
3123 var L1ctlRachSynchSeq synch_seq;
3124 var PCUIF_BurstType pcu_bt;
3125 var GsmFrameNumber fn;
3126 var BIT11 ra11;
3127
3128 f_init_pcu_test();
3129 f_init_l1ctl();
3130 f_l1_tune(L1CTL);
3131
3132 for (var integer i := 0; i < 1000; i := i+1) {
3133 /* We need to test both TS1 & TS2 */
3134 if (i rem 2 == 0) {
3135 synch_seq := RACH_SYNCH_SEQ_TS1;
3136 pcu_bt := BURST_TYPE_1;
3137 } else {
3138 synch_seq := RACH_SYNCH_SEQ_TS2;
3139 pcu_bt := BURST_TYPE_2;
3140 }
3141
3142 ra11 := f_rnd_ra11_ps();
3143 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3144 if (fn == fn_last) {
3145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3146 "Two RACH in same FN?!?");
3147 }
3148 fn_last := fn;
3149
3150 /* Compose the expected message */
3151 pcu_rach_ind := tr_PCUIF_RACH_IND(
3152 bts_nr := 0,
3153 ra := bit2int(ra11),
3154 is_11bit := 1,
3155 burst_type := pcu_bt,
3156 fn := fn);
3157
3158 timer T := 2.0;
3159 T.start;
3160 alt {
3161 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3162 T.stop;
3163 }
3164 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3166 }
3167 [] PCU.receive { repeat; }
3168 [] T.timeout {
3169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3170 }
3171 }
3172 }
3173 setverdict(pass);
3174}
3175
Harald Welte883340c2018-02-28 18:59:29 +01003176private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3177 var integer strlen := lengthof(str);
3178 for (var integer i := 0; i < len-strlen; i := i+1) {
3179 str := str & pad;
3180 }
3181 return str;
3182}
3183
3184/* Send PAGING via RSL, expect it to shw up on PCU socket */
3185testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003186 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003187
3188 for (var integer i := 0; i < 100; i := i+1) {
3189 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3190 timer T := 3.0;
3191 if (i < 50) {
3192 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3193 } else {
3194 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3195 }
3196 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3197 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3198 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3199
3200 /* Send RSL PAGING COMMAND */
3201 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3202 T.start;
3203 alt {
3204 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3205 }
3206 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003208 }
3209 [] PCU.receive { repeat; }
3210 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003212 }
3213 }
3214 }
3215 setverdict(pass);
3216}
3217
Harald Welte3d04ae62018-04-04 20:29:05 +02003218/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003219 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003220 ***********************************************************************/
3221
3222private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3223runs on ConnHdlr {
3224 var PCUIF_send_data sd;
3225 /* Expect BTS to immediately acknowledge activation as PDCH */
3226 PCU.clear;
3227 f_rsl_chan_act(g_pars.chan_mode);
3228 /* expect INFO_IND on PCU interface listing TS as PDCH */
3229 alt {
3230 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3231 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 +02003232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003233 }
3234 }
3235 [] PCU.receive { repeat; }
3236 }
3237 /* try to activate this PDCH from the PCU point of view */
3238 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3239 /* FIXME: is there a response? */
3240}
3241
3242private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3243runs on ConnHdlr {
3244 var PCUIF_send_data sd;
3245 /* Send RSL CHAN REL (deactivate) */
3246 PCU.clear;
3247 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3248 /* expect BTS to ask PCU to deactivate the channel */
3249 alt {
3250 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3251 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 +02003252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003253 }
3254 }
3255 [] PCU.receive { repeat; }
3256 }
3257 /* Emulate PCU asking BTS to deactivate PDCH */
3258 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3259 alt {
3260 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3261 setverdict(pass);
3262 }
3263 [] RSL.receive { repeat; }
3264 }
3265}
3266
3267/* Activate Osmocom-style dynamic PDCH from BSC side */
3268function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3269 var PCUIF_Message first_info;
3270 var integer ts_nr := g_chan_nr.tn;
3271 var integer trx_nr := 0;
3272 var integer bts_nr := 0;
3273 var integer pcu_conn_id := -1;
3274
3275 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3276
3277 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3278 f_sleep(3.0);
3279 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3280 setverdict(pass);
3281}
3282testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3283 var ConnHdlrPars pars;
3284 var ConnHdlr vc_conn;
3285 f_init(testcasename());
3286
3287 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3288 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3289 vc_conn.done;
3290}
3291
3292/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3293function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3294 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003295 var integer pcu_conn_id := -1;
3296
3297 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3298
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003299 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3300 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3301 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003302 setverdict(pass);
3303}
3304testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3305 var ConnHdlrPars pars;
3306 var ConnHdlr vc_conn;
3307 f_init(testcasename());
3308
3309 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3310 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3311 vc_conn.done;
3312}
3313
3314/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3315function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3316 var PCUIF_Message first_info;
3317 var integer ts_nr := g_chan_nr.tn;
3318 var integer trx_nr := 0;
3319 var integer bts_nr := 0;
3320 var integer pcu_conn_id := -1;
3321
3322 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3323
3324 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003325 /* Send a second Chan Activ and expect it to be NACKed */
3326 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3327 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003328 setverdict(pass);
3329}
3330testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3331 var ConnHdlrPars pars;
3332 var ConnHdlr vc_conn;
3333 f_init(testcasename());
3334
3335 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3336 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3337 vc_conn.done;
3338}
3339
3340/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3341function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3342 var PCUIF_Message first_info;
3343 var integer ts_nr := g_chan_nr.tn;
3344 var integer trx_nr := 0;
3345 var integer bts_nr := 0;
3346 var integer pcu_conn_id := -1;
3347 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3348
3349 /* register for the TCH/F channel number */
3350 f_rslem_register(0, chan_nr);
3351
3352 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3353
3354 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3355 "RSL CHAN ACT");
3356 setverdict(pass);
3357}
3358testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3359 var ConnHdlrPars pars;
3360 var ConnHdlr vc_conn;
3361 f_init(testcasename());
3362
3363 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3364 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3365 vc_conn.done;
3366}
3367
3368/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3369function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3370 var PCUIF_Message first_info;
3371 var integer ts_nr := g_chan_nr.tn;
3372 var integer trx_nr := 0;
3373 var integer bts_nr := 0;
3374 var integer pcu_conn_id := -1;
3375 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3376 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3377
3378 /* register for the TCH/H channel numbers */
3379 f_rslem_register(0, chan_nr[0]);
3380 f_rslem_register(0, chan_nr[1]);
3381
3382 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3383
3384 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3385 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3386 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3387 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3388 setverdict(pass);
3389}
3390testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3391 var ConnHdlrPars pars;
3392 var ConnHdlr vc_conn;
3393 f_init(testcasename());
3394
3395 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3396 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3397 vc_conn.done;
3398}
3399
Harald Welte9bbbfb52018-04-05 09:33:19 +02003400/***********************************************************************
3401 * IPA Style Dynamic Timeslot Support
3402 ***********************************************************************/
3403
3404private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3405runs on ConnHdlr {
3406 var PCUIF_send_data sd;
3407 /* Expect BTS to immediately acknowledge activation as PDCH */
3408 PCU.clear;
3409 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3410 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003411 timer T_wait := 2.0;
3412 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003413 alt {
3414 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3415 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003416 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
3417 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3418 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003419 }
3420 }
3421 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003422 [] T_wait.timeout {
3423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3424 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
3425 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003426 }
3427 /* try to activate this PDCH from the PCU point of view */
3428 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3429 /* FIXME: is there a response? */
3430
3431 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3432}
3433
3434private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3435runs on ConnHdlr {
3436 var PCUIF_send_data sd;
3437 /* Send RSL CHAN REL (deactivate) */
3438 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3439 PCU.clear;
3440 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003441 timer T_wait := 2.0;
3442 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003443 alt {
3444 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3445 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003446 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
3447 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3448 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003449 }
3450 }
3451 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003452 [] T_wait.timeout {
3453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3454 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
3455 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003456 }
3457 /* Emulate PCU asking BTS to deactivate PDCH */
3458 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3459 alt {
3460 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3461 setverdict(pass);
3462 }
3463 [] RSL.receive { repeat; }
3464 }
3465}
3466
3467/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3468function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3469 var PCUIF_Message first_info;
3470 var integer ts_nr := g_chan_nr.tn;
3471 var integer trx_nr := 0;
3472 var integer bts_nr := 0;
3473 var integer pcu_conn_id := -1;
3474
3475 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3476
3477 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3478 f_sleep(3.0);
3479 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3480
3481 setverdict(pass);
3482
3483}
3484testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3485 var ConnHdlrPars pars;
3486 var ConnHdlr vc_conn;
3487 f_init();
3488
3489 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3490 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3491 vc_conn.done;
3492}
3493
3494/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3495function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3496 var PCUIF_Message first_info;
3497 var integer ts_nr := g_chan_nr.tn;
3498 var integer trx_nr := 0;
3499 var integer bts_nr := 0;
3500 var integer pcu_conn_id := -1;
3501
3502 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3503
3504 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3505 "RSL CHAN ACT");
3506 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3507 "RF CHAN REL", true);
3508 setverdict(pass);
3509}
3510testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3511 var ConnHdlrPars pars;
3512 var ConnHdlr vc_conn;
3513 f_init(testcasename());
3514
3515 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3516 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3517 vc_conn.done;
3518}
3519
3520/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3521function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3522 var PCUIF_Message first_info;
3523 var integer ts_nr := g_chan_nr.tn;
3524 var integer trx_nr := 0;
3525 var integer bts_nr := 0;
3526 var integer pcu_conn_id := -1;
3527
3528 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3529
3530 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3531 "RSL CHAN ACT");
3532
3533 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3534 alt {
3535 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3536 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02003538 }
3539 [] RSL.receive { repeat; }
3540 }
3541
3542 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3543 "RF CHAN REL", true);
3544 setverdict(pass);
3545}
3546testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3547 var ConnHdlrPars pars;
3548 var ConnHdlr vc_conn;
3549 f_init(testcasename());
3550
3551 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3552 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3553 vc_conn.done;
3554}
3555
3556/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3557function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3558 var PCUIF_Message first_info;
3559 var integer ts_nr := g_chan_nr.tn;
3560 var integer trx_nr := 0;
3561 var integer bts_nr := 0;
3562 var integer pcu_conn_id := -1;
3563
3564 /* register for the TCH/F channel number */
3565 f_rslem_register(0, g_chan_nr);
3566
3567 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3568
3569 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3570
3571 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3572 "RSL CHAN ACT");
3573
3574 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3575
3576 setverdict(pass);
3577}
3578testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3579 var ConnHdlrPars pars;
3580 var ConnHdlr vc_conn;
3581 f_init(testcasename());
3582
3583 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3584 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3585 vc_conn.done;
3586}
3587
3588
Harald Welte0472ab42018-03-12 15:02:26 +01003589/***********************************************************************
3590 * LAPDm / RLL related
3591 ***********************************************************************/
3592
3593private function f_tx_lapdm(template (value) LapdmFrame l,
3594 template (value) RslLinkId link_id) runs on ConnHdlr {
3595 var octetstring l2 := enc_LapdmFrame(valueof(l));
3596 if (valueof(link_id.c) == SACCH) {
3597 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02003598 var L1ctlDataReq l1hl2 := {
3599 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
3600 l2_payload := f_pad_oct(l2, 21, '2B'O)
3601 }
3602 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
3603 } else {
3604 /* If required, pad L2 frame with constant 0x2b filling */
3605 l2 := f_pad_oct(l2, 23, '2B'O);
3606
3607 log("encoding ", l, " to ", l2);
3608 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01003609 }
Harald Welte0472ab42018-03-12 15:02:26 +01003610}
3611
3612type record RllTestCase {
3613 uint3_t sapi,
3614 RslLinkId link_id,
3615 octetstring l3,
3616 boolean exp
3617}
3618type record of RllTestCase RllTestCases;
3619template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3620 sapi := sapi,
3621 link_id := id,
3622 l3 := l3,
3623 exp := exp
3624}
3625
3626/* execute the same callback function with a set of different parameters (tcs) on a
3627 * variety of logical channels */
3628private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3629 var ConnHdlrPars pars;
3630 var ConnHdlr vc_conn;
3631 f_init(testcasename());
3632
3633 /* test on each of the channels we have */
3634 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3635 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3636
3637 /* test each of the test cases on the current channel */
3638 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3639 pars.spec.rll := tcs[j];
3640 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3641 vc_conn := f_start_handler(fn, pars);
3642 vc_conn.done;
3643 }
3644 }
3645
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01003647}
3648
3649/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3650private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3651 var RllTestCase tc := g_pars.spec.rll;
3652 timer T := 3.0;
3653
3654 f_l1_tune(L1CTL);
3655 RSL.clear;
3656
3657 /* activate the logical channel */
3658 f_est_dchan();
3659 L1CTL.clear;
3660
3661 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3662 T.start;
3663 alt {
3664 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3665 if (tc.exp) {
3666 setverdict(pass);
3667 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003669 }
3670 }
3671 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3672 if (tc.exp) {
3673 setverdict(pass);
3674 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01003676 }
3677 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003678 /* We also expect to receive the measurements */
3679 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003680 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003682 }
3683 [not tc.exp] T.timeout {
3684 setverdict(pass);
3685 }
3686 }
3687
3688 f_rsl_chan_deact();
3689 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3690 f_rslem_unregister(0, g_chan_nr);
3691}
3692testcase TC_rll_est_ind() runs on test_CT {
3693 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003694 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003695 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003696 /* normal SAPI0 establishment */
3697 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003698 /* SAPI 3 doesn't support contention resolution */
3699 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3700 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3701 /* normal SAPI3 establishment on main DCCH */
3702 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3703 /* normal SAPI3 establishment on SACCH */
3704 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3705 };
3706 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3707}
3708
3709/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3710private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3711 var RllTestCase tc := g_pars.spec.rll;
3712 var L1ctlDlMessage dl;
3713 timer T := 3.0;
3714
3715 f_l1_tune(L1CTL);
3716 RSL.clear;
3717
3718 /* activate the logical channel */
3719 f_est_dchan();
3720 L1CTL.clear;
3721
3722 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3723 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3724 T.start;
3725 alt {
3726 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3727 var LapdmFrame lapdm;
3728 var octetstring l2 := dl.payload.data_ind.payload;
3729 if (dl.dl_info.link_id.c == SACCH) {
3730 /* remove L1 header */
3731 l2 := substr(l2, 2, lengthof(l2)-2);
3732 }
3733 lapdm.ab := dec_LapdmFrameAB(l2);
3734 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3735 setverdict(pass);
3736 } else {
3737 repeat;
3738 }
3739 }
3740 [] L1CTL.receive { repeat; }
3741 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01003743 }
3744 }
3745
3746 f_rsl_chan_deact();
3747 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3748 f_rslem_unregister(0, g_chan_nr);
3749}
3750testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3751 var RllTestCases tcs := {
3752 /* normal SAPI3 establishment on main DCCH */
3753 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3754 };
3755 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3756}
3757testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3758 var RllTestCases tcs := {
3759 /* normal SAPI3 establishment on SACCH */
3760 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3761 }
3762 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3763}
3764
3765/* altstep to receive a LAPDm frame matching the given template */
3766private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3767 var L1ctlDlMessage dl;
3768 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3769 var LapdmFrame lapdm;
3770 var octetstring l2 := dl.payload.data_ind.payload;
3771 if (dl.dl_info.link_id.c == SACCH) {
3772 /* remove L1 header */
3773 l2 := substr(l2, 2, lengthof(l2)-2);
3774 }
3775 if (ischosen(exp.ab)) {
3776 lapdm.ab := dec_LapdmFrameAB(l2);
3777 } else if (ischosen(exp.b4)) {
3778 lapdm.b4 := dec_LapdmFrameB4(l2);
3779 } else if (ischosen(exp.bbis)) {
3780 lapdm.bbis := dec_LapdmFrameBbis(l2);
3781 }
3782 log("Rx LAPDm ", lapdm);
3783 if (match(lapdm, exp)) {
3784 setverdict(pass);
3785 } else {
3786 repeat;
3787 }
3788 }
3789 [] L1CTL.receive { repeat; }
3790}
3791private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3792 timer T := t;
3793 T.start;
3794 alt {
3795 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01003797 }
3798 [] as_l1_exp_lapdm(exp);
3799 }
3800}
3801
3802/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3803private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3804 /* send SABM from MS -> BTS */
3805 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3806 /* expect RLL EST IND on Abis */
3807 alt {
3808 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3809 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3810 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01003812 }
3813 [] RSL.receive { repeat; }
3814 }
3815 /* expect UA from BTS -> MS */
3816 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3817}
3818
3819/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3820private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3821 var RllTestCase tc := g_pars.spec.rll;
3822
3823 f_l1_tune(L1CTL);
3824 RSL.clear;
3825
3826 /* activate the logical channel */
3827 f_est_dchan();
3828 L1CTL.clear;
3829
3830 /* first establish the link-layer */
3831 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3832
3833 /* then send the DISC */
3834 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3835 /* ... and expect the REL IND on the RSL side */
3836 alt {
3837 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3838 setverdict(pass);
3839 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07003840 /* We also expect to receive the measurements */
3841 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01003842 }
3843
3844 /* release the channel */
3845 f_rsl_chan_deact();
3846 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3847 f_rslem_unregister(0, g_chan_nr);
3848}
3849testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3850 var RllTestCases tcs := {
3851 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3852 };
3853 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3854}
3855
3856testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3857 var RllTestCases tcs := {
3858 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3859 };
3860 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3861}
3862testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3863 var RllTestCases tcs := {
3864 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3865 };
3866 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3867}
3868testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3869 var RllTestCases tcs := {
3870 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3871 };
3872 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3873}
3874
3875/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3876private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3877 var RllTestCase tc := g_pars.spec.rll;
3878 f_l1_tune(L1CTL);
3879 RSL.clear;
3880
3881 /* activate the logical channel */
3882 f_est_dchan();
3883 L1CTL.clear;
3884
3885 /* first establish the link-layer */
3886 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3887
3888 /* then send the REL REQ via RSL */
3889 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3890 /* ... and expect the DISC on the Um side */
3891 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003892 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003893 /* FIXME: send a UA in resposne to the DISC */
3894 }
3895 }
3896
3897 /* release the channel */
3898 f_rsl_chan_deact();
3899 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3900 f_rslem_unregister(0, g_chan_nr);
3901}
3902testcase TC_rll_rel_req() runs on test_CT {
3903 var RllTestCases tcs := {
3904 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3905 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3906 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3907 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3908 };
3909 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3910}
3911
3912/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3913testcase TC_rll_data_req() runs on test_CT {
3914}
3915
3916/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3917testcase TC_rll_data_ind() runs on test_CT {
3918}
3919
3920/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3921private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3922 var RllTestCase tc := g_pars.spec.rll;
3923
3924 f_l1_tune(L1CTL);
3925 RSL.clear;
3926
3927 f_est_dchan();
3928 L1CTL.clear;
3929
3930 /* Send UNITDATA REQ on RSL side */
3931 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3932 /* Expect it to arrive on the other side */
3933 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003934 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003935 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003936 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003937 }
3938
3939 /* release the channel */
3940 f_rsl_chan_deact();
3941 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3942 f_rslem_unregister(0, g_chan_nr);
3943}
3944testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3945 var octetstring l3 := f_rnd_octstring(15);
3946 var RllTestCases tcs := {
3947 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3948 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3949 };
3950 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3951}
3952testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3953 var octetstring l3 := f_rnd_octstring(19);
3954 var RllTestCases tcs := {
3955 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3956 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3957 };
3958 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3959}
3960
3961/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3962private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3963 var RllTestCase tc := g_pars.spec.rll;
3964
3965 f_l1_tune(L1CTL);
3966 RSL.clear;
3967
3968 f_est_dchan();
3969 L1CTL.clear;
3970
3971 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003972 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003973 /* Expdct RLL UNITDATA IND on RSL side */
3974 alt {
3975 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3976 setverdict(pass);
3977 }
3978 [] RSL.receive { repeat; }
3979 }
3980
3981 /* release the channel */
3982 f_rsl_chan_deact();
3983 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3984 f_rslem_unregister(0, g_chan_nr);
3985}
3986testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02003987 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01003988 var RllTestCases tcs := {
3989 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3990 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3991 };
3992 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3993}
3994testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3995 var octetstring l3 := f_rnd_octstring(18);
3996 var RllTestCases tcs := {
3997 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3998 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3999 };
4000 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4001}
4002
Harald Weltee613f962018-04-18 22:38:16 +02004003/***********************************************************************
4004 * Encryption Related
4005 ***********************************************************************/
4006
4007/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4008function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4009 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4010 if (link_id.c == SACCH) {
4011 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4012 } else {
4013 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4014 }
4015}
4016
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004017/* Expect (or not expect) other kinds of messages */
4018private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4019 [exp_any] RSL.receive { repeat; }
4020 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004022 }
4023}
4024
Harald Weltee613f962018-04-18 22:38:16 +02004025/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004026private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004027 RslLinkId link_id,
4028 octetstring l3,
4029 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004030 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004031) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004032 timer T := 3.0;
4033 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4034 T.start;
4035 /* Expect RLL UNITDATA IND on RSL side */
4036 alt {
4037 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4038 setverdict(pass);
4039 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004040 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004041 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004042 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004044 }
Harald Weltee613f962018-04-18 22:38:16 +02004045 }
4046}
4047
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004048/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4049private function f_data_mo(
4050 RslLinkId link_id,
4051 boolean p, uint3_t nr, uint3_t ns,
4052 octetstring l3,
4053 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004054 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004055) runs on ConnHdlr {
4056 timer T := 3.0;
4057 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4058 T.start;
4059 /* Expect RLL DATA IND on RSL side */
4060 alt {
4061 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4062 setverdict(pass);
4063 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004064 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004065 [] as_rsl_any_ind(exp_any);
4066 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004068 }
4069 }
4070}
4071
Harald Weltee613f962018-04-18 22:38:16 +02004072/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4073function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4074 f_l1_tune(L1CTL);
4075 f_est_dchan(true);
4076
4077 /* now we actually need to transmit some data both ways to check if the encryption works */
4078 var L1ctlDlMessage dl;
4079
Stefan Sperling603d98e2018-07-25 16:47:28 +02004080 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004081 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4082
4083 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4084 f_unitdata_mt(link_id, l3);
4085
4086 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4087 f_unitdata_mo(link_id, l3);
4088
4089 /* release the channel */
4090 f_rsl_chan_deact();
4091 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4092 f_rslem_unregister(0, g_chan_nr);
4093}
4094testcase TC_chan_act_a51() runs on test_CT {
4095 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4096 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4097 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4098}
4099testcase TC_chan_act_a52() runs on test_CT {
4100 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4101 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4102 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4103}
4104testcase TC_chan_act_a53() runs on test_CT {
4105 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4106 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4107 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4108}
4109
4110
4111/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4112function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4113 /* L3 payload doesn't matter, as it is passed transparently */
4114 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4115 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4116 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4117
4118 f_l1_tune(L1CTL);
4119
4120 /* first establish a dedicated channel in the clear */
4121 f_est_dchan(false);
4122
4123 /* Establish ABM */
4124 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4125
4126 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4127 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4128 /* expect the L3 to arrive still unencrypted on the MS side */
4129 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4130
4131 /* configure L1 to apply ciphering */
4132 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4133 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4134
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004135 /* send first ciphered I-frame in response and expect it on RSL */
4136 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004137
4138 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4139 * and hence enable encryption also on the downlink */
4140
4141 /* expect bi-directional communication work in encrypted mode */
4142 f_unitdata_mo(link_id, f_rnd_octstring(15));
4143 f_unitdata_mt(link_id, f_rnd_octstring(15));
4144
4145 /* release the channel */
4146 f_rsl_chan_deact();
4147 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4148 f_rslem_unregister(0, g_chan_nr);
4149}
4150testcase TC_encr_cmd_a51() runs on test_CT {
4151 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4152 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4153 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4154}
4155testcase TC_encr_cmd_a52() runs on test_CT {
4156 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4157 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4158 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4159}
4160testcase TC_encr_cmd_a53() runs on test_CT {
4161 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4162 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4163 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4164}
4165
4166private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4167 var LapdmFrame lf;
4168 var octetstring reenc;
4169
4170 /* decode the LAPDm frame */
4171 if (ischosen(exp_match.ab)) {
4172 lf.ab := dec_LapdmFrameAB(enc);
4173 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004175 }
4176
4177 /* check if decoder result matches expectation */
4178 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004180 } else {
4181 log(name, ": matched");
4182 setverdict(pass);
4183 }
4184
4185 /* test if re-encoded frame equals original input */
4186 reenc := enc_LapdmFrame(lf);
4187 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004189 } else {
4190 setverdict(pass);
4191 }
4192}
4193
4194testcase TC_lapdm_selftest() runs on test_CT {
4195 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4196 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4197 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4198 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4199 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4200 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4201 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4202}
4203
Stefan Sperling4880be42018-08-07 18:12:59 +02004204/***********************************************************************
4205 * DTX Related (see GSM 05.08, section 8.3)
4206 ***********************************************************************/
4207
4208/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4209function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4210 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4211 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4212 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4213 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4214}
4215function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4216 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4217 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4218}
4219function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4220 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4221 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4222 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4223 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4224}
4225function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4226 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4227 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4228 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4229 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4230 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4231 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4232 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4233 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4234}
4235
4236function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4237 var L1ctlDlMessage dl;
4238 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4239 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4240 var GsmFrameNumber first_fn;
4241 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004242 var integer nfill_frames_sacch := 0;
4243 var integer nfill_frames_nonsacch := 0;
4244 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004245 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4246 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004247 const integer frame_dtx_tchf_mod := 104;
4248 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4249 * which operates in terms of blocks rather than frames. */
4250 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4251 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004252 timer T := 5.0;
4253
4254 f_l1_tune(L1CTL);
4255 RSL.clear;
4256 L1CTL.clear;
4257
4258 /* activate TCHF signalling channel */
4259 f_est_dchan(false);
4260
4261 T.start;
4262 alt {
4263 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4264 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4265 var octetstring l2 := dl.payload.data_ind.payload;
4266
4267 if (is_first_frame) {
4268 is_first_frame := false;
4269 first_fn := dl.dl_info.frame_nr;
4270 }
4271
4272 if (dl.dl_info.link_id.c == SACCH) {
4273 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4274 if (not match(l2_fill_frame_sacch, l2)) {
4275 repeat;
4276 }
4277 } else if (not match(l2_fill_frame, l2)) {
4278 repeat;
4279 }
4280
4281 if (dtxd) {
4282 if (not f_g_chan_is_tchf()) {
4283 T.stop;
4284 f_rsl_chan_deact();
4285 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004286 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 +02004287 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004288 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004289 T.stop;
4290 f_rsl_chan_deact();
4291 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004292
4293 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4294 * 2 SACCH, 1 TCH/F */
4295 expected_fill_frames := 3;
4296
4297 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4298 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4299 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004301 } else {
4302 setverdict(pass);
4303 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004304 } else {
4305 if (dl.dl_info.link_id.c == SACCH) {
4306 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004307 repeat;
4308 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004309 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4310 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4311 * we should only see the subset of frames numbers which correspond to a block boundary.
4312 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4313 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4314 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4315 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4316 repeat;
4317 }
4318 }
4319 log("Received DTX TCH fill frame with bad frame number: ", fn,
4320 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4321 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4322 f_rsl_chan_deact();
4323 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004325 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004326 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004327 if (dl.dl_info.link_id.c == SACCH) {
4328 nfill_frames_sacch := nfill_frames_sacch + 1;
4329 } else {
4330 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4331 }
4332 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004333 T.stop;
4334 if (f_g_chan_is_tchf()) {
4335 /* Without DTX we can expect 25 fill frames for every 104 frames.
4336 * (24 FACCH + 1 SACCH filling) */
4337 expected_fill_frames := 25;
4338 } else if (f_g_chan_is_tchh()) {
4339 /* We can expect 2 fill frames for every 104 frames. */
4340 expected_fill_frames := 2;
4341 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4342 /* We can expect 5 fill frames for every 104 frames. */
4343 expected_fill_frames := 5;
4344 } else {
4345 f_rsl_chan_deact();
4346 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004348 }
4349
4350 f_rsl_chan_deact();
4351 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004352
4353 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004354 setverdict(pass);
4355 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004356 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4357 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004359 }
4360 } else {
4361 repeat;
4362 }
4363 }
4364 }
4365 [] L1CTL.receive { repeat; }
4366 [] T.timeout {
4367 f_rsl_chan_deact();
4368 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004370 }
4371 }
4372}
4373
4374function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4375 f_test_l2_fill_frames(false);
4376}
4377
4378function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4379 f_test_l2_fill_frames(true);
4380}
4381
4382function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4383 var ConnHdlr vc_conn;
4384 var ConnHdlrPars pars;
4385 pars.t_guard := 60.0;
4386 f_init(testcasename());
4387 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4388 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4389 if (dtxd) {
4390 if (i >= 4) { /* DTX is only allowed on TCH/F */
4391 break;
4392 }
4393 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4394 } else {
4395 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4396 }
4397 vc_conn.done;
4398 }
4399}
4400
4401/* Verify that L2 fill frames are sent on TCH in signaling mode if
4402 * there is nothing to transmit while DTX is disabled on downlink. */
4403testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4404 f_tch_sign_l2_fill_frame(false);
4405}
4406
4407/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4408 * there is nothing to transmit while DTX is enabled on downlink. */
4409testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4410 f_tch_sign_l2_fill_frame(true);
4411}
Harald Welte0472ab42018-03-12 15:02:26 +01004412
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004413testcase TC_chopped_ipa_ping() runs on test_CT {
4414 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4415}
4416
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004417testcase TC_chopped_ipa_payload() runs on test_CT {
4418 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4419}
4420
Harald Welte0472ab42018-03-12 15:02:26 +01004421/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4422/* protocol error as per 44.006 */
4423/* link layer failure (repetition of I-frame N200 times without ACK */
4424/* repetition of SABM or DISC N200 times without ACK */
4425/* receptiom of SABM in multi-frame established state */
4426
4427
4428
4429
Harald Welte883340c2018-02-28 18:59:29 +01004430
Harald Welte68e495b2018-02-25 00:05:57 +01004431/* TODO Areas:
4432
4433* channel activation
4434** with BS_Power / MS_Power, bypassing power control loop
4435** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004436** with timing advance from initial activation on
4437* mode modify
4438** encryption
4439** multirate
4440* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01004441** unsupported algorithm
4442* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01004443* BS Power Control
4444* Physical Context
Harald Welte43c54642018-09-15 17:47:04 +03004445* CCCH Load Indication for RACH
Harald Welte68e495b2018-02-25 00:05:57 +01004446* SMS Broadcast Req / Cmd / CBCH LOad Ind
4447* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01004448* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01004449** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01004450* PCU interface
4451** TIME_IND from BTS->PCU
4452** DATA_IND from BTS->PCU
4453** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01004454
4455*/
Harald Welte70767382018-02-21 12:16:40 +01004456
4457control {
4458 execute( TC_chan_act_stress() );
4459 execute( TC_chan_act_react() );
4460 execute( TC_chan_deact_not_active() );
4461 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01004462 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01004463 execute( TC_sacch_filling() );
4464 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01004465 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01004466 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02004467 execute( TC_sacch_chan_act() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01004468 execute( TC_rach_content() );
4469 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01004470 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01004471 execute( TC_meas_res_sign_tchf() );
4472 execute( TC_meas_res_sign_tchh() );
4473 execute( TC_meas_res_sign_sdcch4() );
4474 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01004475 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01004476 execute( TC_rsl_ms_pwr_ctrl() );
Harald Welte70767382018-02-21 12:16:40 +01004477 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01004478 execute( TC_paging_imsi_80percent() );
4479 execute( TC_paging_tmsi_80percent() );
4480 execute( TC_paging_imsi_200percent() );
4481 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01004482 execute( TC_rsl_protocol_error() );
4483 execute( TC_rsl_mand_ie_error() );
4484 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01004485 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01004486 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01004487 execute( TC_si_sched_2bis() );
4488 execute( TC_si_sched_2ter() );
4489 execute( TC_si_sched_2ter_2bis() );
4490 execute( TC_si_sched_2quater() );
4491 execute( TC_si_sched_13() );
4492 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01004493 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01004494 execute( TC_ipa_crcx_twice_not_active() );
4495 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01004496 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01004497 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01004498
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01004499 if (mp_pcu_socket != "") {
4500 execute( TC_pcu_act_req() );
4501 execute( TC_pcu_act_req_wrong_ts() );
4502 execute( TC_pcu_act_req_wrong_bts() );
4503 execute( TC_pcu_act_req_wrong_trx() );
4504 execute( TC_pcu_deact_req() );
4505 execute( TC_pcu_deact_req_wrong_ts() );
4506 execute( TC_pcu_ver_si13() );
4507 execute( TC_pcu_data_req_wrong_bts() );
4508 execute( TC_pcu_data_req_wrong_trx() );
4509 execute( TC_pcu_data_req_wrong_ts() );
4510 execute( TC_pcu_data_req_ts_inactive() );
4511 execute( TC_pcu_data_req_pdtch() );
4512 execute( TC_pcu_data_req_ptcch() );
4513 execute( TC_pcu_data_req_agch() );
4514 execute( TC_pcu_data_req_imm_ass_pch() );
4515 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004516 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01004517 execute( TC_pcu_paging_from_rsl() );
4518 } else {
4519 log("PCU socket path not available, skipping PCU tests");
4520 }
Harald Welte3d04ae62018-04-04 20:29:05 +02004521
4522 execute( TC_dyn_osmo_pdch_act_deact() );
4523 execute( TC_dyn_osmo_pdch_unsol_deact() );
4524 execute( TC_dyn_osmo_pdch_double_act() );
4525 execute( TC_dyn_osmo_pdch_tchf_act() );
4526 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02004527 execute( TC_dyn_ipa_pdch_act_deact() );
4528 execute( TC_dyn_ipa_pdch_tchf_act() );
4529 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
4530 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01004531
4532 execute( TC_rll_est_ind() );
4533 execute( TC_rll_est_req_DCCH_3() );
4534 execute( TC_rll_est_req_ACCH_3() );
4535 execute( TC_rll_rel_ind_DCCH_0() );
4536 execute( TC_rll_rel_ind_DCCH_3() );
4537 execute( TC_rll_rel_ind_ACCH_0() );
4538 execute( TC_rll_rel_ind_ACCH_3() );
4539 execute( TC_rll_rel_req() );
4540 execute( TC_rll_unit_data_req_DCCH() );
4541 execute( TC_rll_unit_data_req_ACCH() );
4542 execute( TC_rll_unit_data_ind_DCCH() );
4543 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02004544
4545 execute( TC_chan_act_a51() );
4546 execute( TC_chan_act_a52() );
4547 execute( TC_chan_act_a53() );
4548 execute( TC_encr_cmd_a51() );
4549 execute( TC_encr_cmd_a52() );
4550 execute( TC_encr_cmd_a53() );
4551
Harald Welteee25aae2019-05-19 14:32:37 +02004552 execute( TC_err_rep_wrong_mdisc() );
4553 execute( TC_err_rep_wrong_msg_type() );
4554 execute( TC_err_rep_wrong_sequence() );
4555
Harald Weltee613f962018-04-18 22:38:16 +02004556 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02004557
4558 execute( TC_tch_sign_l2_fill_frame() );
4559 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004560
4561 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004562 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01004563}
4564
4565
4566}