blob: aee081e940a3de493bd74603c655942d704129ad [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
3import from General_Types all;
4import from GSM_Types all;
5import from GSM_RR_Types all;
6import from Osmocom_Types all;
7import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +01008import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +01009import from L1CTL_PortType all;
10import from L1CTL_Types all;
11import from LAPDm_Types all;
12import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020013import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010014
15import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010016import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010017import from IPA_Emulation all;
18import from RSL_Emulation all;
19
20import from IPL4asp_Types all;
21import from TRXC_Types all;
22import from TRXC_CodecPort all;
23import from TRXC_CodecPort_CtrlFunct all;
24
Harald Welte883340c2018-02-28 18:59:29 +010025import from PCUIF_Types all;
26import from PCUIF_CodecPort all;
27
Harald Welte7484fc42018-02-24 14:09:45 +010028import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010029import from MobileL3_RRM_Types all;
30import from MobileL3_Types all;
31import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010032
Harald Welte8da48242018-02-27 20:41:32 +010033import from Osmocom_VTY_Functions all;
34import from TELNETasp_PortType all;
35
Harald Welte70767382018-02-21 12:16:40 +010036/* The tests assume a BTS with the following timeslot configuration:
37 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020038 * TS1 : TCH/F
39 * TS2 : TCH/F
40 * TS3 : TCH/F_PDCH (IPA Style)
41 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010042 * TS5 : TCH/H
43 * TS6 : SDCCH/8
44 * TS7 : PDCH
45 */
46
47modulepar {
48 charstring mp_rsl_ip := "127.0.0.2";
49 integer mp_rsl_port := 3003;
50 integer mp_trx0_arfcn := 871;
Harald Weltea4d8f352018-03-01 15:47:20 +010051 charstring mp_bb_trxc_ip := "127.0.0.1";
Harald Welteef3e1c92018-02-28 23:40:14 +010052 integer mp_bb_trxc_port := 6701;
Harald Welte883340c2018-02-28 18:59:29 +010053 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Harald Welted5684392018-03-10 18:22:04 +010054 integer mp_tolerance_rxqual := 1;
55 integer mp_tolerance_rxlev := 3;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020056 charstring mp_ctrl_ip := "127.0.0.1";
57 integer mp_ctrl_port := 4238;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020058 integer mp_rxlev_exp := 57;
Harald Welte70767382018-02-21 12:16:40 +010059}
60
Harald Welte629cc6b2018-03-11 17:19:05 +010061type record of RslChannelNr ChannelNrs;
62
Harald Welte70767382018-02-21 12:16:40 +010063type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010064 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010065 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010066 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010067 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010068 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010069 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010070
71 /* L1CTL port (for classic tests) */
72 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010073
Harald Welte54a2a2d2018-02-26 09:14:05 +010074 /* TRXC port (for classic tests) */
75 port TRXC_CODEC_PT BB_TRXC;
76 var integer g_bb_trxc_conn_id;
77
Harald Welte8da48242018-02-27 20:41:32 +010078 port TELNETasp_PT BTSVTY;
79
Harald Welte883340c2018-02-28 18:59:29 +010080 /* PCU Interface of BTS */
81 port PCUIF_CODEC_PT PCU;
82 var integer g_pcu_conn_id;
83 /* Last PCU INFO IND we received */
84 var PCUIF_Message g_pcu_last_info;
85
Harald Welte48494ca2018-02-25 16:59:50 +010086 /* SI configuration */
87 var SystemInformationConfig si_cfg := {
88 bcch_extended := false,
89 si1_present := false,
90 si2bis_present := false,
91 si2ter_present := false,
92 si2quater_present := false,
93 si7_present := false,
94 si8_present := false,
95 si9_present := false,
96 si13_present := false,
97 si13alt_present := false,
98 si15_present := false,
99 si16_present := false,
100 si17_present := false,
101 si2n_present := false,
102 si21_present := false,
103 si22_present := false
104 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100105
106 /* all logical channels available on the BTS */
107 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100108 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100109}
110
111/* an individual call / channel */
112type component ConnHdlr extends RSL_DchanHdlr {
113 port L1CTL_PT L1CTL;
114
115 port TRXC_CODEC_PT BB_TRXC;
116 var integer g_bb_trxc_conn_id;
117
118 timer g_Tguard;
119 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
120
121 var ConnHdlrPars g_pars;
122 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100123 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200124
125 /* PCU Interface of BTS */
126 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100127}
128
129function f_init_rsl(charstring id) runs on test_CT {
130 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
131 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
132
133 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
134 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
135 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
136
137 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
138 vc_RSL.start(RSL_Emulation.main(false));
139}
140
141type record ConnHdlrPars {
142 RslChannelNr chan_nr,
143 RSL_IE_ChannelMode chan_mode,
144 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100145 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200146 TestSpecUnion spec optional,
147 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100148}
149
150/* Test-specific parameters */
151type union TestSpecUnion {
152 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100153}
154
Harald Welte82ccef72018-02-25 16:17:33 +0100155template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100156 max_retrans := RACH_MAX_RETRANS_7,
157 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100158 cell_barr_access := false,
159 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100160 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100161};
162
Harald Weltef10153f2018-02-25 16:34:05 +0100163template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100164 cell_resel_hyst_2dB := 2,
165 ms_txpwr_max_cch := 7,
Harald Weltef10153f2018-02-25 16:34:05 +0100166 acs := '0'B,
167 neci := true,
168 rxlev_access_min := 0
169}
170
171template (value) LocationAreaIdentification ts_LAI_default := {
172 mcc_mnc := '262F42'H,
173 lac := 42
174}
175
Harald Welte7484fc42018-02-24 14:09:45 +0100176/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100177template (value) SystemInformation ts_SI3_default := {
178 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100179 payload := {
180 si3 := {
181 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100182 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100183 ctrl_chan_desc := {
184 msc_r99 := true,
185 att := true,
186 bs_ag_blks_res := 1,
187 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100188 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100189 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
190 spare := '00'B,
191 bs_pa_mfrms := 0, /* 2 multiframes */
192 t3212 := 1 /* 6 minutes */
193 },
Harald Welte82ccef72018-02-25 16:17:33 +0100194 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100195 dn_ind := false,
196 pwrc := false,
197 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100198 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100199 },
Harald Weltef10153f2018-02-25 16:34:05 +0100200 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100201 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100202 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100203 }
204 }
205}
Harald Welte70767382018-02-21 12:16:40 +0100206
Harald Weltef8df4cb2018-03-10 15:15:08 +0100207template (value) SystemInformation ts_SI2_default := {
208 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100209 payload := {
210 si2 := {
211 bcch_freq_list := '00000000000000000000000000000000'O,
212 ncc_permitted := '11111111'B,
213 rach_control := ts_RachCtrl_default
214 }
215 }
216}
217
Harald Weltef8df4cb2018-03-10 15:15:08 +0100218template (value) SystemInformation ts_SI4_default := {
219 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100220 payload := {
221 si4 := {
222 lai := ts_LAI_default,
223 cell_sel_par := ts_CellSelPar_default,
224 rach_control := ts_RachCtrl_default,
225 cbch_chan_desc := omit,
226 cbch_mobile_alloc := omit,
227 rest_octets := ''O
228 }
229 }
230}
231
232function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
233runs on test_CT {
234 log("Setting ", rsl_si_type, ": ", si_enc);
235 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
236}
237
238function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
239runs on test_CT {
240 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
241 log("Setting ", rsl_si_type, ": ", si_dec);
242 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
243}
244
Harald Welte8da48242018-02-27 20:41:32 +0100245private function f_init_vty(charstring id) runs on test_CT {
246 map(self:BTSVTY, system:BTSVTY);
247 f_vty_set_prompts(BTSVTY);
248 f_vty_transceive(BTSVTY, "enable");
249}
250
Harald Welte883340c2018-02-28 18:59:29 +0100251/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200252private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
253 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100254 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200255 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
256 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100257 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200258 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Harald Welted378a252018-03-13 17:02:14 +0100259 setverdict(fail, "Invalid PCU Version/BTS Number received");
260 self.stop;
Harald Welte883340c2018-02-28 18:59:29 +0100261 }
262}
263
Harald Weltef26de0b2018-04-04 20:28:05 +0200264private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
265 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100266 timer T := 2.0;
267 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100268 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200269 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100270 return;
271 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200272 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100273
274 T.start;
275 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200276 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100277 [] T.timeout {
278 setverdict(fail, "Timeout waiting for PCU INFO_IND");
279 self.stop;
280 }
281 }
282}
283
Harald Welte70767382018-02-21 12:16:40 +0100284/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100285function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte83f6dbf2018-06-03 18:26:50 +0200286 timer T := 10.0;
Harald Welte629cc6b2018-03-11 17:19:05 +0100287 g_AllChannels := {
288 /* TS 1..4: TCH/F */
289 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
290 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
291 /* TS 5: TCH/H */
292 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
293 /* TS 0: SDCCH/4 */
294 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
295 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
296 /* TS 6: SDCCH/8 */
297 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
298 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
299 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
300 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
301 };
Harald Welte0472ab42018-03-12 15:02:26 +0100302 g_AllChanTypes := {
303 /* TS 1..4: TCH/F */
304 //valueof(ts_RslChanNr_Bm(1)),
305 /* TS 5: TCH/H */
306 //valueof(ts_RslChanNr_Lm(5,1)),
307 /* TS 0: SDCCH/4 */
308 valueof(ts_RslChanNr_SDCCH4(0,2)),
309 /* TS 6: SDCCH/8 */
310 valueof(ts_RslChanNr_SDCCH8(6,4))
311 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100312
Harald Welte70767382018-02-21 12:16:40 +0100313 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200314 T.start;
315 alt {
316 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
317 [] T.timeout {
318 setverdict(fail, "Timeout waiting for ASP_IPA_EVENT_UP");
319 self.stop;
320 }
321 }
Harald Welte2d142592018-02-25 13:19:44 +0100322 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100323 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200324 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100325
326 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100327 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
328 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
329 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
330 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100331
Harald Weltef26de0b2018-04-04 20:28:05 +0200332 map(self:PCU, system:PCU);
333 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100334
Harald Welte84271622018-03-10 17:21:03 +0100335 if (mp_bb_trxc_port != -1) {
336 var TrxcMessage ret;
337 /* start with a default moderate timing offset equalling TA=2 */
338 f_main_trxc_connect();
339 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
340 }
Harald Welte70767382018-02-21 12:16:40 +0100341}
342
Harald Welte294b0a22018-03-10 23:26:48 +0100343function f_shutdown() runs on test_CT {
Daniel Willmanncc7bbeb2018-07-03 16:33:56 +0200344 /* mtc.stop cleanly stops testcase execution to avoid unclean shutdown */
345 mtc.stop;
Harald Welte294b0a22018-03-10 23:26:48 +0100346}
347
Harald Welte68e495b2018-02-25 00:05:57 +0100348/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
349function f_init_l1ctl() runs on test_CT {
350 map(self:L1CTL, system:L1CTL);
351 f_connect_reset(L1CTL);
352}
353
Harald Welte70767382018-02-21 12:16:40 +0100354type function void_fn(charstring id) runs on ConnHdlr;
355
356/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200357function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100358runs on test_CT return ConnHdlr {
359 var charstring id := testcasename();
360 var ConnHdlr vc_conn;
361
362 vc_conn := ConnHdlr.create(id);
363 /* connect to RSL Emulation main component */
364 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
365 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200366 if (pcu_comp) {
367 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
368 * it from the test_CT and connect it to the component. This obviously only
369 * works for one component, i.e. no concurrency */
370 unmap(self:PCU, system:PCU);
371 map(vc_conn:PCU, system:PCU);
372 }
Harald Welte70767382018-02-21 12:16:40 +0100373
374 vc_conn.start(f_handler_init(fn, id, pars));
375 return vc_conn;
376}
377
Harald Welte7484fc42018-02-24 14:09:45 +0100378template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
379 streamId := sid,
380 rsl := rsl
381}
382
383template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
384 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
385 streamId := sid,
386 rsl := rsl
387}
388
Harald Welte70767382018-02-21 12:16:40 +0100389private altstep as_Tguard() runs on ConnHdlr {
390 [] g_Tguard.timeout {
391 setverdict(fail, "Tguard timeout");
392 self.stop;
393 }
394}
395
Harald Welte68e495b2018-02-25 00:05:57 +0100396private function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200397 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100398}
399
400private function f_trxc_connect() runs on ConnHdlr {
401 map(self:BB_TRXC, system:BB_TRXC);
402 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100403 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
404 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200405 if (not ispresent(res.connId)) {
406 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
407 self.stop;
408 }
Harald Welte70767382018-02-21 12:16:40 +0100409 g_bb_trxc_conn_id := res.connId;
410}
411
412private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100413 var TrxcMessage ret;
414 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100415}
416
417private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100418 var TrxcMessage ret;
419 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100420}
421
422/* first function started in ConnHdlr component */
423private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
424runs on ConnHdlr {
425 g_pars := pars;
426 g_chan_nr := pars.chan_nr;
427
428 map(self:L1CTL, system:L1CTL);
429 f_connect_reset(L1CTL);
430
Harald Welte84271622018-03-10 17:21:03 +0100431 if (mp_bb_trxc_port != -1) {
432 f_trxc_connect();
433 }
Harald Welte70767382018-02-21 12:16:40 +0100434
435 g_Tguard.start(pars.t_guard);
436 activate(as_Tguard());
437
438 f_rslem_register(0, pars.chan_nr);
439
440 /* call the user-supplied test case function */
441 fn.apply(id);
442}
443
Harald Welteb1726c92018-03-30 11:56:38 +0200444function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
445 boolean ignore_other := false)
446runs on ConnHdlr return RSL_Message {
447 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100448 timer T := 3.0;
449 RSL.send(tx);
450 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100451 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200452 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100453 T.stop;
454 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100455 }
Harald Welte1eba3742018-02-25 12:48:14 +0100456 [] T.timeout {
457 setverdict(fail, "Timeout expecting " & id);
458 self.stop;
459 }
Harald Welte21240e62018-03-11 21:43:35 +0100460 [not ignore_other] as_l1_sacch();
461 [not ignore_other] as_meas_res();
462 [not ignore_other] as_l1_dcch();
463 [not ignore_other] RSL.receive {
Harald Welte1eba3742018-02-25 12:48:14 +0100464 setverdict(fail, "Unexpected RSL message received");
Harald Welteb1726c92018-03-30 11:56:38 +0200465 self.stop;
Harald Welte70767382018-02-21 12:16:40 +0100466 }
Harald Welte21240e62018-03-11 21:43:35 +0100467 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100468 }
Harald Welteb1726c92018-03-30 11:56:38 +0200469 return rx;
470}
471
472function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
473 boolean ignore_other := false)
474runs on ConnHdlr {
475 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100476}
477
Harald Weltee613f962018-04-18 22:38:16 +0200478function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false)
479runs on ConnHdlr {
480 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
481 if (encr_enable) {
482 /* append encryption related IEs, if requested */
483 var RSL_IE_EncryptionInfo encr_info;
484 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
485 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
486encr_info})) };
487 }
488 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100489}
490
Harald Welte70767382018-02-21 12:16:40 +0100491function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100492 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 +0100493 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100494}
495
Harald Welte70767382018-02-21 12:16:40 +0100496private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
497 template RSL_IE_ChannelMode chan_mode,
498 float t_guard := 20.0) := {
499 chan_nr := valueof(chan_nr),
500 chan_mode := valueof(chan_mode),
501 t_guard := t_guard,
502 l1_pars := {
503 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100504 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100505 meas_ul := {
506 full := {
507 rxlev := dbm2rxlev(-53),
508 rxqual := 0
509 },
510 sub := {
511 rxlev := dbm2rxlev(-53),
512 rxqual := 0
513 }
514 },
515 timing_offset_256syms := 0,
516 bs_power_level := 0,
517 ms_power_level := 0,
518 ms_actual_ta := 0
Harald Welte0472ab42018-03-12 15:02:26 +0100519 },
Harald Weltee613f962018-04-18 22:38:16 +0200520 spec := omit,
521 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100522}
523
Harald Welte93640c62018-02-25 16:59:33 +0100524/***********************************************************************
525 * Channel Activation / Deactivation
526 ***********************************************************************/
527
Harald Welte70767382018-02-21 12:16:40 +0100528/* Stress test: Do 500 channel activations/deactivations in rapid succession */
529function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
530 for (var integer i := 0; i < 500; i := i+1) {
531 f_rsl_chan_act(g_pars.chan_mode);
532 f_rsl_chan_deact();
533 }
534 setverdict(pass);
535}
536testcase TC_chan_act_stress() runs on test_CT {
537 var ConnHdlr vc_conn;
538 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
539 f_init(testcasename());
540 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
541 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100542 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100543}
544
545/* Test if re-activation of an already active channel fails as expected */
546function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
547 f_rsl_chan_act(g_pars.chan_mode);
548 /* attempt to activate the same lchan again -> expect reject */
549 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
550 alt {
551 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
552 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
553 }
554 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
555 setverdict(pass);
556 }
557 }
558 f_rsl_chan_deact();
559}
560testcase TC_chan_act_react() runs on test_CT {
561 var ConnHdlr vc_conn;
562 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100563 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100564 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
565 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100566 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100567}
568
569/* Attempt to de-activate a channel that's not active */
570function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
571 timer T := 3.0;
572 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
573 T.start;
574 alt {
575 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
576 setverdict(pass);
577 }
578 [] T.timeout {
579 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
580 }
581 }
582}
583testcase TC_chan_deact_not_active() runs on test_CT {
584 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100585 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100586 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
587 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100588 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100589}
590
591/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
592function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
593 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
594 alt {
595 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
596 setverdict(fail, "Unexpected CHAN ACT ACK");
597 }
598 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
599 setverdict(pass);
600 }
601 }
602}
603private type record WrongChanNrCase {
604 RslChannelNr chan_nr,
605 charstring description
606}
607private type record of WrongChanNrCase WrongChanNrCases;
608private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
609 chan_nr := chan_nr,
610 description := desc
611}
612
613testcase TC_chan_act_wrong_nr() runs on test_CT {
614 var ConnHdlr vc_conn;
615 var ConnHdlrPars pars;
616
Harald Welte294b0a22018-03-10 23:26:48 +0100617 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100618
619 var WrongChanNrCases wrong := {
620 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
621 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
622 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
623 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
624 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
625 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
626 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
627 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
628 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
629 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
630 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
631 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
632 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
633 };
634
635 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
636 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
637 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
638 vc_conn.done;
639 }
Harald Welte294b0a22018-03-10 23:26:48 +0100640 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100641}
642
Harald Weltee613f962018-04-18 22:38:16 +0200643/* execute the same callback function on a variety of logical channels */
644private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
645 var ConnHdlr vc_conn;
646 f_init(testcasename());
647
648 /* test on each of the channels we have */
649 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
650 pars.chan_nr := valueof(g_AllChanTypes[i]);
651
652 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
653 vc_conn := f_start_handler(fn, pars);
654 vc_conn.done;
655 }
656
657 f_shutdown();
658}
659
Harald Welte93640c62018-02-25 16:59:33 +0100660/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100661 * SACCH handling
662 ***********************************************************************/
663
664private function f_exp_sacch(boolean exp) runs on ConnHdlr {
665 timer T_sacch := 3.0;
666 T_sacch.start;
667 alt {
668 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
669 setverdict(fail, "Received SACCH when not expecting it");
670 }
671 [not exp] T_sacch.timeout {
672 setverdict(pass);
673 }
674 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
675 setverdict(pass);
676 }
677 [exp] T_sacch.timeout {
678 setverdict(fail, "Timeout waiting for SACCH on ", g_chan_nr);
679 }
680 [] L1CTL.receive { repeat; }
681 [] RSL.receive { repeat; }
682 }
683}
684
685/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
686private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
687 f_l1_tune(L1CTL);
688 RSL.clear;
689
690 /* activate the logical channel */
691 f_est_dchan();
692 L1CTL.clear;
693
694 /* check that SACCH actually are received as expected */
695 f_exp_sacch(true);
696
697 /* deactivate SACCH on the logical channel */
698 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
699 f_sleep(1.0);
700 L1CTL.clear;
701
702 /* check that no SACCH are received anymore */
703 f_exp_sacch(false);
704
705 /* release the channel */
706 f_rsl_chan_deact();
707 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
708}
709testcase TC_deact_sacch() runs on test_CT {
710 var ConnHdlr vc_conn;
711 var ConnHdlrPars pars;
712 f_init();
713 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
714 //for (var integer i := 0; i < 1; i := i+1) {
715 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
716 log(testcasename(), ": Starting for ", g_AllChannels[i]);
717 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
718 vc_conn.done;
719 }
720 /* TODO: do the above in parallel, rather than sequentially? */
721 f_shutdown();
722}
723
Harald Welte55700662018-03-12 13:15:43 +0100724/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100725private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
726 var L1ctlDlMessage dl;
727 /* check that the specified SI5 value is actually sent */
728 timer T_sacch := 3.0;
729 L1CTL.clear;
730 T_sacch.start;
731 alt {
732 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
733 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
734 if (match(l3, l3_exp)) {
735 setverdict(pass);
736 } else {
737 repeat;
738 }
739 }
740 [] L1CTL.receive { repeat; }
741 [] T_sacch.timeout {
742 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
743 self.stop;
744 }
745 }
746}
747
Harald Welte55700662018-03-12 13:15:43 +0100748/* verify that given SACCH payload is not present */
749private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
750 var L1ctlDlMessage dl;
751 /* check that the specified SI5 value is actually sent */
752 timer T_sacch := 3.0;
753 L1CTL.clear;
754 T_sacch.start;
755 alt {
756 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
757 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
758 if (match(l3, l3_exp)) {
759 setverdict(fail, "Received unexpected SACCH ", dl);
Daniel Willmann3487a852018-07-05 15:41:59 +0200760 mtc.stop;
Harald Welte55700662018-03-12 13:15:43 +0100761 } else {
762 repeat;
763 }
764 }
765 [] L1CTL.receive { repeat; }
766 [] T_sacch.timeout {
767 setverdict(pass);
768 }
769 }
770}
771
Harald Welte629cc6b2018-03-11 17:19:05 +0100772/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100773private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
774 /* Set a known default SACCH filling for SI5 */
775 var octetstring si5 := f_rnd_octstring(19);
776 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
777
778 f_l1_tune(L1CTL);
779 RSL.clear;
780
781 /* activate the logical channel */
782 f_est_dchan();
783
784 /* check that the specified SI5 value is actually sent */
785 f_sacch_present(si5);
786
787 /* release the channel */
788 RSL.clear;
789 f_rsl_chan_deact();
790 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
791}
792testcase TC_sacch_filling() runs on test_CT {
793 var ConnHdlr vc_conn;
794 var ConnHdlrPars pars;
795 f_init();
796 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
797 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
798 log(testcasename(), ": Starting for ", g_AllChannels[i]);
799 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
800 vc_conn.done;
801 }
802 /* TODO: do the above in parallel, rather than sequentially? */
803 f_shutdown();
804}
805
Harald Welte629cc6b2018-03-11 17:19:05 +0100806/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100807private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
808 /* Set a known default SACCH filling for SI5 */
809 var octetstring si5 := f_rnd_octstring(19);
810 var octetstring si5_diff := f_rnd_octstring(19);
811 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
812
813 f_l1_tune(L1CTL);
814 RSL.clear;
815
816 log("Activating channel, expecting standard SI5");
817 /* activate the logical channel */
818 f_est_dchan();
819 /* check that the specified SI5 value is actually sent */
820 f_sacch_present(si5);
821
822 /* set channel-specific different SI5 */
823 log("Setting channel specific SACCH INFO, expecting it");
824 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
825 /* check that the specified lchan-specific value is now used */
826 f_sacch_present(si5_diff);
827
828 /* deactivate the channel and re-activate it, this should result in default SI5 */
829 log("De-activating and re-activating channel, expecting standard SI5");
830 f_rsl_chan_deact();
831 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
832 /* Verify that the TRX-wide default SACCH filling is present again */
833 f_sacch_present(si5);
834
835 /* release the channel */
836 RSL.clear;
837 f_rsl_chan_deact();
838 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
839}
840testcase TC_sacch_info_mod() runs on test_CT {
841 var ConnHdlr vc_conn;
842 var ConnHdlrPars pars;
843 f_init();
844 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
845 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
846 log(testcasename(), ": Starting for ", g_AllChannels[i]);
847 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
848 vc_conn.done;
849 }
850 /* TODO: do the above in parallel, rather than sequentially? */
851 f_shutdown();
852}
853
Harald Welte075d84c2018-03-12 13:07:24 +0100854/* Test SACCH scheduling of multiple different SI message types */
855private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
856 var octetstring si5 := f_rnd_octstring(19);
857 var octetstring si5bis := f_rnd_octstring(19);
858 var octetstring si5ter := f_rnd_octstring(19);
859 var octetstring si6 := f_rnd_octstring(19);
860
861 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
862 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
863 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
864 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
865
866 f_l1_tune(L1CTL);
867 RSL.clear;
868
869 /* activate the logical channel */
870 f_est_dchan();
871 L1CTL.clear;
872
873 /* check that SACCH actually are received as expected */
874 f_sacch_present(si5);
875 f_sacch_present(si5bis);
876 f_sacch_present(si5ter);
877 f_sacch_present(si6);
878
879 /* release the channel */
880 f_rsl_chan_deact();
881 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
882}
883testcase TC_sacch_multi() runs on test_CT {
884 var ConnHdlr vc_conn;
885 var ConnHdlrPars pars;
886 f_init();
887 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
888 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
889 log(testcasename(), ": Starting for ", g_AllChannels[i]);
890 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
891 vc_conn.done;
892 }
893 /* TODO: do the above in parallel, rather than sequentially? */
894 f_shutdown();
895}
896
Harald Welte55700662018-03-12 13:15:43 +0100897/* Test if SACH information is modified as expected */
898private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
899 var octetstring si5 := f_rnd_octstring(19);
900 var octetstring si6 := f_rnd_octstring(19);
901
902 /* First, configure both SI5 and SI6 to be transmitted */
903 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
904 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
905
906 f_l1_tune(L1CTL);
907 RSL.clear;
908
909 /* activate the logical channel */
910 f_est_dchan();
911 L1CTL.clear;
912
913 /* check that SACCH actually are received as expected */
914 f_sacch_present(si5);
915 f_sacch_present(si6);
916
917 /* disable SI6 */
918 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
919
920 /* check that SI5 is still transmitted */
921 f_sacch_present(si5);
922 /* check if SI6 is now gone */
923 f_sacch_missing(si6);
924
925 /* release the channel */
926 f_rsl_chan_deact();
927 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
928}
929testcase TC_sacch_multi_chg() runs on test_CT {
930 var ConnHdlr vc_conn;
931 var ConnHdlrPars pars;
932 f_init();
933 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
934 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
935 log(testcasename(), ": Starting for ", g_AllChannels[i]);
936 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
937 vc_conn.done;
938 }
939 /* TODO: do the above in parallel, rather than sequentially? */
940 f_shutdown();
941}
942
Harald Welte075d84c2018-03-12 13:07:24 +0100943/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
944/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100945
946
947/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100948 * RACH Handling
949 ***********************************************************************/
950
Harald Welte8c24c2b2018-02-26 08:31:31 +0100951/* like L1SAP_IS_PACKET_RACH */
952private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100953 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100954 return true;
955 }
956 return false;
957}
958
959/* generate a random RACH for circuit-switched */
960private function f_rnd_ra_cs() return OCT1 {
961 var OCT1 ra;
962 do {
963 ra := f_rnd_octstring(1);
964 } while (ra_is_ps(ra));
965 return ra;
966}
967
Harald Welte883340c2018-02-28 18:59:29 +0100968/* generate a random RACH for packet-switched */
969private function f_rnd_ra_ps() return OCT1 {
970 var OCT1 ra;
971 do {
972 ra := f_rnd_octstring(1);
973 } while (not ra_is_ps(ra));
974 return ra;
975}
976
Harald Welte8c24c2b2018-02-26 08:31:31 +0100977/* Send 1000 RACH requests and check their RA+FN on the RSL side */
978testcase TC_rach_content() runs on test_CT {
979 f_init(testcasename());
980 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100981 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100982
Harald Welte8c24c2b2018-02-26 08:31:31 +0100983 var GsmFrameNumber fn_last := 0;
984 for (var integer i := 0; i < 1000; i := i+1) {
985 var OCT1 ra := f_rnd_ra_cs();
986 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
987 if (fn == fn_last) {
988 setverdict(fail, "Two RACH in same FN?!?");
989 self.stop;
990 }
991 fn_last := fn;
992
993 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100994 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100995 alt {
996 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
997 T.stop;
998 }
999 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
1000 setverdict(fail, "Unexpected CHAN RQD");
1001 self.stop;
1002 }
1003 [] RSL_CCHAN.receive { repeat; }
1004 [] T.timeout {
1005 setverdict(fail, "Timeout waiting for CHAN RQD");
1006 self.stop;
1007 }
1008 }
1009 }
1010 setverdict(pass);
Harald Welte294b0a22018-03-10 23:26:48 +01001011 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001012}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001013
1014/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1015testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001016 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001017 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001019 f_l1_tune(L1CTL);
1020
1021 var GsmFrameNumber fn_last := 0;
1022 for (var integer i := 0; i < 1000; i := i+1) {
1023 var OCT1 ra := f_rnd_ra_cs();
1024 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1025 if (fn == fn_last) {
1026 setverdict(fail, "Two RACH in same FN?!?");
1027 self.stop;
1028 }
1029 fn_last := fn;
1030 }
1031 var integer rsl_chrqd := 0;
1032 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001033 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001034 alt {
1035 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1036 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001037 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001038 repeat;
1039 }
1040 [] RSL_CCHAN.receive { repeat; }
1041 [] T.timeout { }
1042 }
1043 if (rsl_chrqd == 1000) {
1044 setverdict(pass);
1045 } else {
1046 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
1047 }
Harald Welte294b0a22018-03-10 23:26:48 +01001048 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001049}
1050
Harald Welte54a2a2d2018-02-26 09:14:05 +01001051private function f_main_trxc_connect() runs on test_CT {
1052 map(self:BB_TRXC, system:BB_TRXC);
1053 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +01001054 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
1055 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001056 if (not ispresent(res.connId)) {
1057 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
1058 self.stop;
1059 }
Harald Welte54a2a2d2018-02-26 09:14:05 +01001060 g_bb_trxc_conn_id := res.connId;
1061}
1062
1063private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001064 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001065 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +01001066 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001067 f_sleep(0.5);
1068
1069 /* Transmit RACH request + wait for confirmation */
1070 var OCT1 ra := f_rnd_ra_cs();
1071 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1072
1073 /* Check for expected result */
1074 timer T := 1.5;
1075 T.start;
1076 alt {
1077 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1078 setverdict(pass);
1079 }
1080 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +01001081 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001082 }
1083 [] RSL_CCHAN.receive { repeat; }
1084 [not expect_pass] T.timeout {
1085 setverdict(pass);
1086 }
1087 [expect_pass] T.timeout {
1088 setverdict(fail, "Timeout waiting for CHAN RQD");
1089 }
1090 }
1091}
1092
1093/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1094testcase TC_rach_max_ta() runs on test_CT {
1095 f_init(testcasename());
1096 f_init_l1ctl();
1097 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001098 f_sleep(1.0);
1099
1100 /* default max-ta is 63 (full range of GSM timing advance */
1101
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001102 /* We allow early arrival up to 2 symbols */
1103 f_rach_toffs(-1*256, true);
1104 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001105 f_rach_toffs(-10*256, false);
1106
1107 /* 0 / 32 / 63 bits is legal / permitted */
1108 f_rach_toffs(0, true);
1109 f_rach_toffs(32*256, true);
1110 f_rach_toffs(63*256, true);
1111
1112 /* more than 63 bits is not legal / permitted */
1113 f_rach_toffs(64*256, false);
1114 f_rach_toffs(127*256, false);
Harald Welte294b0a22018-03-10 23:26:48 +01001115 f_shutdown();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001116}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001117
Harald Welte93640c62018-02-25 16:59:33 +01001118/***********************************************************************
1119 * Measurement Processing / Reporting
1120 ***********************************************************************/
1121
Harald Welte70767382018-02-21 12:16:40 +01001122template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1123 spare := '0'B,
1124 lpd := 0,
1125 sapi := sapi,
1126 c_r := c_r,
1127 ea := true
1128}
1129
Harald Welted879bd92018-03-12 15:01:23 +01001130template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001131 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001132 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001133 len := 0, /* overwritten */
1134 m := false,
1135 el := 1,
1136 payload := pl
1137}
1138
1139/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1140altstep as_l1_sacch() runs on ConnHdlr {
1141 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001142 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001143 log("SACCH received: ", l1_dl.payload.data_ind.payload);
1144 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001145 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001146 log("LAPDm: ", lb);
Harald Welted879bd92018-03-12 15:01:23 +01001147 var octetstring pl := '0000'O & enc_LapdmFrameAB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001148 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001149 repeat;
1150 }
1151}
1152
1153altstep as_l1_dcch() runs on ConnHdlr {
1154 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001155 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001156 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1157 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001158 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001159 repeat;
1160 }
1161}
1162
1163type record MeasElem {
1164 uint6_t rxlev,
1165 uint3_t rxqual
1166}
1167
1168type record MeasElemFS {
1169 MeasElem full,
1170 MeasElem sub
1171}
1172
1173type record ConnL1Pars {
1174 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001175 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001176 MeasElemFS meas_ul,
1177 int16_t timing_offset_256syms,
1178 uint5_t bs_power_level,
1179 uint5_t ms_power_level,
1180 uint8_t ms_actual_ta
1181}
1182
1183/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1184private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1185 return 63 + (toffs256s/256);
1186}
1187
Harald Welted5684392018-03-10 18:22:04 +01001188private function f_max(integer a, integer b) return integer {
1189 if (a > b) {
1190 return a;
1191 } else {
1192 return b;
1193 }
1194}
1195
1196private function f_min(integer a, integer b) return integer {
1197 if (a < b) {
1198 return a;
1199 } else {
1200 return b;
1201 }
1202}
1203
1204/* compute negative tolerance val-tolerance, ensure >= min */
1205private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1206 val := val - tolerance;
1207 return f_max(val, min);
1208}
1209
1210/* compute positive tolerance val+tolerance, ensure <= max */
1211private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1212 val := val + tolerance;
1213 return f_min(val, max);
1214}
1215
1216/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1217private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1218return template integer {
1219 var template integer ret;
1220 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1221 return ret;
1222}
1223
1224
Harald Welte70767382018-02-21 12:16:40 +01001225/* build a template for matching measurement results against */
1226private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1227 var ConnL1Pars l1p := g_pars.l1_pars;
1228 var template RSL_IE_UplinkMeas ul_meas := {
1229 len := 3,
1230 rfu := '0'B,
1231 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001232 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001233 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001234 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001235 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001236 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1237 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001238 supp_meas_info := omit
1239 };
Harald Welte685d5982018-02-27 20:42:05 +01001240 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001241 ul_meas.len := (3+8);
1242 ul_meas.supp_meas_info := {
1243 toa256_mean := l1p.timing_offset_256syms,
1244 toa256_min := ?,
1245 toa256_max := ?,
1246 toa256_std_dev := ?
1247 }
Harald Welte685d5982018-02-27 20:42:05 +01001248 }
Harald Welte70767382018-02-21 12:16:40 +01001249 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
1250 ul_meas.rxlev_f_u := ?;
1251 ul_meas.rxlev_s_u := ?;
1252 ul_meas.rxq_f_u := ?;
1253 ul_meas.rxq_s_u := ?;
1254 var template RSL_IE_BS_Power bs_power := {
1255 reserved := 0,
1256 epc := false,
1257 fpc := false,
1258 power_level := l1p.bs_power_level
1259 };
1260 var template RSL_IE_L1Info l1_info := {
1261 ms_power_lvl := l1p.ms_power_level,
1262 fpc := false,
1263 reserved := 0,
1264 actual_ta := l1p.ms_actual_ta
1265 };
1266 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
1267 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
1268 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1269 ?, t_toffs);
1270}
1271
1272/* verify we regularly receive measurement reports with incrementing numbers */
1273altstep as_meas_res() runs on ConnHdlr {
1274 var RSL_Message rsl;
1275 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1276 /* increment counter of next to-be-expected meas rep */
1277 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1278 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001279 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001280 repeat;
1281 }
1282 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001283 /* increment counter of next to-be-expected meas rep */
1284 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1285 if (g_first_meas_res) {
1286 g_first_meas_res := false;
1287 repeat;
1288 } else {
1289 setverdict(fail, "Received unspecific MEAS RES ", rsl);
1290 self.stop;
1291 }
Harald Welte70767382018-02-21 12:16:40 +01001292 }
1293 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
1294 setverdict(fail, "Received unexpected MEAS RES ", rsl);
1295 self.stop;
1296 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001297 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Harald Welte70767382018-02-21 12:16:40 +01001298 setverdict(fail, "Didn't receive expected measurement result")
1299 self.stop;
1300 }
1301}
1302
Harald Weltee613f962018-04-18 22:38:16 +02001303private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1304 select (rsl_alg_id) {
1305 case (RSL_ALG_ID_A5_0) { return 0; }
1306 case (RSL_ALG_ID_A5_1) { return 1; }
1307 case (RSL_ALG_ID_A5_2) { return 2; }
1308 case (RSL_ALG_ID_A5_3) { return 3; }
1309 case (RSL_ALG_ID_A5_4) { return 4; }
1310 case (RSL_ALG_ID_A5_5) { return 5; }
1311 case (RSL_ALG_ID_A5_6) { return 6; }
1312 case (RSL_ALG_ID_A5_7) { return 7; }
1313 case else {
1314 setverdict(fail, "Unknwon Algorithm ID");
1315 self.stop;
1316 }
1317 }
1318}
1319
1320private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1321 select (rsl_alg_id) {
1322 case (RSL_ALG_ID_A5_1) { return '000'B; }
1323 case (RSL_ALG_ID_A5_2) { return '001'B; }
1324 case (RSL_ALG_ID_A5_3) { return '010'B; }
1325 case (RSL_ALG_ID_A5_4) { return '011'B; }
1326 case (RSL_ALG_ID_A5_5) { return '100'B; }
1327 case (RSL_ALG_ID_A5_6) { return '101'B; }
1328 case (RSL_ALG_ID_A5_7) { return '110'B; }
1329 case else {
1330 setverdict(fail, "Unknwon Algorithm ID");
1331 self.stop;
1332 }
1333 }
1334}
1335
1336
Harald Welte70767382018-02-21 12:16:40 +01001337/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001338private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001339 var GsmFrameNumber fn;
1340 var ImmediateAssignment imm_ass;
1341 var integer ra := 23;
1342
1343 fn := f_L1CTL_RACH(L1CTL, ra);
1344 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
1345 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
1346
1347 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001348 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001349
1350 /* Send IMM.ASS via CCHAN */
1351 var ChannelDescription ch_desc := {
1352 chan_nr := g_pars.chan_nr,
1353 tsc := 7,
1354 h := false,
1355 arfcn := mp_trx0_arfcn,
1356 maio_hsn := omit
1357 };
1358 var MobileAllocation ma := {
1359 len := 0,
1360 ma := ''B
1361 };
1362 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1363 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1364
1365 /* receive IMM.ASS on MS side */
1366 var ImmediateAssignment ia_um;
1367 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1368 /* enable dedicated mode */
1369 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001370 /* enable encryption, if requested */
1371 if (encr_enable) {
1372 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1373 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1374 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001375
1376 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001377}
1378
1379/* establish DChan, verify existance + contents of measurement reports */
1380function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001381 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001382 RSL.clear;
1383
Harald Welte5398d5e2018-03-10 19:00:24 +01001384 if (mp_bb_trxc_port != -1) {
1385 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1386 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001387
Harald Welte5398d5e2018-03-10 19:00:24 +01001388 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1389 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1390 } else {
1391 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1392 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1393 }
1394 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001395
1396 f_est_dchan();
1397
1398 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1399 * RSL measurement reports on Abis side */
1400 timer T := 8.0;
1401 T.start;
1402 alt {
1403 [] as_l1_sacch();
1404 [] as_meas_res();
1405 [] as_l1_dcch();
1406 [] L1CTL.receive { repeat; }
1407 [g_Tmeas_exp.running] T.timeout {
1408 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1409 * of any earlier errors, so if we reach this timeout, we're good */
1410 setverdict(pass);
1411 }
1412 [] T.timeout {
1413 setverdict(fail, "No MEAS RES received at all");
1414 }
1415 }
1416 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001418}
Harald Welte0472ab42018-03-12 15:02:26 +01001419
Harald Welte70767382018-02-21 12:16:40 +01001420testcase TC_meas_res_sign_tchf() runs on test_CT {
1421 var ConnHdlr vc_conn;
1422 var ConnHdlrPars pars;
1423 f_init(testcasename());
1424 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1425 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1426 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1427 vc_conn.done;
1428 }
Harald Welte294b0a22018-03-10 23:26:48 +01001429 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001430}
1431testcase TC_meas_res_sign_tchh() runs on test_CT {
1432 var ConnHdlr vc_conn;
1433 var ConnHdlrPars pars;
1434 f_init(testcasename());
1435 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1436 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1437 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1438 vc_conn.done;
1439 }
Harald Welte294b0a22018-03-10 23:26:48 +01001440 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001441}
1442testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1443 var ConnHdlr vc_conn;
1444 var ConnHdlrPars pars;
1445 f_init(testcasename());
1446 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1447 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1448 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1449 vc_conn.done;
1450 }
Harald Welte294b0a22018-03-10 23:26:48 +01001451 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001452}
1453testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1454 var ConnHdlr vc_conn;
1455 var ConnHdlrPars pars;
1456 f_init(testcasename());
1457 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1458 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1459 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1460 vc_conn.done;
1461 }
Harald Welte294b0a22018-03-10 23:26:48 +01001462 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001463}
Harald Welte685d5982018-02-27 20:42:05 +01001464testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1465 var ConnHdlr vc_conn;
1466 var ConnHdlrPars pars;
1467 f_init(testcasename());
1468 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1469 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1470 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1471 pars.l1_pars.toa256_enabled := true;
1472 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1473 vc_conn.done;
1474 }
Harald Welte294b0a22018-03-10 23:26:48 +01001475 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001476}
1477
Harald Welte70767382018-02-21 12:16:40 +01001478
Harald Welte0472ab42018-03-12 15:02:26 +01001479/* 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 +01001480private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001481 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001482 RSL.clear;
1483
1484 f_est_dchan();
1485 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001486 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001487
1488 timer T := 40.0;
1489 T.start;
1490 alt {
1491 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1492 setverdict(pass)
1493 }
1494 [] RSL.receive { repeat };
1495 [] T.timeout {
1496 setverdict(fail, "No CONN FAIL IND received");
1497 }
1498 }
1499 f_rsl_chan_deact();
1500}
1501testcase TC_conn_fail_crit() runs on test_CT {
1502 var ConnHdlr vc_conn;
1503 var ConnHdlrPars pars;
1504 f_init(testcasename());
1505 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1506 pars.t_guard := 60.0;
1507 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1508 vc_conn.done;
1509}
1510
Harald Welte93640c62018-02-25 16:59:33 +01001511/***********************************************************************
1512 * Paging
1513 ***********************************************************************/
1514
Harald Welte68e495b2018-02-25 00:05:57 +01001515function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1516 if (tmsi == 'FFFFFFFF'O) {
1517 return true;
1518 } else {
1519 return false;
1520 }
1521}
Harald Welte70767382018-02-21 12:16:40 +01001522
Harald Welte68e495b2018-02-25 00:05:57 +01001523altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1524runs on test_CT {
1525 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001526 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001527 repeat;
1528 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001529 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001530 var octetstring without_plen :=
1531 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1532 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1533 if (match(rr, tr_PAGING_REQ1)) {
1534 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1535 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1536 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1537 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1538 }
1539 } else if (match(rr, tr_PAGING_REQ2)) {
1540 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1541 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1542 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1543 }
1544 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1545 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1546 }
1547 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1548 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1549 }
1550 } else if (match(rr, tr_PAGING_REQ3)) {
1551 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1552 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1553 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1554 }
1555 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1556 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1557 }
1558 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1559 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1560 }
1561 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1562 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1563 }
1564 }
1565 repeat;
1566 }
1567}
1568
1569type record PagingTestCfg {
1570 boolean combined_ccch,
1571 integer bs_ag_blks_res,
1572 float load_factor,
1573 boolean exp_load_ind,
1574 boolean exp_overload,
1575 boolean use_tmsi
1576}
1577
1578type record PagingTestState {
1579 integer num_paging_sent,
1580 integer num_paging_rcv_msgs,
1581 integer num_paging_rcv_ids,
1582 integer num_overload
1583}
1584
1585/* receive + ignore RSL RF RES IND */
1586altstep as_rsl_res_ind() runs on test_CT {
1587 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1588 repeat;
1589 }
1590}
1591
1592/* Helper function for paging related testing */
1593private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1594 f_init(testcasename());
1595 f_init_l1ctl();
1596 f_l1_tune(L1CTL);
1597
1598 var PagingTestState st := {
1599 num_paging_sent := 0,
1600 num_paging_rcv_msgs := 0,
1601 num_paging_rcv_ids := 0,
1602 num_overload := 0
1603 };
1604
1605 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1606 var float max_pch_imsi_per_sec;
1607 if (cfg.use_tmsi) {
1608 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1609 } else {
1610 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1611 }
1612 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1613 var float interval := 1.0 / pch_blocks_per_sec;
1614 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1615
1616 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1617 /* build mobile Identity */
1618 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1619 if (cfg.use_tmsi) {
1620 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1621 } else {
1622 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1623 }
1624 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1625 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1626
1627 /* Send RSL PAGING COMMAND */
1628 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1629 st.num_paging_sent := st.num_paging_sent + 1;
1630
1631 /* Wait for interval to next PAGING COMMAND */
1632 timer T_itv := interval;
1633 T_itv.start;
1634 alt {
1635 /* check for presence of CCCH LOAD IND (paging load) */
1636 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1637 st.num_overload := st.num_overload + 1;
1638 repeat;
1639 }
1640 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1641 setverdict(fail, "Unexpected PCH Overload");
1642 }
1643 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1644 log("Rx LOAD_IND");
1645 /* FIXME: analyze/verify interval + contents */
1646 repeat;
1647 }
1648 /* check if paging requests arrive on Um side */
1649 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1650 [] L1CTL.receive { repeat; }
1651 [] T_itv.timeout { }
1652 [] as_rsl_res_ind();
1653 }
1654 }
1655
1656 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1657 timer T_wait := 18.0;
1658 T_wait.start;
1659 alt {
1660 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1661 [] L1CTL.receive { repeat; }
1662 /* 65535 == empty paging queue, we can terminate*/
1663 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1664 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1665 [] T_wait.timeout {
1666 setverdict(fail, "Waiting for empty paging queue");
1667 }
1668 [] as_rsl_res_ind();
1669 }
1670
1671 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1672 " rcvd_ids=", st.num_paging_rcv_ids);
1673 return st;
1674}
1675
1676/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1677 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1678 * - that CCCH LOAD IND (PCH) are being generated
1679 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1680testcase TC_paging_imsi_80percent() runs on test_CT {
1681 var PagingTestCfg cfg := {
1682 combined_ccch := true,
1683 bs_ag_blks_res := 1,
1684 load_factor := 0.8,
1685 exp_load_ind := true,
1686 exp_overload := false,
1687 use_tmsi := false
1688 };
1689 var PagingTestState st := f_TC_paging(cfg);
1690 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1691 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1692 st.num_paging_rcv_ids);
1693 } else {
1694 setverdict(pass);
1695 }
Daniel Willmanna59afab2018-07-05 16:16:32 +02001696 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001697}
1698
1699/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1700 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1701 * - that CCCH LOAD IND (PCH) are being generated
1702 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1703testcase TC_paging_tmsi_80percent() runs on test_CT {
1704 var PagingTestCfg cfg := {
1705 combined_ccch := true,
1706 bs_ag_blks_res := 1,
1707 load_factor := 0.8,
1708 exp_load_ind := true,
1709 exp_overload := false,
1710 use_tmsi := true
1711 };
1712 var PagingTestState st := f_TC_paging(cfg);
1713 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1714 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1715 st.num_paging_rcv_ids);
1716 } else {
1717 setverdict(pass);
1718 }
Daniel Willmanna59afab2018-07-05 16:16:32 +02001719 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001720}
1721
1722/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1723 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1724 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1725 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1726testcase TC_paging_imsi_200percent() runs on test_CT {
1727 var PagingTestCfg cfg := {
1728 combined_ccch := true,
1729 bs_ag_blks_res := 1,
1730 load_factor := 2.0,
1731 exp_load_ind := true,
1732 exp_overload := true,
1733 use_tmsi := false
1734 };
1735 var PagingTestState st := f_TC_paging(cfg);
1736 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1737 * slots and will fully drain that buffer before returning */
1738 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1739 if (not match(st.num_paging_rcv_ids, tpl)) {
1740 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1741 } else {
1742 setverdict(pass);
1743 }
Daniel Willmanna59afab2018-07-05 16:16:32 +02001744 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001745}
1746
1747/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1748 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1749 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1750 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1751testcase TC_paging_tmsi_200percent() runs on test_CT {
1752 var PagingTestCfg cfg := {
1753 combined_ccch := true,
1754 bs_ag_blks_res := 1,
1755 load_factor := 2.0,
1756 exp_load_ind := true,
1757 exp_overload := true,
1758 use_tmsi := true
1759 };
1760 var PagingTestState st := f_TC_paging(cfg);
1761 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1762 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001763 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001764 if (not match(st.num_paging_rcv_ids, tpl)) {
1765 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1766 } else {
1767 setverdict(pass);
1768 }
Daniel Willmanna59afab2018-07-05 16:16:32 +02001769 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001770}
1771
1772
Harald Welte93640c62018-02-25 16:59:33 +01001773/***********************************************************************
1774 * Immediate Assignment / AGCH
1775 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001776const MobileAllocation c_MA_null := {
1777 len := 0,
1778 ma := ''B
1779}
Harald Welte93640c62018-02-25 16:59:33 +01001780
Harald Weltee8d750e2018-06-10 21:41:35 +02001781template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1782 uint12_t arfcn := 871) := {
1783 chan_nr := chan_nr,
1784 tsc := tsc,
1785 h := false,
1786 arfcn := arfcn,
1787 maio_hsn := omit
1788}
1789
1790private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1791 return int2str(num_tx) & " sent, "
1792 & int2str(num_rx) & " received, "
1793 & int2str(num_del) & " deleted";
1794}
1795
1796private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1797 var L1ctlDlMessage l1_dl;
1798 timer T := 10.0;
1799 var integer num_tx := 0;
1800 var integer num_rx := 0;
1801 var integer num_del := 0;
1802 var charstring res_str;
1803 var float rx_ratio;
1804
Harald Welte68e495b2018-02-25 00:05:57 +01001805 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001806 f_init_l1ctl();
1807 f_l1_tune(L1CTL);
1808
1809 for (var integer i := 0; i < num_total; i := i+1) {
1810 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1811 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1812 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001813 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001814 num_tx := num_tx+1;
1815 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001816 }
1817 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02001818 T.start;
1819 alt {
1820 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
1821 num_del := num_del+1;
1822 repeat;
1823 }
1824 [] RSL_CCHAN.receive {
1825 repeat;
1826 }
1827 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
1828 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1829 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
1830 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
1831 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
1832 //setverdict(fail, "Unexpected IMM-ASS values on AGCH: ", rr);
1833 //self.stop;
1834 } else {
1835 num_rx := num_rx+1;
1836 }
1837 repeat;
1838 }
1839 [] L1CTL.receive { repeat; }
1840 [] T.timeout { }
1841 }
1842 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
1843 log("AGCH test: " & res_str);
1844 if (num_rx + num_del != num_tx) {
1845 setverdict(fail, "RX + DEL != TX ?!?: " & res_str);
1846 }
1847 rx_ratio := int2float(num_rx) / int2float(num_tx);
1848 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
1849 setverdict(fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
1850 } else {
1851 setverdict(pass);
1852 }
Harald Welte68e495b2018-02-25 00:05:57 +01001853}
1854
Harald Weltee8d750e2018-06-10 21:41:35 +02001855/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
1856testcase TC_imm_ass_1000_20ms() runs on test_CT {
1857 f_TC_imm_ass(1000, 0.02, 0.25);
1858}
1859
1860/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
1861testcase TC_imm_ass_200_0ms() runs on test_CT {
1862 f_TC_imm_ass(200, 0.0, 0.05);
1863}
1864
1865/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
1866testcase TC_imm_ass_200_76ms() runs on test_CT {
1867 f_TC_imm_ass(150, 0.076, 1.00);
1868}
1869
1870
1871
Harald Welte48494ca2018-02-25 16:59:50 +01001872/***********************************************************************
1873 * BCCH
1874 ***********************************************************************/
1875
1876/* tuple of Frame Number + decoded SI */
1877type record SystemInformationFn {
1878 GsmFrameNumber frame_number,
1879 SystemInformation si
1880}
1881
1882/* an arbitrary-length vector of decoded SI + gsmtap header */
1883type record of SystemInformationFn SystemInformationVector;
1884
1885/* an array of SI-vectors indexed by TC value */
1886type SystemInformationVector SystemInformationVectorPerTc[8];
1887
1888/* determine if a given SI vector contains given SI type at least once */
1889function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1890 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1891 var integer fn_mod51 := arr[i].frame_number mod 51;
1892 if (not bcch_ext and fn_mod51 == 2 or
1893 bcch_ext and fn_mod51 == 6) {
1894 if (arr[i].si.header.message_type == key) {
1895 return true;
1896 }
1897 }
1898 }
1899 return false;
1900}
1901
1902/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1903function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1904 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1905 setverdict(fail, "No ", key, " in TC=", tc, "!");
1906 }
1907}
1908
1909/* check if a given SI vector contains given SI type at least once on any TC */
1910function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1911 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1912 if (f_si_vecslot_contains(arr[tc], key) or
1913 f_si_vecslot_contains(arr[tc], key, true)) {
1914 return true;
1915 }
1916 }
1917 return false;
1918}
1919
1920/* determine if a given SI vector contains given SI type at least N of M times */
1921function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1922 var integer count := 0;
1923 if (sizeof(arr) < m) {
1924 setverdict(fail, "Error: Insufficient SI in array");
1925 self.stop;
1926 }
1927 for (var integer i:= 0; i < m; i := i + 1) {
1928 var integer fn_mod51 := arr[i].frame_number mod 51;
1929 if (not bcch_ext and fn_mod51 == 2 or
1930 bcch_ext and fn_mod51 == 6) {
1931 if (arr[i].si.header.message_type == key) {
1932 count := count + 1;
1933 }
1934 }
1935 }
1936 if (count >= n) {
1937 return true;
1938 } else {
1939 return false;
1940 }
1941}
1942
1943/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1944function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1945 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1946 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1947 }
1948}
1949
1950/* determine if a given SI vector contains given SI type at least once */
1951function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1952 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1953 var integer fn_mod51 := arr[i].frame_number mod 51;
1954 if (not bcch_ext and fn_mod51 == 2 or
1955 bcch_ext and fn_mod51 == 6) {
1956 if (arr[i].si.header.message_type != key) {
1957 return false;
1958 }
1959 }
1960 }
1961 return true;
1962}
1963
1964/* ensure a given TC slot of the SI vector contains only given SI type */
1965function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1966 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1967 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1968 }
1969}
1970
1971/* SI configuration of cell, against which we validate actual SI messages */
1972type set SystemInformationConfig {
1973 boolean bcch_extended,
1974 boolean si1_present,
1975 boolean si2bis_present,
1976 boolean si2ter_present,
1977 boolean si2quater_present,
1978 boolean si7_present,
1979 boolean si8_present,
1980 boolean si9_present,
1981 boolean si13_present,
1982 boolean si13alt_present,
1983 boolean si15_present,
1984 boolean si16_present,
1985 boolean si17_present,
1986 boolean si2n_present,
1987 boolean si21_present,
1988 boolean si22_present
1989}
1990
1991/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1992function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1993 var integer i;
1994 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1995 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001996 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001997 }
1998 }
1999 if (cfg.si1_present) {
2000 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2001 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2002 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2003 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2004 /* make sure *ALL* contain SI1 */
2005 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2006 }
2007 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2008 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2009 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2010 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2011 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2012 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2013
2014 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2015 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2016 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2017 * consecutive occurrences of TC = 4. */
2018 if (cfg.si2bis_present and not cfg.si2ter_present) {
2019 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2020 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2021 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2022 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2023 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2024 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2025 }
2026
2027 if (cfg.si7_present or cfg.si8_present) {
2028 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2029 * if System Information type 4 does not contain all information needed for cell
2030 * selection and reselection. */
2031 if (not cfg.bcch_extended) {
2032 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2033 }
2034 if (cfg.si7_present) {
2035 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2036 }
2037 if (cfg.si8_present) {
2038 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2039 }
2040 }
2041
2042 if (cfg.si2quater_present) {
2043 /* iii) System information type 2 quater is sent if needed, as determined by the system
2044 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2045 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2046 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2047 * within any of 4 consecutive occurrences of TC = 5. */
2048 if (not (cfg.bcch_extended)) {
2049 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2050 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2051 } else {
2052 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2053 }
2054 } else {
2055 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2056 }
2057 }
2058 if (cfg.si9_present) {
2059 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2060 * in system information type 3 as defined in 3GPP TS 44.018. */
2061 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2062 }
2063 if (cfg.si13_present) {
2064 /* vii) System Information type 13 is only related to the GPRS service. System Information
2065 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2066 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2067 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2068 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2069 * within any of 4 consecutive occurrences of TC=4. */
2070 if (not cfg.bcch_extended) {
2071 log("not-bccch-extended");
2072 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2073 } else {
2074 log("bccch-extended");
2075 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2076 }
2077 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
2078 setverdict(fail, "Cannot have SI13alt and SI13");
2079 }
2080 }
2081 if (cfg.si16_present or cfg.si17_present) {
2082 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2083 * should not be sent in a cell where network sharing is used (see rule xv). */
2084 if (cfg.si22_present) {
2085 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2086 }
2087 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
2088 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2089 }
2090 if (not cfg.bcch_extended) {
2091 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2092 }
2093 if (cfg.si16_present) {
2094 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2095 }
2096 if (cfg.si17_present) {
2097 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2098 }
2099 }
2100
2101 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2102 * broadcast information. The frequency with which they are sent is determined by the
2103 * system operator. System Information type 9 identifies the scheduling of System
2104 * Information type 18 and 20 messages. */
2105
2106 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2107 * Information Type 19 is present, then its scheduling shall be indicated in System
2108 * Information Type 9. */
2109
2110 if (cfg.si15_present) {
2111 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2112 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2113 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2114 * 4 consecutive occurrences of TC = 1. */
2115 if (not cfg.bcch_extended) {
2116 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2117 } else {
2118 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2119 }
2120 }
2121 if (cfg.si13alt_present) {
2122 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2123 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2124 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2125 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2126 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2127 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2128 * of TC = 4. */
2129 if (cfg.si13_present) {
2130 testcase.stop("Error: Cannot have SI13alt and SI13");
2131 }
2132 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
2133 setverdict(fail, "Cannot have SI13alt and SI13");
2134 }
2135 if (not cfg.bcch_extended) {
2136 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2137 } else {
2138 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2139 }
2140 }
2141 if (cfg.si2n_present) {
2142 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2143 * as determined by the system operator. In the case that the message is sent on the
2144 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2145 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2146 * consecutive occurrences of TC = 4. */
2147 if (not cfg.bcch_extended) {
2148 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2149 } else {
2150 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2151 }
2152 }
2153 if (cfg.si21_present) {
2154 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2155 * determined by the system operator. If Extended Access Barring is in use in the cell
2156 * then this message is sent at least once within any of 4 consecutive occurrences of
2157 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2158 * cell then this message shall only be sent on BCCH Ext. */
2159 if (not cfg.bcch_extended) {
2160 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2161 } else {
2162 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2163 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
2164 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
2165 }
2166 }
2167 }
2168 if (cfg.si22_present) {
2169 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2170 * should not be sent in a cell where SoLSA is used (see rule viii). System
2171 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2172 * =2 and TC=6. */
2173 if (cfg.si16_present or cfg.si17_present) {
2174 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2175 }
2176 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2177 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2178 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2179 }
2180 if (not cfg.bcch_extended) {
2181 testcase.stop("Error: SI22 requires BCCH Extd!");
2182 } else {
2183 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2184 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2185 }
2186 }
2187}
2188
2189/* sample Systme Information for specified duration via L1CTL */
2190function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2191 timer T := duration;
2192 var SystemInformationVectorPerTc si_per_tc;
2193 var L1ctlDlMessage l1_dl;
2194
2195 /* initialize all per-TC vectors empty */
2196 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2197 si_per_tc[i] := {};
2198 }
2199
2200 /* flush all previous L1 queued msgs */
2201 pt.clear;
2202
2203 T.start;
2204 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002205 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002206 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2207 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2208 log("Ignoring non-RR SI ", l1_dl);
2209 repeat;
2210 }
2211 var SystemInformationFn sig := {
2212 frame_number := l1_dl.dl_info.frame_nr,
2213 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2214 }
2215 var integer tc := f_gsm_compute_tc(sig.frame_number);
2216 log("SI received at TC=", tc, ": ", sig.si);
2217 /* append to the per-TC bucket */
2218 si_per_tc[tc] := si_per_tc[tc] & { sig };
2219 repeat;
2220 }
2221 [] pt.receive { repeat; }
2222 [] T.timeout { }
2223 }
2224
2225 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2226 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2227 }
2228 log("si_per_tc=", si_per_tc);
2229 return si_per_tc;
2230}
2231
2232/* helper function: Set given SI via RSL + validate scheduling.
2233 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2234function f_TC_si_sched() runs on test_CT {
2235 var SystemInformationVectorPerTc si_per_tc;
2236 f_init_l1ctl();
2237 f_l1_tune(L1CTL);
2238
2239 /* Sample + Validate Scheduling */
2240 si_per_tc := f_l1_sample_si(L1CTL);
2241 f_validate_si_scheduling(si_cfg, si_per_tc);
2242
2243 setverdict(pass);
2244}
2245
2246testcase TC_si_sched_default() runs on test_CT {
2247 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002248 /* 2+3+4 are mandatory and set in f_init() */
2249 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002250 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002251}
2252
2253testcase TC_si_sched_1() runs on test_CT {
2254 f_init();
2255 si_cfg.si1_present := true;
2256 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002257 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002258 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002259}
2260
2261testcase TC_si_sched_2bis() runs on test_CT {
2262 f_init();
2263 si_cfg.si2bis_present := true;
2264 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2265 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002266 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002267}
2268
2269testcase TC_si_sched_2ter() runs on test_CT {
2270 f_init();
2271 si_cfg.si2ter_present := true;
2272 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2273 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002274 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002275}
2276
2277testcase TC_si_sched_2ter_2bis() runs on test_CT {
2278 f_init();
2279 si_cfg.si2bis_present := true;
2280 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2281 si_cfg.si2ter_present := true;
2282 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2283 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002284 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002285}
2286
2287testcase TC_si_sched_2quater() runs on test_CT {
2288 f_init();
2289 si_cfg.si2quater_present := true;
2290 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2291 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002292 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002293}
2294
2295testcase TC_si_sched_13() runs on test_CT {
2296 f_init();
2297 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002298 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002299 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002300 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002301}
2302
2303testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2304 f_init();
2305 si_cfg.si2bis_present := true;
2306 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2307 si_cfg.si2ter_present := true;
2308 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2309 si_cfg.si2quater_present := true;
2310 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2311 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002312 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002313 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002314 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002315}
2316
2317
Harald Welte68e495b2018-02-25 00:05:57 +01002318testcase TC_bcch_info() runs on test_CT {
2319 f_init(testcasename());
2320 /* FIXME: enable / disable individual BCCH info */
2321 //ts_RSL_BCCH_INFO(si_type, info);
2322 /* expect no ERROR REPORT after either of them *
2323 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002324 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002325}
2326
Harald Welte93640c62018-02-25 16:59:33 +01002327/***********************************************************************
2328 * Low-Level Protocol Errors / ERROR REPORT
2329 ***********************************************************************/
2330
Harald Welte01d982c2018-02-25 01:31:40 +01002331private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2332 timer T := 5.0;
2333 T.start;
2334 alt {
2335 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2336 setverdict(pass);
2337 }
2338 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2339 setverdict(fail, "Wrong cause in RSL ERR REP");
2340 }
2341 [] RSL_CCHAN.receive {
2342 repeat;
2343 }
2344 [] T.timeout {
2345 setverdict(fail, "Timeout waiting for RSL ERR REP");
2346 }
2347 }
2348}
2349
2350/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2351testcase TC_rsl_protocol_error() runs on test_CT {
2352 f_init(testcasename());
2353 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2354 rsl.ies := omit;
2355 RSL_CCHAN.send(ts_RSL_UD(rsl));
2356
2357 f_exp_err_rep(RSL_ERR_PROTO);
2358}
2359
2360/* Provoke a mandatory IE error and match on ERROR REPORT */
2361testcase TC_rsl_mand_ie_error() runs on test_CT {
2362 f_init(testcasename());
2363
2364 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2365 rsl.ies := { rsl.ies[0] };
2366 RSL_CCHAN.send(ts_RSL_UD(rsl));
2367
2368 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2369}
2370
2371/* Provoke an IE content error and match on ERROR REPORT */
2372testcase TC_rsl_ie_content_error() runs on test_CT {
2373 f_init(testcasename());
2374 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2375 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2376 RSL_CCHAN.send(ts_RSL_UD(rsl));
2377
2378 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2379}
2380
Harald Welte93640c62018-02-25 16:59:33 +01002381/***********************************************************************
2382 * IPA CRCX/MDCX/DLCS media stream handling
2383 ***********************************************************************/
2384
Harald Weltea871a382018-02-25 02:03:14 +01002385/* Send IPA DLCX to inactive lchan */
2386function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002387 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2388 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002389}
2390testcase TC_ipa_dlcx_not_active() runs on test_CT {
2391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2392 f_init(testcasename());
2393 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2394 vc_conn.done;
2395}
Harald Welte68e495b2018-02-25 00:05:57 +01002396
Harald Weltea3f1df92018-02-25 12:49:55 +01002397/* Send IPA CRCX twice to inactive lchan */
2398function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2399 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2400 "IPA CRCX ACK");
2401 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2402 "IPA CRCX NACK");
2403}
2404testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2405 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2406 f_init(testcasename());
2407 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2408 vc_conn.done;
2409}
2410
2411/* Regular sequence of CRCX/MDCX/DLCX */
2412function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2413 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2414 "IPA CRCX ACK");
2415 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2416 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2417 var uint7_t rtp_pt2 := f_rnd_int(127);
2418 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2419 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2420 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2421 "IPA MDCX ACK");
2422 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2423 "IPA DLCX ACK");
2424}
2425testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2426 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2427 f_init(testcasename());
2428 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2429 vc_conn.done;
2430}
2431
Harald Welte3ae11da2018-02-25 13:36:06 +01002432/* Sequence of CRCX, 2x MDCX, DLCX */
2433function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2434 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2435 "IPA CRCX ACK");
2436 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2437 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2438 var uint7_t rtp_pt2 := f_rnd_int(127);
2439 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2440 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2441 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2442 "IPA MDCX ACK");
2443 /* Second MDCX */
2444 remote_ip := f_rnd_int(c_UINT32_MAX);
2445 remote_port := f_rnd_int(c_UINT16_MAX);
2446 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2447 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2448 "IPA MDCX ACK");
2449 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2450 "IPA DLCX ACK");
2451}
2452testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2454 f_init(testcasename());
2455 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2456 vc_conn.done;
2457}
2458
Harald Welte9912eb52018-02-25 13:30:15 +01002459/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2460function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2461 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2462 "IPA CRCX NACK");
2463}
2464testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2465 var ConnHdlrPars pars;
2466 var ConnHdlr vc_conn;
2467 f_init(testcasename());
2468
2469 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2470 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2471 vc_conn.done;
2472
2473 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2474 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2475 vc_conn.done;
2476}
2477
Harald Weltea3f1df92018-02-25 12:49:55 +01002478
Harald Welte883340c2018-02-28 18:59:29 +01002479/***********************************************************************
2480 * PCU Socket related tests
2481 ***********************************************************************/
2482
2483private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2484runs on test_CT {
2485 timer T := 3.0;
2486
2487 /* we don't expect any RTS.req before PDCH are active */
2488 T.start;
2489 alt {
2490 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2491 setverdict(fail, "PCU RTS.req before PDCH active?");
2492 self.stop;
2493 }
2494 [] PCU.receive { repeat; }
2495 [] T.timeout { }
2496 }
2497
2498 /* Send PDCH activate request for known PDCH timeslot */
2499 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2500
2501 /* we now expect RTS.req for this timeslot (only) */
2502 T.start;
2503 alt {
2504 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2505 setverdict(pass);
2506 }
2507 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2508 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2509 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2510 self.stop;
2511 }
2512 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2513 setverdict(fail, "RTS.req for wrong TRX/TS");
2514 self.stop;
2515 }
2516 [] PCU.receive { repeat; }
2517 [exp_success] T.timeout {
2518 setverdict(fail, "Timeout waiting for PCU RTS.req");
2519 }
2520 [not exp_success] T.timeout {
2521 setverdict(pass);
2522 }
2523 }
2524}
2525
2526private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2527runs on test_CT {
2528 timer T := 3.0;
2529
2530 /* Send PDCH activate request for known PDCH timeslot */
2531 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2532
2533 PCU.clear;
2534 /* we now expect no RTS.req for this timeslot */
2535 T.start;
2536 alt {
2537 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2538 setverdict(fail, "Received unexpected PCU RTS.req");
2539 self.stop;
2540 }
2541 [] PCU.receive { repeat; }
2542 [] T.timeout {
2543 setverdict(pass);
2544 }
2545 }
2546}
2547
2548/* PDCH activation via PCU socket; check for presence of RTS.req */
2549testcase TC_pcu_act_req() runs on test_CT {
2550 f_init();
2551 f_TC_pcu_act_req(0, 0, 7, true);
2552}
2553
2554/* PDCH activation via PCU socket on non-PDCU timeslot */
2555testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2556 f_init();
2557 f_TC_pcu_act_req(0, 0, 1, false);
2558}
2559
2560/* PDCH activation via PCU socket on wrong BTS */
2561testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2562 f_init();
2563 f_TC_pcu_act_req(23, 0, 7, false);
2564}
2565
2566/* PDCH activation via PCU socket on wrong TRX */
2567testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2568 f_init();
2569 f_TC_pcu_act_req(0, 23, 7, false);
2570}
2571
2572/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2573testcase TC_pcu_deact_req() runs on test_CT {
2574 f_init();
2575 /* Activate PDCH */
2576 f_TC_pcu_act_req(0, 0, 7, true);
2577 f_sleep(1.0);
2578 /* and De-Activate again */
2579 f_TC_pcu_deact_req(0, 0, 7);
2580}
2581
2582/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2583testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2584 f_init();
2585 f_TC_pcu_deact_req(0, 0, 1);
2586}
2587
2588/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2589testcase TC_pcu_ver_si13() runs on test_CT {
2590 const octetstring si13 := '00010203040506070909'O;
2591 var PCUIF_send_data sd;
2592 timer T:= 3.0;
2593 f_init();
2594
2595 /* Set SI13 via RSL */
2596 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2597 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2598 T.start;
2599 alt {
2600 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2601 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2602 setverdict(pass);
2603 } else {
2604 repeat;
2605 }
2606 }
2607 [] PCU.receive { repeat; }
2608 [] T.timeout {
2609 setverdict(fail, "Timeout waiting for SI13");
2610 self.stop;
2611 }
2612 }
2613}
2614
2615private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2616
2617/* helper function to send a PCU DATA.req */
2618private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2619 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2620runs on test_CT
2621{
2622 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2623 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2624}
2625
2626/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2627private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2628 PCUIF_Sapi sapi, octetstring data)
2629runs on test_CT
2630{
2631 var PCUIF_send_data sd;
2632
2633 timer T := 3.0;
2634 T.start;
2635 alt {
2636 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2637 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2638 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2639 sd.data.u.rts_req.fn, sapi, data);
2640 }
2641 [] PCU.receive { repeat; }
2642 [] T.timeout {
2643 setverdict(fail, "Timeout waiting for RTS.ind");
2644 }
2645 }
2646}
2647
2648/* Send DATA.req on invalid BTS */
2649testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2650 f_init();
2651 f_TC_pcu_act_req(0, 0, 7, true);
2652 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2653 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2654 f_sleep(10.0);
2655}
2656
2657/* Send DATA.req on invalid TRX */
2658testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2659 f_init();
2660 f_TC_pcu_act_req(0, 0, 7, true);
2661 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2662 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2663 f_sleep(10.0);
2664}
2665
2666/* Send DATA.req on invalid timeslot */
2667testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2668 f_init();
2669 f_TC_pcu_act_req(0, 0, 7, true);
2670 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2671 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2672 f_sleep(10.0);
2673}
2674
2675/* Send DATA.req on timeslot that hasn't been activated */
2676testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2677 f_init();
2678 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2679 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2680 f_sleep(2.0);
2681}
2682
2683testcase TC_pcu_data_req_pdtch() runs on test_CT {
2684 f_init();
2685 f_TC_pcu_act_req(0, 0, 7, true);
2686 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2687 /* FIXME: how to check this was actually sent */
2688 f_sleep(2.0);
2689}
2690
2691testcase TC_pcu_data_req_ptcch() runs on test_CT {
2692 f_init();
2693 f_TC_pcu_act_req(0, 0, 7, true);
2694 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2695 /* FIXME: how to check this was actually sent */
2696 f_sleep(2.0);
2697}
2698
2699/* Send AGCH from PCU; check it appears on Um side */
2700testcase TC_pcu_data_req_agch() runs on test_CT {
2701 timer T := 3.0;
2702 f_init();
2703 f_init_l1ctl();
2704 f_l1_tune(L1CTL);
2705
2706 f_TC_pcu_act_req(0, 0, 7, true);
2707 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2708
2709 T.start;
2710 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002711 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002712 setverdict(pass);
2713 }
2714 [] L1CTL.receive { repeat; }
2715 [] T.timeout {
2716 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2717 }
2718 }
2719}
2720
2721/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2722testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2723 var octetstring imm_ass := f_rnd_octstring(23);
2724 f_init();
2725 f_init_l1ctl();
2726 f_l1_tune(L1CTL);
2727
2728 /* append 3 last imsi digits so BTS can compute pagng group */
2729 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2730
2731 timer T := 0.5;
2732 T.start;
2733 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002734 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002735 /* TODO: verify paging group */
2736 setverdict(pass);
2737 }
2738 [] L1CTL.receive { repeat; }
2739 [] T.timeout {
2740 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2741 }
2742 }
2743}
2744
2745/* Send RACH from Um side, expect it to show up on PCU socket */
2746testcase TC_pcu_rach_content() runs on test_CT {
2747 f_init();
2748 f_init_l1ctl();
2749 f_l1_tune(L1CTL);
2750
2751 var GsmFrameNumber fn_last := 0;
2752 for (var integer i := 0; i < 1000; i := i+1) {
2753 var OCT1 ra := f_rnd_ra_ps();
2754 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2755 if (fn == fn_last) {
2756 setverdict(fail, "Two RACH in same FN?!?");
2757 self.stop;
2758 }
2759 fn_last := fn;
2760
2761 timer T := 2.0;
2762 T.start;
2763 alt {
2764 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2765 T.stop;
2766 }
2767 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2768 setverdict(fail, "Unexpected RACH IND");
2769 self.stop;
2770 }
2771 [] PCU.receive { repeat; }
2772 [] T.timeout {
2773 setverdict(fail, "Timeout waiting for RACH IND");
2774 self.stop;
2775 }
2776 }
2777 }
2778 setverdict(pass);
2779}
2780
2781private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2782 var integer strlen := lengthof(str);
2783 for (var integer i := 0; i < len-strlen; i := i+1) {
2784 str := str & pad;
2785 }
2786 return str;
2787}
2788
2789/* Send PAGING via RSL, expect it to shw up on PCU socket */
2790testcase TC_pcu_paging_from_rsl() runs on test_CT {
2791 f_init();
2792
2793 for (var integer i := 0; i < 100; i := i+1) {
2794 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2795 timer T := 3.0;
2796 if (i < 50) {
2797 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2798 } else {
2799 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2800 }
2801 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2802 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2803 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2804
2805 /* Send RSL PAGING COMMAND */
2806 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2807 T.start;
2808 alt {
2809 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2810 }
2811 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2812 setverdict(fail, "Unexpected PAGING REQ");
2813 self.stop;
2814 }
2815 [] PCU.receive { repeat; }
2816 [] T.timeout {
2817 setverdict(fail, "Timeout waiting for PAGING REQ");
2818 self.stop;
2819 }
2820 }
2821 }
2822 setverdict(pass);
2823}
2824
Harald Welte3d04ae62018-04-04 20:29:05 +02002825/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002826 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002827 ***********************************************************************/
2828
2829private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2830runs on ConnHdlr {
2831 var PCUIF_send_data sd;
2832 /* Expect BTS to immediately acknowledge activation as PDCH */
2833 PCU.clear;
2834 f_rsl_chan_act(g_pars.chan_mode);
2835 /* expect INFO_IND on PCU interface listing TS as PDCH */
2836 alt {
2837 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2838 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2839 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2840 self.stop;
2841 }
2842 }
2843 [] PCU.receive { repeat; }
2844 }
2845 /* try to activate this PDCH from the PCU point of view */
2846 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2847 /* FIXME: is there a response? */
2848}
2849
2850private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2851runs on ConnHdlr {
2852 var PCUIF_send_data sd;
2853 /* Send RSL CHAN REL (deactivate) */
2854 PCU.clear;
2855 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2856 /* expect BTS to ask PCU to deactivate the channel */
2857 alt {
2858 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2859 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2860 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2861 self.stop;
2862 }
2863 }
2864 [] PCU.receive { repeat; }
2865 }
2866 /* Emulate PCU asking BTS to deactivate PDCH */
2867 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2868 alt {
2869 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2870 setverdict(pass);
2871 }
2872 [] RSL.receive { repeat; }
2873 }
2874}
2875
2876/* Activate Osmocom-style dynamic PDCH from BSC side */
2877function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2878 var PCUIF_Message first_info;
2879 var integer ts_nr := g_chan_nr.tn;
2880 var integer trx_nr := 0;
2881 var integer bts_nr := 0;
2882 var integer pcu_conn_id := -1;
2883
2884 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2885
2886 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2887 f_sleep(3.0);
2888 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2889 setverdict(pass);
2890}
2891testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2892 var ConnHdlrPars pars;
2893 var ConnHdlr vc_conn;
2894 f_init(testcasename());
2895
2896 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2897 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2898 vc_conn.done;
2899}
2900
2901/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2902function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2903 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002904 var integer pcu_conn_id := -1;
2905
2906 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2907
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002908 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2909 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2910 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002911 setverdict(pass);
2912}
2913testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2914 var ConnHdlrPars pars;
2915 var ConnHdlr vc_conn;
2916 f_init(testcasename());
2917
2918 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2919 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2920 vc_conn.done;
2921}
2922
2923/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2924function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2925 var PCUIF_Message first_info;
2926 var integer ts_nr := g_chan_nr.tn;
2927 var integer trx_nr := 0;
2928 var integer bts_nr := 0;
2929 var integer pcu_conn_id := -1;
2930
2931 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2932
2933 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002934 /* Send a second Chan Activ and expect it to be NACKed */
2935 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2936 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002937 setverdict(pass);
2938}
2939testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2940 var ConnHdlrPars pars;
2941 var ConnHdlr vc_conn;
2942 f_init(testcasename());
2943
2944 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2945 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2946 vc_conn.done;
2947}
2948
2949/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2950function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2951 var PCUIF_Message first_info;
2952 var integer ts_nr := g_chan_nr.tn;
2953 var integer trx_nr := 0;
2954 var integer bts_nr := 0;
2955 var integer pcu_conn_id := -1;
2956 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2957
2958 /* register for the TCH/F channel number */
2959 f_rslem_register(0, chan_nr);
2960
2961 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2962
2963 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2964 "RSL CHAN ACT");
2965 setverdict(pass);
2966}
2967testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2968 var ConnHdlrPars pars;
2969 var ConnHdlr vc_conn;
2970 f_init(testcasename());
2971
2972 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2973 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2974 vc_conn.done;
2975}
2976
2977/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2978function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2979 var PCUIF_Message first_info;
2980 var integer ts_nr := g_chan_nr.tn;
2981 var integer trx_nr := 0;
2982 var integer bts_nr := 0;
2983 var integer pcu_conn_id := -1;
2984 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2985 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2986
2987 /* register for the TCH/H channel numbers */
2988 f_rslem_register(0, chan_nr[0]);
2989 f_rslem_register(0, chan_nr[1]);
2990
2991 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2992
2993 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2994 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2995 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2996 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2997 setverdict(pass);
2998}
2999testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3000 var ConnHdlrPars pars;
3001 var ConnHdlr vc_conn;
3002 f_init(testcasename());
3003
3004 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3005 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3006 vc_conn.done;
3007}
3008
Harald Welte9bbbfb52018-04-05 09:33:19 +02003009/***********************************************************************
3010 * IPA Style Dynamic Timeslot Support
3011 ***********************************************************************/
3012
3013private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3014runs on ConnHdlr {
3015 var PCUIF_send_data sd;
3016 /* Expect BTS to immediately acknowledge activation as PDCH */
3017 PCU.clear;
3018 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3019 /* expect INFO_IND on PCU interface listing TS as PDCH */
3020 alt {
3021 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3022 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
3023 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
3024 self.stop;
3025 }
3026 }
3027 [] PCU.receive { repeat; }
3028 }
3029 /* try to activate this PDCH from the PCU point of view */
3030 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3031 /* FIXME: is there a response? */
3032
3033 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3034}
3035
3036private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3037runs on ConnHdlr {
3038 var PCUIF_send_data sd;
3039 /* Send RSL CHAN REL (deactivate) */
3040 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3041 PCU.clear;
3042 /* expect BTS to ask PCU to deactivate the channel */
3043 alt {
3044 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3045 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
3046 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
3047 self.stop;
3048 }
3049 }
3050 [] PCU.receive { repeat; }
3051 }
3052 /* Emulate PCU asking BTS to deactivate PDCH */
3053 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3054 alt {
3055 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3056 setverdict(pass);
3057 }
3058 [] RSL.receive { repeat; }
3059 }
3060}
3061
3062/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3063function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3064 var PCUIF_Message first_info;
3065 var integer ts_nr := g_chan_nr.tn;
3066 var integer trx_nr := 0;
3067 var integer bts_nr := 0;
3068 var integer pcu_conn_id := -1;
3069
3070 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3071
3072 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3073 f_sleep(3.0);
3074 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3075
3076 setverdict(pass);
3077
3078}
3079testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3080 var ConnHdlrPars pars;
3081 var ConnHdlr vc_conn;
3082 f_init();
3083
3084 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3085 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3086 vc_conn.done;
3087}
3088
3089/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3090function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3091 var PCUIF_Message first_info;
3092 var integer ts_nr := g_chan_nr.tn;
3093 var integer trx_nr := 0;
3094 var integer bts_nr := 0;
3095 var integer pcu_conn_id := -1;
3096
3097 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3098
3099 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3100 "RSL CHAN ACT");
3101 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3102 "RF CHAN REL", true);
3103 setverdict(pass);
3104}
3105testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3106 var ConnHdlrPars pars;
3107 var ConnHdlr vc_conn;
3108 f_init(testcasename());
3109
3110 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3111 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3112 vc_conn.done;
3113}
3114
3115/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3116function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3117 var PCUIF_Message first_info;
3118 var integer ts_nr := g_chan_nr.tn;
3119 var integer trx_nr := 0;
3120 var integer bts_nr := 0;
3121 var integer pcu_conn_id := -1;
3122
3123 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3124
3125 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3126 "RSL CHAN ACT");
3127
3128 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3129 alt {
3130 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3131 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
3132 setverdict(fail, "Unexpected PDCH ACT ACK");
3133 self.stop;
3134 }
3135 [] RSL.receive { repeat; }
3136 }
3137
3138 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3139 "RF CHAN REL", true);
3140 setverdict(pass);
3141}
3142testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3143 var ConnHdlrPars pars;
3144 var ConnHdlr vc_conn;
3145 f_init(testcasename());
3146
3147 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3148 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3149 vc_conn.done;
3150}
3151
3152/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3153function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3154 var PCUIF_Message first_info;
3155 var integer ts_nr := g_chan_nr.tn;
3156 var integer trx_nr := 0;
3157 var integer bts_nr := 0;
3158 var integer pcu_conn_id := -1;
3159
3160 /* register for the TCH/F channel number */
3161 f_rslem_register(0, g_chan_nr);
3162
3163 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3164
3165 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3166
3167 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3168 "RSL CHAN ACT");
3169
3170 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3171
3172 setverdict(pass);
3173}
3174testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3175 var ConnHdlrPars pars;
3176 var ConnHdlr vc_conn;
3177 f_init(testcasename());
3178
3179 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3180 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3181 vc_conn.done;
3182}
3183
3184
Harald Welte0472ab42018-03-12 15:02:26 +01003185/***********************************************************************
3186 * LAPDm / RLL related
3187 ***********************************************************************/
3188
3189private function f_tx_lapdm(template (value) LapdmFrame l,
3190 template (value) RslLinkId link_id) runs on ConnHdlr {
3191 var octetstring l2 := enc_LapdmFrame(valueof(l));
3192 if (valueof(link_id.c) == SACCH) {
3193 /* prepend dummy L1 header */
3194 l2 := '0000'O & l2;
3195 }
3196 log("encoding ", l, " to ", l2);
3197 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3198}
3199
3200type record RllTestCase {
3201 uint3_t sapi,
3202 RslLinkId link_id,
3203 octetstring l3,
3204 boolean exp
3205}
3206type record of RllTestCase RllTestCases;
3207template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3208 sapi := sapi,
3209 link_id := id,
3210 l3 := l3,
3211 exp := exp
3212}
3213
3214/* execute the same callback function with a set of different parameters (tcs) on a
3215 * variety of logical channels */
3216private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3217 var ConnHdlrPars pars;
3218 var ConnHdlr vc_conn;
3219 f_init(testcasename());
3220
3221 /* test on each of the channels we have */
3222 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3223 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3224
3225 /* test each of the test cases on the current channel */
3226 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3227 pars.spec.rll := tcs[j];
3228 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3229 vc_conn := f_start_handler(fn, pars);
3230 vc_conn.done;
3231 }
3232 }
3233
3234 f_shutdown();
3235}
3236
3237/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3238private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3239 var RllTestCase tc := g_pars.spec.rll;
3240 timer T := 3.0;
3241
3242 f_l1_tune(L1CTL);
3243 RSL.clear;
3244
3245 /* activate the logical channel */
3246 f_est_dchan();
3247 L1CTL.clear;
3248
3249 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3250 T.start;
3251 alt {
3252 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3253 if (tc.exp) {
3254 setverdict(pass);
3255 } else {
3256 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3257 }
3258 }
3259 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3260 if (tc.exp) {
3261 setverdict(pass);
3262 } else {
3263 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3264 }
3265 }
3266 [tc.exp] T.timeout {
3267 setverdict(fail, "Timeout waiting for EST IND");
3268 }
3269 [not tc.exp] T.timeout {
3270 setverdict(pass);
3271 }
3272 }
3273
3274 f_rsl_chan_deact();
3275 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3276 f_rslem_unregister(0, g_chan_nr);
3277}
3278testcase TC_rll_est_ind() runs on test_CT {
3279 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003280 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003281 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003282 /* normal SAPI0 establishment */
3283 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003284 /* SAPI 3 doesn't support contention resolution */
3285 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3286 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3287 /* normal SAPI3 establishment on main DCCH */
3288 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3289 /* normal SAPI3 establishment on SACCH */
3290 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3291 };
3292 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3293}
3294
3295/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3296private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3297 var RllTestCase tc := g_pars.spec.rll;
3298 var L1ctlDlMessage dl;
3299 timer T := 3.0;
3300
3301 f_l1_tune(L1CTL);
3302 RSL.clear;
3303
3304 /* activate the logical channel */
3305 f_est_dchan();
3306 L1CTL.clear;
3307
3308 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3309 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3310 T.start;
3311 alt {
3312 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3313 var LapdmFrame lapdm;
3314 var octetstring l2 := dl.payload.data_ind.payload;
3315 if (dl.dl_info.link_id.c == SACCH) {
3316 /* remove L1 header */
3317 l2 := substr(l2, 2, lengthof(l2)-2);
3318 }
3319 lapdm.ab := dec_LapdmFrameAB(l2);
3320 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3321 setverdict(pass);
3322 } else {
3323 repeat;
3324 }
3325 }
3326 [] L1CTL.receive { repeat; }
3327 [] T.timeout {
3328 setverdict(fail, "Timeout waiting for SABM");
3329 self.stop;
3330 }
3331 }
3332
3333 f_rsl_chan_deact();
3334 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3335 f_rslem_unregister(0, g_chan_nr);
3336}
3337testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3338 var RllTestCases tcs := {
3339 /* normal SAPI3 establishment on main DCCH */
3340 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3341 };
3342 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3343}
3344testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3345 var RllTestCases tcs := {
3346 /* normal SAPI3 establishment on SACCH */
3347 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3348 }
3349 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3350}
3351
3352/* altstep to receive a LAPDm frame matching the given template */
3353private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3354 var L1ctlDlMessage dl;
3355 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3356 var LapdmFrame lapdm;
3357 var octetstring l2 := dl.payload.data_ind.payload;
3358 if (dl.dl_info.link_id.c == SACCH) {
3359 /* remove L1 header */
3360 l2 := substr(l2, 2, lengthof(l2)-2);
3361 }
3362 if (ischosen(exp.ab)) {
3363 lapdm.ab := dec_LapdmFrameAB(l2);
3364 } else if (ischosen(exp.b4)) {
3365 lapdm.b4 := dec_LapdmFrameB4(l2);
3366 } else if (ischosen(exp.bbis)) {
3367 lapdm.bbis := dec_LapdmFrameBbis(l2);
3368 }
3369 log("Rx LAPDm ", lapdm);
3370 if (match(lapdm, exp)) {
3371 setverdict(pass);
3372 } else {
3373 repeat;
3374 }
3375 }
3376 [] L1CTL.receive { repeat; }
3377}
3378private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3379 timer T := t;
3380 T.start;
3381 alt {
3382 [] T.timeout {
3383 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3384 self.stop;
3385 }
3386 [] as_l1_exp_lapdm(exp);
3387 }
3388}
3389
3390/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3391private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3392 /* send SABM from MS -> BTS */
3393 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3394 /* expect RLL EST IND on Abis */
3395 alt {
3396 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3397 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3398 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3399 setverdict(fail, "Failing due to RSL_ERROR_IND");
3400 self.stop;
3401 }
3402 [] RSL.receive { repeat; }
3403 }
3404 /* expect UA from BTS -> MS */
3405 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3406}
3407
3408/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3409private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3410 var RllTestCase tc := g_pars.spec.rll;
3411
3412 f_l1_tune(L1CTL);
3413 RSL.clear;
3414
3415 /* activate the logical channel */
3416 f_est_dchan();
3417 L1CTL.clear;
3418
3419 /* first establish the link-layer */
3420 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3421
3422 /* then send the DISC */
3423 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3424 /* ... and expect the REL IND on the RSL side */
3425 alt {
3426 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3427 setverdict(pass);
3428 }
3429 }
3430
3431 /* release the channel */
3432 f_rsl_chan_deact();
3433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3434 f_rslem_unregister(0, g_chan_nr);
3435}
3436testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3437 var RllTestCases tcs := {
3438 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3439 };
3440 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3441}
3442
3443testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3444 var RllTestCases tcs := {
3445 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3446 };
3447 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3448}
3449testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3450 var RllTestCases tcs := {
3451 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3452 };
3453 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3454}
3455testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3456 var RllTestCases tcs := {
3457 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3458 };
3459 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3460}
3461
3462/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3463private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3464 var RllTestCase tc := g_pars.spec.rll;
3465 f_l1_tune(L1CTL);
3466 RSL.clear;
3467
3468 /* activate the logical channel */
3469 f_est_dchan();
3470 L1CTL.clear;
3471
3472 /* first establish the link-layer */
3473 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3474
3475 /* then send the REL REQ via RSL */
3476 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3477 /* ... and expect the DISC on the Um side */
3478 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003479 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003480 /* FIXME: send a UA in resposne to the DISC */
3481 }
3482 }
3483
3484 /* release the channel */
3485 f_rsl_chan_deact();
3486 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3487 f_rslem_unregister(0, g_chan_nr);
3488}
3489testcase TC_rll_rel_req() runs on test_CT {
3490 var RllTestCases tcs := {
3491 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3492 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3493 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3494 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3495 };
3496 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3497}
3498
3499/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3500testcase TC_rll_data_req() runs on test_CT {
3501}
3502
3503/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3504testcase TC_rll_data_ind() runs on test_CT {
3505}
3506
3507/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3508private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3509 var RllTestCase tc := g_pars.spec.rll;
3510
3511 f_l1_tune(L1CTL);
3512 RSL.clear;
3513
3514 f_est_dchan();
3515 L1CTL.clear;
3516
3517 /* Send UNITDATA REQ on RSL side */
3518 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3519 /* Expect it to arrive on the other side */
3520 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003521 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003522 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003523 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003524 }
3525
3526 /* release the channel */
3527 f_rsl_chan_deact();
3528 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3529 f_rslem_unregister(0, g_chan_nr);
3530}
3531testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3532 var octetstring l3 := f_rnd_octstring(15);
3533 var RllTestCases tcs := {
3534 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3535 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3536 };
3537 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3538}
3539testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3540 var octetstring l3 := f_rnd_octstring(19);
3541 var RllTestCases tcs := {
3542 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3543 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3544 };
3545 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3546}
3547
3548/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3549private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3550 var RllTestCase tc := g_pars.spec.rll;
3551
3552 f_l1_tune(L1CTL);
3553 RSL.clear;
3554
3555 f_est_dchan();
3556 L1CTL.clear;
3557
3558 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003559 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003560 /* Expdct RLL UNITDATA IND on RSL side */
3561 alt {
3562 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3563 setverdict(pass);
3564 }
3565 [] RSL.receive { repeat; }
3566 }
3567
3568 /* release the channel */
3569 f_rsl_chan_deact();
3570 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3571 f_rslem_unregister(0, g_chan_nr);
3572}
3573testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3574 var octetstring l3 := f_rnd_octstring(15);
3575 var RllTestCases tcs := {
3576 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3577 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3578 };
3579 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3580}
3581testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3582 var octetstring l3 := f_rnd_octstring(18);
3583 var RllTestCases tcs := {
3584 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3585 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3586 };
3587 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3588}
3589
Harald Weltee613f962018-04-18 22:38:16 +02003590/***********************************************************************
3591 * Encryption Related
3592 ***********************************************************************/
3593
3594/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3595function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3596 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3597 if (link_id.c == SACCH) {
3598 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3599 } else {
3600 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3601 }
3602}
3603
3604/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3605function f_unitdata_mo(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3606 timer T := 3.0;
3607 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3608 T.start;
3609 /* Expect RLL UNITDATA IND on RSL side */
3610 alt {
3611 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3612 setverdict(pass);
3613 }
3614 [] T.timeout {
3615 setverdict(fail, "Timeout waiting for UNIT_DATA_IND");
3616 }
3617 [] RSL.receive { repeat; }
3618 }
3619}
3620
3621/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3622function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3623 f_l1_tune(L1CTL);
3624 f_est_dchan(true);
3625
3626 /* now we actually need to transmit some data both ways to check if the encryption works */
3627 var L1ctlDlMessage dl;
3628
3629 var octetstring l3 := f_rnd_octstring(16);
3630 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3631
3632 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3633 f_unitdata_mt(link_id, l3);
3634
3635 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3636 f_unitdata_mo(link_id, l3);
3637
3638 /* release the channel */
3639 f_rsl_chan_deact();
3640 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3641 f_rslem_unregister(0, g_chan_nr);
3642}
3643testcase TC_chan_act_a51() runs on test_CT {
3644 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3645 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3646 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3647}
3648testcase TC_chan_act_a52() runs on test_CT {
3649 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3650 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3651 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3652}
3653testcase TC_chan_act_a53() runs on test_CT {
3654 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3655 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3656 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3657}
3658
3659
3660/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3661function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3662 /* L3 payload doesn't matter, as it is passed transparently */
3663 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3664 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3665 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3666
3667 f_l1_tune(L1CTL);
3668
3669 /* first establish a dedicated channel in the clear */
3670 f_est_dchan(false);
3671
3672 /* Establish ABM */
3673 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3674
3675 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3676 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3677 /* expect the L3 to arrive still unencrypted on the MS side */
3678 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3679
3680 /* configure L1 to apply ciphering */
3681 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3682 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3683
3684 /* send first ciphered I-frame in response */
3685 l3 := '0a0b0c0d'O;
3686 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3687 RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3));
3688
3689 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3690 * and hence enable encryption also on the downlink */
3691
3692 /* expect bi-directional communication work in encrypted mode */
3693 f_unitdata_mo(link_id, f_rnd_octstring(15));
3694 f_unitdata_mt(link_id, f_rnd_octstring(15));
3695
3696 /* release the channel */
3697 f_rsl_chan_deact();
3698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3699 f_rslem_unregister(0, g_chan_nr);
3700}
3701testcase TC_encr_cmd_a51() runs on test_CT {
3702 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3703 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3704 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3705}
3706testcase TC_encr_cmd_a52() runs on test_CT {
3707 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3708 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3709 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3710}
3711testcase TC_encr_cmd_a53() runs on test_CT {
3712 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3713 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3714 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3715}
3716
3717private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3718 var LapdmFrame lf;
3719 var octetstring reenc;
3720
3721 /* decode the LAPDm frame */
3722 if (ischosen(exp_match.ab)) {
3723 lf.ab := dec_LapdmFrameAB(enc);
3724 } else {
3725 setverdict(fail, "unsupported frame type");
3726 self.stop;
3727 }
3728
3729 /* check if decoder result matches expectation */
3730 if (not match(lf, exp_match)) {
3731 setverdict(fail, name, ": decoded LAPDm doesn't match");
3732 } else {
3733 log(name, ": matched");
3734 setverdict(pass);
3735 }
3736
3737 /* test if re-encoded frame equals original input */
3738 reenc := enc_LapdmFrame(lf);
3739 if (enc != reenc) {
3740 setverdict(fail, name, ": re-encoded LAPDm frame doesn't match");
3741 } else {
3742 setverdict(pass);
3743 }
3744}
3745
3746testcase TC_lapdm_selftest() runs on test_CT {
3747 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3748 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3749 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3750 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3751 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3752 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3753 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3754}
3755
Harald Welte0472ab42018-03-12 15:02:26 +01003756
3757/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3758/* protocol error as per 44.006 */
3759/* link layer failure (repetition of I-frame N200 times without ACK */
3760/* repetition of SABM or DISC N200 times without ACK */
3761/* receptiom of SABM in multi-frame established state */
3762
3763
3764
3765
Harald Welte883340c2018-02-28 18:59:29 +01003766
Harald Welte68e495b2018-02-25 00:05:57 +01003767/* TODO Areas:
3768
3769* channel activation
3770** with BS_Power / MS_Power, bypassing power control loop
3771** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01003772** with timing advance from initial activation on
3773* mode modify
3774** encryption
3775** multirate
3776* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01003777** unsupported algorithm
3778* handover detection
3779* MS Power Control
3780* BS Power Control
3781* Physical Context
3782* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003783* CCCH Load Indication for PCH and RACH
3784* Delete Indication on AGCH overflow
3785* SMS Broadcast Req / Cmd / CBCH LOad Ind
3786* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003787* error handling
3788* discriminator error
3789** type error
3790** sequence error
3791** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003792* PCU interface
3793** TIME_IND from BTS->PCU
3794** DATA_IND from BTS->PCU
3795** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003796
3797*/
Harald Welte70767382018-02-21 12:16:40 +01003798
3799control {
3800 execute( TC_chan_act_stress() );
3801 execute( TC_chan_act_react() );
3802 execute( TC_chan_deact_not_active() );
3803 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003804 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003805 execute( TC_sacch_filling() );
3806 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003807 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003808 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003809 execute( TC_rach_content() );
3810 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003811 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003812 execute( TC_meas_res_sign_tchf() );
3813 execute( TC_meas_res_sign_tchh() );
3814 execute( TC_meas_res_sign_sdcch4() );
3815 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003816 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003817 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003818 execute( TC_paging_imsi_80percent() );
3819 execute( TC_paging_tmsi_80percent() );
3820 execute( TC_paging_imsi_200percent() );
3821 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003822 execute( TC_rsl_protocol_error() );
3823 execute( TC_rsl_mand_ie_error() );
3824 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003825 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003826 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003827 execute( TC_si_sched_2bis() );
3828 execute( TC_si_sched_2ter() );
3829 execute( TC_si_sched_2ter_2bis() );
3830 execute( TC_si_sched_2quater() );
3831 execute( TC_si_sched_13() );
3832 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003833 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003834 execute( TC_ipa_crcx_twice_not_active() );
3835 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003836 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003837 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003838
3839 execute( TC_pcu_act_req() );
3840 execute( TC_pcu_act_req_wrong_ts() );
3841 execute( TC_pcu_act_req_wrong_bts() );
3842 execute( TC_pcu_act_req_wrong_trx() );
3843 execute( TC_pcu_deact_req() );
3844 execute( TC_pcu_deact_req_wrong_ts() );
3845 execute( TC_pcu_ver_si13() );
3846 execute( TC_pcu_data_req_wrong_bts() );
3847 execute( TC_pcu_data_req_wrong_trx() );
3848 execute( TC_pcu_data_req_wrong_ts() );
3849 execute( TC_pcu_data_req_ts_inactive() );
3850 execute( TC_pcu_data_req_pdtch() );
3851 execute( TC_pcu_data_req_ptcch() );
3852 execute( TC_pcu_data_req_agch() );
3853 execute( TC_pcu_data_req_imm_ass_pch() );
3854 execute( TC_pcu_rach_content() );
3855 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003856
3857 execute( TC_dyn_osmo_pdch_act_deact() );
3858 execute( TC_dyn_osmo_pdch_unsol_deact() );
3859 execute( TC_dyn_osmo_pdch_double_act() );
3860 execute( TC_dyn_osmo_pdch_tchf_act() );
3861 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003862 execute( TC_dyn_ipa_pdch_act_deact() );
3863 execute( TC_dyn_ipa_pdch_tchf_act() );
3864 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3865 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003866
3867 execute( TC_rll_est_ind() );
3868 execute( TC_rll_est_req_DCCH_3() );
3869 execute( TC_rll_est_req_ACCH_3() );
3870 execute( TC_rll_rel_ind_DCCH_0() );
3871 execute( TC_rll_rel_ind_DCCH_3() );
3872 execute( TC_rll_rel_ind_ACCH_0() );
3873 execute( TC_rll_rel_ind_ACCH_3() );
3874 execute( TC_rll_rel_req() );
3875 execute( TC_rll_unit_data_req_DCCH() );
3876 execute( TC_rll_unit_data_req_ACCH() );
3877 execute( TC_rll_unit_data_ind_DCCH() );
3878 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02003879
3880 execute( TC_chan_act_a51() );
3881 execute( TC_chan_act_a52() );
3882 execute( TC_chan_act_a53() );
3883 execute( TC_encr_cmd_a51() );
3884 execute( TC_encr_cmd_a52() );
3885 execute( TC_encr_cmd_a53() );
3886
3887 execute( TC_lapdm_selftest() );
Harald Welte70767382018-02-21 12:16:40 +01003888}
3889
3890
3891}