blob: 05831718f0feb94face1bcbb2272f52c104c8307 [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 }
1297 [] g_Tmeas_exp.timeout {
1298 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
Harald Welte294b0a22018-03-10 23:26:48 +01001671 f_shutdown();
1672
Harald Welte68e495b2018-02-25 00:05:57 +01001673 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1674 " rcvd_ids=", st.num_paging_rcv_ids);
1675 return st;
1676}
1677
1678/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1679 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1680 * - that CCCH LOAD IND (PCH) are being generated
1681 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1682testcase TC_paging_imsi_80percent() runs on test_CT {
1683 var PagingTestCfg cfg := {
1684 combined_ccch := true,
1685 bs_ag_blks_res := 1,
1686 load_factor := 0.8,
1687 exp_load_ind := true,
1688 exp_overload := false,
1689 use_tmsi := false
1690 };
1691 var PagingTestState st := f_TC_paging(cfg);
1692 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1693 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1694 st.num_paging_rcv_ids);
1695 } else {
1696 setverdict(pass);
1697 }
1698}
1699
1700/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1701 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1702 * - that CCCH LOAD IND (PCH) are being generated
1703 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1704testcase TC_paging_tmsi_80percent() runs on test_CT {
1705 var PagingTestCfg cfg := {
1706 combined_ccch := true,
1707 bs_ag_blks_res := 1,
1708 load_factor := 0.8,
1709 exp_load_ind := true,
1710 exp_overload := false,
1711 use_tmsi := true
1712 };
1713 var PagingTestState st := f_TC_paging(cfg);
1714 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1715 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1716 st.num_paging_rcv_ids);
1717 } else {
1718 setverdict(pass);
1719 }
1720}
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 }
1744}
1745
1746/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1747 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1748 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1749 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1750testcase TC_paging_tmsi_200percent() runs on test_CT {
1751 var PagingTestCfg cfg := {
1752 combined_ccch := true,
1753 bs_ag_blks_res := 1,
1754 load_factor := 2.0,
1755 exp_load_ind := true,
1756 exp_overload := true,
1757 use_tmsi := true
1758 };
1759 var PagingTestState st := f_TC_paging(cfg);
1760 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1761 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001762 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001763 if (not match(st.num_paging_rcv_ids, tpl)) {
1764 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1765 } else {
1766 setverdict(pass);
1767 }
1768}
1769
1770
Harald Welte93640c62018-02-25 16:59:33 +01001771/***********************************************************************
1772 * Immediate Assignment / AGCH
1773 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001774const MobileAllocation c_MA_null := {
1775 len := 0,
1776 ma := ''B
1777}
Harald Welte93640c62018-02-25 16:59:33 +01001778
Harald Weltee8d750e2018-06-10 21:41:35 +02001779template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1780 uint12_t arfcn := 871) := {
1781 chan_nr := chan_nr,
1782 tsc := tsc,
1783 h := false,
1784 arfcn := arfcn,
1785 maio_hsn := omit
1786}
1787
1788private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1789 return int2str(num_tx) & " sent, "
1790 & int2str(num_rx) & " received, "
1791 & int2str(num_del) & " deleted";
1792}
1793
1794private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1795 var L1ctlDlMessage l1_dl;
1796 timer T := 10.0;
1797 var integer num_tx := 0;
1798 var integer num_rx := 0;
1799 var integer num_del := 0;
1800 var charstring res_str;
1801 var float rx_ratio;
1802
Harald Welte68e495b2018-02-25 00:05:57 +01001803 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001804 f_init_l1ctl();
1805 f_l1_tune(L1CTL);
1806
1807 for (var integer i := 0; i < num_total; i := i+1) {
1808 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1809 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1810 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001811 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001812 num_tx := num_tx+1;
1813 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001814 }
1815 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02001816 T.start;
1817 alt {
1818 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
1819 num_del := num_del+1;
1820 repeat;
1821 }
1822 [] RSL_CCHAN.receive {
1823 repeat;
1824 }
1825 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
1826 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1827 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
1828 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
1829 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
1830 //setverdict(fail, "Unexpected IMM-ASS values on AGCH: ", rr);
1831 //self.stop;
1832 } else {
1833 num_rx := num_rx+1;
1834 }
1835 repeat;
1836 }
1837 [] L1CTL.receive { repeat; }
1838 [] T.timeout { }
1839 }
1840 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
1841 log("AGCH test: " & res_str);
1842 if (num_rx + num_del != num_tx) {
1843 setverdict(fail, "RX + DEL != TX ?!?: " & res_str);
1844 }
1845 rx_ratio := int2float(num_rx) / int2float(num_tx);
1846 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
1847 setverdict(fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
1848 } else {
1849 setverdict(pass);
1850 }
Harald Welte68e495b2018-02-25 00:05:57 +01001851}
1852
Harald Weltee8d750e2018-06-10 21:41:35 +02001853/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
1854testcase TC_imm_ass_1000_20ms() runs on test_CT {
1855 f_TC_imm_ass(1000, 0.02, 0.25);
1856}
1857
1858/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
1859testcase TC_imm_ass_200_0ms() runs on test_CT {
1860 f_TC_imm_ass(200, 0.0, 0.05);
1861}
1862
1863/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
1864testcase TC_imm_ass_200_76ms() runs on test_CT {
1865 f_TC_imm_ass(150, 0.076, 1.00);
1866}
1867
1868
1869
Harald Welte48494ca2018-02-25 16:59:50 +01001870/***********************************************************************
1871 * BCCH
1872 ***********************************************************************/
1873
1874/* tuple of Frame Number + decoded SI */
1875type record SystemInformationFn {
1876 GsmFrameNumber frame_number,
1877 SystemInformation si
1878}
1879
1880/* an arbitrary-length vector of decoded SI + gsmtap header */
1881type record of SystemInformationFn SystemInformationVector;
1882
1883/* an array of SI-vectors indexed by TC value */
1884type SystemInformationVector SystemInformationVectorPerTc[8];
1885
1886/* determine if a given SI vector contains given SI type at least once */
1887function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1888 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1889 var integer fn_mod51 := arr[i].frame_number mod 51;
1890 if (not bcch_ext and fn_mod51 == 2 or
1891 bcch_ext and fn_mod51 == 6) {
1892 if (arr[i].si.header.message_type == key) {
1893 return true;
1894 }
1895 }
1896 }
1897 return false;
1898}
1899
1900/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1901function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1902 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1903 setverdict(fail, "No ", key, " in TC=", tc, "!");
1904 }
1905}
1906
1907/* check if a given SI vector contains given SI type at least once on any TC */
1908function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1909 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1910 if (f_si_vecslot_contains(arr[tc], key) or
1911 f_si_vecslot_contains(arr[tc], key, true)) {
1912 return true;
1913 }
1914 }
1915 return false;
1916}
1917
1918/* determine if a given SI vector contains given SI type at least N of M times */
1919function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1920 var integer count := 0;
1921 if (sizeof(arr) < m) {
1922 setverdict(fail, "Error: Insufficient SI in array");
1923 self.stop;
1924 }
1925 for (var integer i:= 0; i < m; i := i + 1) {
1926 var integer fn_mod51 := arr[i].frame_number mod 51;
1927 if (not bcch_ext and fn_mod51 == 2 or
1928 bcch_ext and fn_mod51 == 6) {
1929 if (arr[i].si.header.message_type == key) {
1930 count := count + 1;
1931 }
1932 }
1933 }
1934 if (count >= n) {
1935 return true;
1936 } else {
1937 return false;
1938 }
1939}
1940
1941/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1942function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1943 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1944 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1945 }
1946}
1947
1948/* determine if a given SI vector contains given SI type at least once */
1949function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1950 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1951 var integer fn_mod51 := arr[i].frame_number mod 51;
1952 if (not bcch_ext and fn_mod51 == 2 or
1953 bcch_ext and fn_mod51 == 6) {
1954 if (arr[i].si.header.message_type != key) {
1955 return false;
1956 }
1957 }
1958 }
1959 return true;
1960}
1961
1962/* ensure a given TC slot of the SI vector contains only given SI type */
1963function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1964 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1965 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1966 }
1967}
1968
1969/* SI configuration of cell, against which we validate actual SI messages */
1970type set SystemInformationConfig {
1971 boolean bcch_extended,
1972 boolean si1_present,
1973 boolean si2bis_present,
1974 boolean si2ter_present,
1975 boolean si2quater_present,
1976 boolean si7_present,
1977 boolean si8_present,
1978 boolean si9_present,
1979 boolean si13_present,
1980 boolean si13alt_present,
1981 boolean si15_present,
1982 boolean si16_present,
1983 boolean si17_present,
1984 boolean si2n_present,
1985 boolean si21_present,
1986 boolean si22_present
1987}
1988
1989/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1990function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1991 var integer i;
1992 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1993 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001994 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001995 }
1996 }
1997 if (cfg.si1_present) {
1998 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1999 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2000 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2001 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2002 /* make sure *ALL* contain SI1 */
2003 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2004 }
2005 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2006 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2007 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2008 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2009 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2010 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2011
2012 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2013 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2014 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2015 * consecutive occurrences of TC = 4. */
2016 if (cfg.si2bis_present and not cfg.si2ter_present) {
2017 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2018 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2019 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2020 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2021 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2022 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2023 }
2024
2025 if (cfg.si7_present or cfg.si8_present) {
2026 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2027 * if System Information type 4 does not contain all information needed for cell
2028 * selection and reselection. */
2029 if (not cfg.bcch_extended) {
2030 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2031 }
2032 if (cfg.si7_present) {
2033 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2034 }
2035 if (cfg.si8_present) {
2036 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2037 }
2038 }
2039
2040 if (cfg.si2quater_present) {
2041 /* iii) System information type 2 quater is sent if needed, as determined by the system
2042 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2043 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2044 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2045 * within any of 4 consecutive occurrences of TC = 5. */
2046 if (not (cfg.bcch_extended)) {
2047 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2048 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2049 } else {
2050 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2051 }
2052 } else {
2053 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2054 }
2055 }
2056 if (cfg.si9_present) {
2057 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2058 * in system information type 3 as defined in 3GPP TS 44.018. */
2059 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2060 }
2061 if (cfg.si13_present) {
2062 /* vii) System Information type 13 is only related to the GPRS service. System Information
2063 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2064 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2065 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2066 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2067 * within any of 4 consecutive occurrences of TC=4. */
2068 if (not cfg.bcch_extended) {
2069 log("not-bccch-extended");
2070 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2071 } else {
2072 log("bccch-extended");
2073 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2074 }
2075 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
2076 setverdict(fail, "Cannot have SI13alt and SI13");
2077 }
2078 }
2079 if (cfg.si16_present or cfg.si17_present) {
2080 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2081 * should not be sent in a cell where network sharing is used (see rule xv). */
2082 if (cfg.si22_present) {
2083 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2084 }
2085 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
2086 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2087 }
2088 if (not cfg.bcch_extended) {
2089 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2090 }
2091 if (cfg.si16_present) {
2092 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2093 }
2094 if (cfg.si17_present) {
2095 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2096 }
2097 }
2098
2099 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2100 * broadcast information. The frequency with which they are sent is determined by the
2101 * system operator. System Information type 9 identifies the scheduling of System
2102 * Information type 18 and 20 messages. */
2103
2104 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2105 * Information Type 19 is present, then its scheduling shall be indicated in System
2106 * Information Type 9. */
2107
2108 if (cfg.si15_present) {
2109 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2110 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2111 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2112 * 4 consecutive occurrences of TC = 1. */
2113 if (not cfg.bcch_extended) {
2114 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2115 } else {
2116 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2117 }
2118 }
2119 if (cfg.si13alt_present) {
2120 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2121 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2122 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2123 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2124 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2125 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2126 * of TC = 4. */
2127 if (cfg.si13_present) {
2128 testcase.stop("Error: Cannot have SI13alt and SI13");
2129 }
2130 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
2131 setverdict(fail, "Cannot have SI13alt and SI13");
2132 }
2133 if (not cfg.bcch_extended) {
2134 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2135 } else {
2136 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2137 }
2138 }
2139 if (cfg.si2n_present) {
2140 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2141 * as determined by the system operator. In the case that the message is sent on the
2142 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2143 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2144 * consecutive occurrences of TC = 4. */
2145 if (not cfg.bcch_extended) {
2146 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2147 } else {
2148 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2149 }
2150 }
2151 if (cfg.si21_present) {
2152 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2153 * determined by the system operator. If Extended Access Barring is in use in the cell
2154 * then this message is sent at least once within any of 4 consecutive occurrences of
2155 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2156 * cell then this message shall only be sent on BCCH Ext. */
2157 if (not cfg.bcch_extended) {
2158 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2159 } else {
2160 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2161 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
2162 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
2163 }
2164 }
2165 }
2166 if (cfg.si22_present) {
2167 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2168 * should not be sent in a cell where SoLSA is used (see rule viii). System
2169 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2170 * =2 and TC=6. */
2171 if (cfg.si16_present or cfg.si17_present) {
2172 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2173 }
2174 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2175 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2176 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2177 }
2178 if (not cfg.bcch_extended) {
2179 testcase.stop("Error: SI22 requires BCCH Extd!");
2180 } else {
2181 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2182 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2183 }
2184 }
2185}
2186
2187/* sample Systme Information for specified duration via L1CTL */
2188function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2189 timer T := duration;
2190 var SystemInformationVectorPerTc si_per_tc;
2191 var L1ctlDlMessage l1_dl;
2192
2193 /* initialize all per-TC vectors empty */
2194 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2195 si_per_tc[i] := {};
2196 }
2197
2198 /* flush all previous L1 queued msgs */
2199 pt.clear;
2200
2201 T.start;
2202 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002203 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002204 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2205 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2206 log("Ignoring non-RR SI ", l1_dl);
2207 repeat;
2208 }
2209 var SystemInformationFn sig := {
2210 frame_number := l1_dl.dl_info.frame_nr,
2211 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2212 }
2213 var integer tc := f_gsm_compute_tc(sig.frame_number);
2214 log("SI received at TC=", tc, ": ", sig.si);
2215 /* append to the per-TC bucket */
2216 si_per_tc[tc] := si_per_tc[tc] & { sig };
2217 repeat;
2218 }
2219 [] pt.receive { repeat; }
2220 [] T.timeout { }
2221 }
2222
2223 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2224 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2225 }
2226 log("si_per_tc=", si_per_tc);
2227 return si_per_tc;
2228}
2229
2230/* helper function: Set given SI via RSL + validate scheduling.
2231 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2232function f_TC_si_sched() runs on test_CT {
2233 var SystemInformationVectorPerTc si_per_tc;
2234 f_init_l1ctl();
2235 f_l1_tune(L1CTL);
2236
2237 /* Sample + Validate Scheduling */
2238 si_per_tc := f_l1_sample_si(L1CTL);
2239 f_validate_si_scheduling(si_cfg, si_per_tc);
2240
2241 setverdict(pass);
2242}
2243
2244testcase TC_si_sched_default() runs on test_CT {
2245 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002246 /* 2+3+4 are mandatory and set in f_init() */
2247 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002248 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002249}
2250
2251testcase TC_si_sched_1() runs on test_CT {
2252 f_init();
2253 si_cfg.si1_present := true;
2254 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002255 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002256 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002257}
2258
2259testcase TC_si_sched_2bis() runs on test_CT {
2260 f_init();
2261 si_cfg.si2bis_present := true;
2262 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2263 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002264 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002265}
2266
2267testcase TC_si_sched_2ter() runs on test_CT {
2268 f_init();
2269 si_cfg.si2ter_present := true;
2270 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2271 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002272 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002273}
2274
2275testcase TC_si_sched_2ter_2bis() runs on test_CT {
2276 f_init();
2277 si_cfg.si2bis_present := true;
2278 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2279 si_cfg.si2ter_present := true;
2280 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2281 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002282 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002283}
2284
2285testcase TC_si_sched_2quater() runs on test_CT {
2286 f_init();
2287 si_cfg.si2quater_present := true;
2288 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2289 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002290 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002291}
2292
2293testcase TC_si_sched_13() runs on test_CT {
2294 f_init();
2295 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002296 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002297 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002298 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002299}
2300
2301testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2302 f_init();
2303 si_cfg.si2bis_present := true;
2304 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2305 si_cfg.si2ter_present := true;
2306 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2307 si_cfg.si2quater_present := true;
2308 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2309 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002310 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002311 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002312 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002313}
2314
2315
Harald Welte68e495b2018-02-25 00:05:57 +01002316testcase TC_bcch_info() runs on test_CT {
2317 f_init(testcasename());
2318 /* FIXME: enable / disable individual BCCH info */
2319 //ts_RSL_BCCH_INFO(si_type, info);
2320 /* expect no ERROR REPORT after either of them *
2321 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002322 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002323}
2324
Harald Welte93640c62018-02-25 16:59:33 +01002325/***********************************************************************
2326 * Low-Level Protocol Errors / ERROR REPORT
2327 ***********************************************************************/
2328
Harald Welte01d982c2018-02-25 01:31:40 +01002329private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2330 timer T := 5.0;
2331 T.start;
2332 alt {
2333 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2334 setverdict(pass);
2335 }
2336 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2337 setverdict(fail, "Wrong cause in RSL ERR REP");
2338 }
2339 [] RSL_CCHAN.receive {
2340 repeat;
2341 }
2342 [] T.timeout {
2343 setverdict(fail, "Timeout waiting for RSL ERR REP");
2344 }
2345 }
2346}
2347
2348/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2349testcase TC_rsl_protocol_error() runs on test_CT {
2350 f_init(testcasename());
2351 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2352 rsl.ies := omit;
2353 RSL_CCHAN.send(ts_RSL_UD(rsl));
2354
2355 f_exp_err_rep(RSL_ERR_PROTO);
2356}
2357
2358/* Provoke a mandatory IE error and match on ERROR REPORT */
2359testcase TC_rsl_mand_ie_error() runs on test_CT {
2360 f_init(testcasename());
2361
2362 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2363 rsl.ies := { rsl.ies[0] };
2364 RSL_CCHAN.send(ts_RSL_UD(rsl));
2365
2366 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2367}
2368
2369/* Provoke an IE content error and match on ERROR REPORT */
2370testcase TC_rsl_ie_content_error() runs on test_CT {
2371 f_init(testcasename());
2372 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2373 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2374 RSL_CCHAN.send(ts_RSL_UD(rsl));
2375
2376 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2377}
2378
Harald Welte93640c62018-02-25 16:59:33 +01002379/***********************************************************************
2380 * IPA CRCX/MDCX/DLCS media stream handling
2381 ***********************************************************************/
2382
Harald Weltea871a382018-02-25 02:03:14 +01002383/* Send IPA DLCX to inactive lchan */
2384function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002385 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2386 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002387}
2388testcase TC_ipa_dlcx_not_active() runs on test_CT {
2389 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2390 f_init(testcasename());
2391 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2392 vc_conn.done;
2393}
Harald Welte68e495b2018-02-25 00:05:57 +01002394
Harald Weltea3f1df92018-02-25 12:49:55 +01002395/* Send IPA CRCX twice to inactive lchan */
2396function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2397 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2398 "IPA CRCX ACK");
2399 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2400 "IPA CRCX NACK");
2401}
2402testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2403 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2404 f_init(testcasename());
2405 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2406 vc_conn.done;
2407}
2408
2409/* Regular sequence of CRCX/MDCX/DLCX */
2410function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2411 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2412 "IPA CRCX ACK");
2413 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2414 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2415 var uint7_t rtp_pt2 := f_rnd_int(127);
2416 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2417 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2418 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2419 "IPA MDCX ACK");
2420 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2421 "IPA DLCX ACK");
2422}
2423testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2424 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2425 f_init(testcasename());
2426 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2427 vc_conn.done;
2428}
2429
Harald Welte3ae11da2018-02-25 13:36:06 +01002430/* Sequence of CRCX, 2x MDCX, DLCX */
2431function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2432 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2433 "IPA CRCX ACK");
2434 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2435 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2436 var uint7_t rtp_pt2 := f_rnd_int(127);
2437 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2438 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2439 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2440 "IPA MDCX ACK");
2441 /* Second MDCX */
2442 remote_ip := f_rnd_int(c_UINT32_MAX);
2443 remote_port := f_rnd_int(c_UINT16_MAX);
2444 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2445 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2446 "IPA MDCX ACK");
2447 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2448 "IPA DLCX ACK");
2449}
2450testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2451 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2452 f_init(testcasename());
2453 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2454 vc_conn.done;
2455}
2456
Harald Welte9912eb52018-02-25 13:30:15 +01002457/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2458function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2459 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2460 "IPA CRCX NACK");
2461}
2462testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2463 var ConnHdlrPars pars;
2464 var ConnHdlr vc_conn;
2465 f_init(testcasename());
2466
2467 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2468 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2469 vc_conn.done;
2470
2471 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2472 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2473 vc_conn.done;
2474}
2475
Harald Weltea3f1df92018-02-25 12:49:55 +01002476
Harald Welte883340c2018-02-28 18:59:29 +01002477/***********************************************************************
2478 * PCU Socket related tests
2479 ***********************************************************************/
2480
2481private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2482runs on test_CT {
2483 timer T := 3.0;
2484
2485 /* we don't expect any RTS.req before PDCH are active */
2486 T.start;
2487 alt {
2488 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2489 setverdict(fail, "PCU RTS.req before PDCH active?");
2490 self.stop;
2491 }
2492 [] PCU.receive { repeat; }
2493 [] T.timeout { }
2494 }
2495
2496 /* Send PDCH activate request for known PDCH timeslot */
2497 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2498
2499 /* we now expect RTS.req for this timeslot (only) */
2500 T.start;
2501 alt {
2502 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2503 setverdict(pass);
2504 }
2505 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2506 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2507 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2508 self.stop;
2509 }
2510 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2511 setverdict(fail, "RTS.req for wrong TRX/TS");
2512 self.stop;
2513 }
2514 [] PCU.receive { repeat; }
2515 [exp_success] T.timeout {
2516 setverdict(fail, "Timeout waiting for PCU RTS.req");
2517 }
2518 [not exp_success] T.timeout {
2519 setverdict(pass);
2520 }
2521 }
2522}
2523
2524private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2525runs on test_CT {
2526 timer T := 3.0;
2527
2528 /* Send PDCH activate request for known PDCH timeslot */
2529 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2530
2531 PCU.clear;
2532 /* we now expect no RTS.req for this timeslot */
2533 T.start;
2534 alt {
2535 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2536 setverdict(fail, "Received unexpected PCU RTS.req");
2537 self.stop;
2538 }
2539 [] PCU.receive { repeat; }
2540 [] T.timeout {
2541 setverdict(pass);
2542 }
2543 }
2544}
2545
2546/* PDCH activation via PCU socket; check for presence of RTS.req */
2547testcase TC_pcu_act_req() runs on test_CT {
2548 f_init();
2549 f_TC_pcu_act_req(0, 0, 7, true);
2550}
2551
2552/* PDCH activation via PCU socket on non-PDCU timeslot */
2553testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2554 f_init();
2555 f_TC_pcu_act_req(0, 0, 1, false);
2556}
2557
2558/* PDCH activation via PCU socket on wrong BTS */
2559testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2560 f_init();
2561 f_TC_pcu_act_req(23, 0, 7, false);
2562}
2563
2564/* PDCH activation via PCU socket on wrong TRX */
2565testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2566 f_init();
2567 f_TC_pcu_act_req(0, 23, 7, false);
2568}
2569
2570/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2571testcase TC_pcu_deact_req() runs on test_CT {
2572 f_init();
2573 /* Activate PDCH */
2574 f_TC_pcu_act_req(0, 0, 7, true);
2575 f_sleep(1.0);
2576 /* and De-Activate again */
2577 f_TC_pcu_deact_req(0, 0, 7);
2578}
2579
2580/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2581testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2582 f_init();
2583 f_TC_pcu_deact_req(0, 0, 1);
2584}
2585
2586/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2587testcase TC_pcu_ver_si13() runs on test_CT {
2588 const octetstring si13 := '00010203040506070909'O;
2589 var PCUIF_send_data sd;
2590 timer T:= 3.0;
2591 f_init();
2592
2593 /* Set SI13 via RSL */
2594 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2595 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2596 T.start;
2597 alt {
2598 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2599 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2600 setverdict(pass);
2601 } else {
2602 repeat;
2603 }
2604 }
2605 [] PCU.receive { repeat; }
2606 [] T.timeout {
2607 setverdict(fail, "Timeout waiting for SI13");
2608 self.stop;
2609 }
2610 }
2611}
2612
2613private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2614
2615/* helper function to send a PCU DATA.req */
2616private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2617 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2618runs on test_CT
2619{
2620 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2621 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2622}
2623
2624/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2625private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2626 PCUIF_Sapi sapi, octetstring data)
2627runs on test_CT
2628{
2629 var PCUIF_send_data sd;
2630
2631 timer T := 3.0;
2632 T.start;
2633 alt {
2634 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2635 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2636 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2637 sd.data.u.rts_req.fn, sapi, data);
2638 }
2639 [] PCU.receive { repeat; }
2640 [] T.timeout {
2641 setverdict(fail, "Timeout waiting for RTS.ind");
2642 }
2643 }
2644}
2645
2646/* Send DATA.req on invalid BTS */
2647testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2648 f_init();
2649 f_TC_pcu_act_req(0, 0, 7, true);
2650 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2651 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2652 f_sleep(10.0);
2653}
2654
2655/* Send DATA.req on invalid TRX */
2656testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2657 f_init();
2658 f_TC_pcu_act_req(0, 0, 7, true);
2659 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2660 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2661 f_sleep(10.0);
2662}
2663
2664/* Send DATA.req on invalid timeslot */
2665testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2666 f_init();
2667 f_TC_pcu_act_req(0, 0, 7, true);
2668 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2669 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2670 f_sleep(10.0);
2671}
2672
2673/* Send DATA.req on timeslot that hasn't been activated */
2674testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2675 f_init();
2676 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2677 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2678 f_sleep(2.0);
2679}
2680
2681testcase TC_pcu_data_req_pdtch() runs on test_CT {
2682 f_init();
2683 f_TC_pcu_act_req(0, 0, 7, true);
2684 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2685 /* FIXME: how to check this was actually sent */
2686 f_sleep(2.0);
2687}
2688
2689testcase TC_pcu_data_req_ptcch() runs on test_CT {
2690 f_init();
2691 f_TC_pcu_act_req(0, 0, 7, true);
2692 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2693 /* FIXME: how to check this was actually sent */
2694 f_sleep(2.0);
2695}
2696
2697/* Send AGCH from PCU; check it appears on Um side */
2698testcase TC_pcu_data_req_agch() runs on test_CT {
2699 timer T := 3.0;
2700 f_init();
2701 f_init_l1ctl();
2702 f_l1_tune(L1CTL);
2703
2704 f_TC_pcu_act_req(0, 0, 7, true);
2705 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2706
2707 T.start;
2708 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002709 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002710 setverdict(pass);
2711 }
2712 [] L1CTL.receive { repeat; }
2713 [] T.timeout {
2714 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2715 }
2716 }
2717}
2718
2719/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2720testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2721 var octetstring imm_ass := f_rnd_octstring(23);
2722 f_init();
2723 f_init_l1ctl();
2724 f_l1_tune(L1CTL);
2725
2726 /* append 3 last imsi digits so BTS can compute pagng group */
2727 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2728
2729 timer T := 0.5;
2730 T.start;
2731 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002732 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002733 /* TODO: verify paging group */
2734 setverdict(pass);
2735 }
2736 [] L1CTL.receive { repeat; }
2737 [] T.timeout {
2738 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2739 }
2740 }
2741}
2742
2743/* Send RACH from Um side, expect it to show up on PCU socket */
2744testcase TC_pcu_rach_content() runs on test_CT {
2745 f_init();
2746 f_init_l1ctl();
2747 f_l1_tune(L1CTL);
2748
2749 var GsmFrameNumber fn_last := 0;
2750 for (var integer i := 0; i < 1000; i := i+1) {
2751 var OCT1 ra := f_rnd_ra_ps();
2752 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2753 if (fn == fn_last) {
2754 setverdict(fail, "Two RACH in same FN?!?");
2755 self.stop;
2756 }
2757 fn_last := fn;
2758
2759 timer T := 2.0;
2760 T.start;
2761 alt {
2762 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2763 T.stop;
2764 }
2765 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2766 setverdict(fail, "Unexpected RACH IND");
2767 self.stop;
2768 }
2769 [] PCU.receive { repeat; }
2770 [] T.timeout {
2771 setverdict(fail, "Timeout waiting for RACH IND");
2772 self.stop;
2773 }
2774 }
2775 }
2776 setverdict(pass);
2777}
2778
2779private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2780 var integer strlen := lengthof(str);
2781 for (var integer i := 0; i < len-strlen; i := i+1) {
2782 str := str & pad;
2783 }
2784 return str;
2785}
2786
2787/* Send PAGING via RSL, expect it to shw up on PCU socket */
2788testcase TC_pcu_paging_from_rsl() runs on test_CT {
2789 f_init();
2790
2791 for (var integer i := 0; i < 100; i := i+1) {
2792 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2793 timer T := 3.0;
2794 if (i < 50) {
2795 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2796 } else {
2797 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2798 }
2799 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2800 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2801 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2802
2803 /* Send RSL PAGING COMMAND */
2804 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2805 T.start;
2806 alt {
2807 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2808 }
2809 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2810 setverdict(fail, "Unexpected PAGING REQ");
2811 self.stop;
2812 }
2813 [] PCU.receive { repeat; }
2814 [] T.timeout {
2815 setverdict(fail, "Timeout waiting for PAGING REQ");
2816 self.stop;
2817 }
2818 }
2819 }
2820 setverdict(pass);
2821}
2822
Harald Welte3d04ae62018-04-04 20:29:05 +02002823/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002824 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002825 ***********************************************************************/
2826
2827private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2828runs on ConnHdlr {
2829 var PCUIF_send_data sd;
2830 /* Expect BTS to immediately acknowledge activation as PDCH */
2831 PCU.clear;
2832 f_rsl_chan_act(g_pars.chan_mode);
2833 /* expect INFO_IND on PCU interface listing TS as PDCH */
2834 alt {
2835 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2836 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2837 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2838 self.stop;
2839 }
2840 }
2841 [] PCU.receive { repeat; }
2842 }
2843 /* try to activate this PDCH from the PCU point of view */
2844 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2845 /* FIXME: is there a response? */
2846}
2847
2848private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2849runs on ConnHdlr {
2850 var PCUIF_send_data sd;
2851 /* Send RSL CHAN REL (deactivate) */
2852 PCU.clear;
2853 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2854 /* expect BTS to ask PCU to deactivate the channel */
2855 alt {
2856 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2857 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2858 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2859 self.stop;
2860 }
2861 }
2862 [] PCU.receive { repeat; }
2863 }
2864 /* Emulate PCU asking BTS to deactivate PDCH */
2865 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2866 alt {
2867 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2868 setverdict(pass);
2869 }
2870 [] RSL.receive { repeat; }
2871 }
2872}
2873
2874/* Activate Osmocom-style dynamic PDCH from BSC side */
2875function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2876 var PCUIF_Message first_info;
2877 var integer ts_nr := g_chan_nr.tn;
2878 var integer trx_nr := 0;
2879 var integer bts_nr := 0;
2880 var integer pcu_conn_id := -1;
2881
2882 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2883
2884 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2885 f_sleep(3.0);
2886 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2887 setverdict(pass);
2888}
2889testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2890 var ConnHdlrPars pars;
2891 var ConnHdlr vc_conn;
2892 f_init(testcasename());
2893
2894 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2895 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2896 vc_conn.done;
2897}
2898
2899/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2900function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2901 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002902 var integer pcu_conn_id := -1;
2903
2904 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2905
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002906 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2907 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2908 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002909 setverdict(pass);
2910}
2911testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2912 var ConnHdlrPars pars;
2913 var ConnHdlr vc_conn;
2914 f_init(testcasename());
2915
2916 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2917 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2918 vc_conn.done;
2919}
2920
2921/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2922function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2923 var PCUIF_Message first_info;
2924 var integer ts_nr := g_chan_nr.tn;
2925 var integer trx_nr := 0;
2926 var integer bts_nr := 0;
2927 var integer pcu_conn_id := -1;
2928
2929 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2930
2931 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002932 /* Send a second Chan Activ and expect it to be NACKed */
2933 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2934 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002935 setverdict(pass);
2936}
2937testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2938 var ConnHdlrPars pars;
2939 var ConnHdlr vc_conn;
2940 f_init(testcasename());
2941
2942 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2943 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2944 vc_conn.done;
2945}
2946
2947/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2948function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2949 var PCUIF_Message first_info;
2950 var integer ts_nr := g_chan_nr.tn;
2951 var integer trx_nr := 0;
2952 var integer bts_nr := 0;
2953 var integer pcu_conn_id := -1;
2954 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2955
2956 /* register for the TCH/F channel number */
2957 f_rslem_register(0, chan_nr);
2958
2959 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2960
2961 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2962 "RSL CHAN ACT");
2963 setverdict(pass);
2964}
2965testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2966 var ConnHdlrPars pars;
2967 var ConnHdlr vc_conn;
2968 f_init(testcasename());
2969
2970 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2971 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2972 vc_conn.done;
2973}
2974
2975/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2976function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2977 var PCUIF_Message first_info;
2978 var integer ts_nr := g_chan_nr.tn;
2979 var integer trx_nr := 0;
2980 var integer bts_nr := 0;
2981 var integer pcu_conn_id := -1;
2982 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2983 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2984
2985 /* register for the TCH/H channel numbers */
2986 f_rslem_register(0, chan_nr[0]);
2987 f_rslem_register(0, chan_nr[1]);
2988
2989 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2990
2991 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2992 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2993 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2994 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2995 setverdict(pass);
2996}
2997testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
2998 var ConnHdlrPars pars;
2999 var ConnHdlr vc_conn;
3000 f_init(testcasename());
3001
3002 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3003 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3004 vc_conn.done;
3005}
3006
Harald Welte9bbbfb52018-04-05 09:33:19 +02003007/***********************************************************************
3008 * IPA Style Dynamic Timeslot Support
3009 ***********************************************************************/
3010
3011private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3012runs on ConnHdlr {
3013 var PCUIF_send_data sd;
3014 /* Expect BTS to immediately acknowledge activation as PDCH */
3015 PCU.clear;
3016 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3017 /* expect INFO_IND on PCU interface listing TS as PDCH */
3018 alt {
3019 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3020 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
3021 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
3022 self.stop;
3023 }
3024 }
3025 [] PCU.receive { repeat; }
3026 }
3027 /* try to activate this PDCH from the PCU point of view */
3028 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3029 /* FIXME: is there a response? */
3030
3031 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3032}
3033
3034private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3035runs on ConnHdlr {
3036 var PCUIF_send_data sd;
3037 /* Send RSL CHAN REL (deactivate) */
3038 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3039 PCU.clear;
3040 /* expect BTS to ask PCU to deactivate the channel */
3041 alt {
3042 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3043 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
3044 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
3045 self.stop;
3046 }
3047 }
3048 [] PCU.receive { repeat; }
3049 }
3050 /* Emulate PCU asking BTS to deactivate PDCH */
3051 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3052 alt {
3053 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3054 setverdict(pass);
3055 }
3056 [] RSL.receive { repeat; }
3057 }
3058}
3059
3060/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3061function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3062 var PCUIF_Message first_info;
3063 var integer ts_nr := g_chan_nr.tn;
3064 var integer trx_nr := 0;
3065 var integer bts_nr := 0;
3066 var integer pcu_conn_id := -1;
3067
3068 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3069
3070 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3071 f_sleep(3.0);
3072 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3073
3074 setverdict(pass);
3075
3076}
3077testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3078 var ConnHdlrPars pars;
3079 var ConnHdlr vc_conn;
3080 f_init();
3081
3082 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3083 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3084 vc_conn.done;
3085}
3086
3087/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3088function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3089 var PCUIF_Message first_info;
3090 var integer ts_nr := g_chan_nr.tn;
3091 var integer trx_nr := 0;
3092 var integer bts_nr := 0;
3093 var integer pcu_conn_id := -1;
3094
3095 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3096
3097 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3098 "RSL CHAN ACT");
3099 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3100 "RF CHAN REL", true);
3101 setverdict(pass);
3102}
3103testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3104 var ConnHdlrPars pars;
3105 var ConnHdlr vc_conn;
3106 f_init(testcasename());
3107
3108 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3109 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3110 vc_conn.done;
3111}
3112
3113/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3114function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3115 var PCUIF_Message first_info;
3116 var integer ts_nr := g_chan_nr.tn;
3117 var integer trx_nr := 0;
3118 var integer bts_nr := 0;
3119 var integer pcu_conn_id := -1;
3120
3121 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3122
3123 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3124 "RSL CHAN ACT");
3125
3126 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3127 alt {
3128 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3129 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
3130 setverdict(fail, "Unexpected PDCH ACT ACK");
3131 self.stop;
3132 }
3133 [] RSL.receive { repeat; }
3134 }
3135
3136 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3137 "RF CHAN REL", true);
3138 setverdict(pass);
3139}
3140testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3141 var ConnHdlrPars pars;
3142 var ConnHdlr vc_conn;
3143 f_init(testcasename());
3144
3145 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3146 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3147 vc_conn.done;
3148}
3149
3150/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3151function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3152 var PCUIF_Message first_info;
3153 var integer ts_nr := g_chan_nr.tn;
3154 var integer trx_nr := 0;
3155 var integer bts_nr := 0;
3156 var integer pcu_conn_id := -1;
3157
3158 /* register for the TCH/F channel number */
3159 f_rslem_register(0, g_chan_nr);
3160
3161 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3162
3163 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3164
3165 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3166 "RSL CHAN ACT");
3167
3168 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3169
3170 setverdict(pass);
3171}
3172testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3173 var ConnHdlrPars pars;
3174 var ConnHdlr vc_conn;
3175 f_init(testcasename());
3176
3177 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3178 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3179 vc_conn.done;
3180}
3181
3182
Harald Welte0472ab42018-03-12 15:02:26 +01003183/***********************************************************************
3184 * LAPDm / RLL related
3185 ***********************************************************************/
3186
3187private function f_tx_lapdm(template (value) LapdmFrame l,
3188 template (value) RslLinkId link_id) runs on ConnHdlr {
3189 var octetstring l2 := enc_LapdmFrame(valueof(l));
3190 if (valueof(link_id.c) == SACCH) {
3191 /* prepend dummy L1 header */
3192 l2 := '0000'O & l2;
3193 }
3194 log("encoding ", l, " to ", l2);
3195 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3196}
3197
3198type record RllTestCase {
3199 uint3_t sapi,
3200 RslLinkId link_id,
3201 octetstring l3,
3202 boolean exp
3203}
3204type record of RllTestCase RllTestCases;
3205template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3206 sapi := sapi,
3207 link_id := id,
3208 l3 := l3,
3209 exp := exp
3210}
3211
3212/* execute the same callback function with a set of different parameters (tcs) on a
3213 * variety of logical channels */
3214private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3215 var ConnHdlrPars pars;
3216 var ConnHdlr vc_conn;
3217 f_init(testcasename());
3218
3219 /* test on each of the channels we have */
3220 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3221 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3222
3223 /* test each of the test cases on the current channel */
3224 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3225 pars.spec.rll := tcs[j];
3226 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3227 vc_conn := f_start_handler(fn, pars);
3228 vc_conn.done;
3229 }
3230 }
3231
3232 f_shutdown();
3233}
3234
3235/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3236private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3237 var RllTestCase tc := g_pars.spec.rll;
3238 timer T := 3.0;
3239
3240 f_l1_tune(L1CTL);
3241 RSL.clear;
3242
3243 /* activate the logical channel */
3244 f_est_dchan();
3245 L1CTL.clear;
3246
3247 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3248 T.start;
3249 alt {
3250 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3251 if (tc.exp) {
3252 setverdict(pass);
3253 } else {
3254 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3255 }
3256 }
3257 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3258 if (tc.exp) {
3259 setverdict(pass);
3260 } else {
3261 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3262 }
3263 }
3264 [tc.exp] T.timeout {
3265 setverdict(fail, "Timeout waiting for EST IND");
3266 }
3267 [not tc.exp] T.timeout {
3268 setverdict(pass);
3269 }
3270 }
3271
3272 f_rsl_chan_deact();
3273 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3274 f_rslem_unregister(0, g_chan_nr);
3275}
3276testcase TC_rll_est_ind() runs on test_CT {
3277 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003278 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003279 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003280 /* normal SAPI0 establishment */
3281 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003282 /* SAPI 3 doesn't support contention resolution */
3283 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3284 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3285 /* normal SAPI3 establishment on main DCCH */
3286 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3287 /* normal SAPI3 establishment on SACCH */
3288 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3289 };
3290 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3291}
3292
3293/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3294private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3295 var RllTestCase tc := g_pars.spec.rll;
3296 var L1ctlDlMessage dl;
3297 timer T := 3.0;
3298
3299 f_l1_tune(L1CTL);
3300 RSL.clear;
3301
3302 /* activate the logical channel */
3303 f_est_dchan();
3304 L1CTL.clear;
3305
3306 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3307 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3308 T.start;
3309 alt {
3310 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3311 var LapdmFrame lapdm;
3312 var octetstring l2 := dl.payload.data_ind.payload;
3313 if (dl.dl_info.link_id.c == SACCH) {
3314 /* remove L1 header */
3315 l2 := substr(l2, 2, lengthof(l2)-2);
3316 }
3317 lapdm.ab := dec_LapdmFrameAB(l2);
3318 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3319 setverdict(pass);
3320 } else {
3321 repeat;
3322 }
3323 }
3324 [] L1CTL.receive { repeat; }
3325 [] T.timeout {
3326 setverdict(fail, "Timeout waiting for SABM");
3327 self.stop;
3328 }
3329 }
3330
3331 f_rsl_chan_deact();
3332 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3333 f_rslem_unregister(0, g_chan_nr);
3334}
3335testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3336 var RllTestCases tcs := {
3337 /* normal SAPI3 establishment on main DCCH */
3338 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3339 };
3340 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3341}
3342testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3343 var RllTestCases tcs := {
3344 /* normal SAPI3 establishment on SACCH */
3345 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3346 }
3347 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3348}
3349
3350/* altstep to receive a LAPDm frame matching the given template */
3351private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3352 var L1ctlDlMessage dl;
3353 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3354 var LapdmFrame lapdm;
3355 var octetstring l2 := dl.payload.data_ind.payload;
3356 if (dl.dl_info.link_id.c == SACCH) {
3357 /* remove L1 header */
3358 l2 := substr(l2, 2, lengthof(l2)-2);
3359 }
3360 if (ischosen(exp.ab)) {
3361 lapdm.ab := dec_LapdmFrameAB(l2);
3362 } else if (ischosen(exp.b4)) {
3363 lapdm.b4 := dec_LapdmFrameB4(l2);
3364 } else if (ischosen(exp.bbis)) {
3365 lapdm.bbis := dec_LapdmFrameBbis(l2);
3366 }
3367 log("Rx LAPDm ", lapdm);
3368 if (match(lapdm, exp)) {
3369 setverdict(pass);
3370 } else {
3371 repeat;
3372 }
3373 }
3374 [] L1CTL.receive { repeat; }
3375}
3376private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3377 timer T := t;
3378 T.start;
3379 alt {
3380 [] T.timeout {
3381 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3382 self.stop;
3383 }
3384 [] as_l1_exp_lapdm(exp);
3385 }
3386}
3387
3388/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3389private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3390 /* send SABM from MS -> BTS */
3391 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3392 /* expect RLL EST IND on Abis */
3393 alt {
3394 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3395 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3396 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3397 setverdict(fail, "Failing due to RSL_ERROR_IND");
3398 self.stop;
3399 }
3400 [] RSL.receive { repeat; }
3401 }
3402 /* expect UA from BTS -> MS */
3403 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3404}
3405
3406/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3407private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3408 var RllTestCase tc := g_pars.spec.rll;
3409
3410 f_l1_tune(L1CTL);
3411 RSL.clear;
3412
3413 /* activate the logical channel */
3414 f_est_dchan();
3415 L1CTL.clear;
3416
3417 /* first establish the link-layer */
3418 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3419
3420 /* then send the DISC */
3421 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3422 /* ... and expect the REL IND on the RSL side */
3423 alt {
3424 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3425 setverdict(pass);
3426 }
3427 }
3428
3429 /* release the channel */
3430 f_rsl_chan_deact();
3431 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3432 f_rslem_unregister(0, g_chan_nr);
3433}
3434testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3435 var RllTestCases tcs := {
3436 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3437 };
3438 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3439}
3440
3441testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3442 var RllTestCases tcs := {
3443 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3444 };
3445 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3446}
3447testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3448 var RllTestCases tcs := {
3449 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3450 };
3451 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3452}
3453testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3454 var RllTestCases tcs := {
3455 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3456 };
3457 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3458}
3459
3460/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3461private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3462 var RllTestCase tc := g_pars.spec.rll;
3463 f_l1_tune(L1CTL);
3464 RSL.clear;
3465
3466 /* activate the logical channel */
3467 f_est_dchan();
3468 L1CTL.clear;
3469
3470 /* first establish the link-layer */
3471 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3472
3473 /* then send the REL REQ via RSL */
3474 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3475 /* ... and expect the DISC on the Um side */
3476 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003477 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003478 /* FIXME: send a UA in resposne to the DISC */
3479 }
3480 }
3481
3482 /* release the channel */
3483 f_rsl_chan_deact();
3484 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3485 f_rslem_unregister(0, g_chan_nr);
3486}
3487testcase TC_rll_rel_req() runs on test_CT {
3488 var RllTestCases tcs := {
3489 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3490 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3491 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3492 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3493 };
3494 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3495}
3496
3497/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3498testcase TC_rll_data_req() runs on test_CT {
3499}
3500
3501/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3502testcase TC_rll_data_ind() runs on test_CT {
3503}
3504
3505/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3506private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3507 var RllTestCase tc := g_pars.spec.rll;
3508
3509 f_l1_tune(L1CTL);
3510 RSL.clear;
3511
3512 f_est_dchan();
3513 L1CTL.clear;
3514
3515 /* Send UNITDATA REQ on RSL side */
3516 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3517 /* Expect it to arrive on the other side */
3518 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003519 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003520 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003521 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003522 }
3523
3524 /* release the channel */
3525 f_rsl_chan_deact();
3526 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3527 f_rslem_unregister(0, g_chan_nr);
3528}
3529testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3530 var octetstring l3 := f_rnd_octstring(15);
3531 var RllTestCases tcs := {
3532 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3533 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3534 };
3535 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3536}
3537testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3538 var octetstring l3 := f_rnd_octstring(19);
3539 var RllTestCases tcs := {
3540 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3541 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3542 };
3543 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3544}
3545
3546/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3547private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3548 var RllTestCase tc := g_pars.spec.rll;
3549
3550 f_l1_tune(L1CTL);
3551 RSL.clear;
3552
3553 f_est_dchan();
3554 L1CTL.clear;
3555
3556 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003557 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003558 /* Expdct RLL UNITDATA IND on RSL side */
3559 alt {
3560 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3561 setverdict(pass);
3562 }
3563 [] RSL.receive { repeat; }
3564 }
3565
3566 /* release the channel */
3567 f_rsl_chan_deact();
3568 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3569 f_rslem_unregister(0, g_chan_nr);
3570}
3571testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3572 var octetstring l3 := f_rnd_octstring(15);
3573 var RllTestCases tcs := {
3574 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3575 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3576 };
3577 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3578}
3579testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3580 var octetstring l3 := f_rnd_octstring(18);
3581 var RllTestCases tcs := {
3582 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3583 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3584 };
3585 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3586}
3587
Harald Weltee613f962018-04-18 22:38:16 +02003588/***********************************************************************
3589 * Encryption Related
3590 ***********************************************************************/
3591
3592/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3593function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3594 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3595 if (link_id.c == SACCH) {
3596 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3597 } else {
3598 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3599 }
3600}
3601
3602/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3603function f_unitdata_mo(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3604 timer T := 3.0;
3605 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3606 T.start;
3607 /* Expect RLL UNITDATA IND on RSL side */
3608 alt {
3609 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3610 setverdict(pass);
3611 }
3612 [] T.timeout {
3613 setverdict(fail, "Timeout waiting for UNIT_DATA_IND");
3614 }
3615 [] RSL.receive { repeat; }
3616 }
3617}
3618
3619/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3620function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3621 f_l1_tune(L1CTL);
3622 f_est_dchan(true);
3623
3624 /* now we actually need to transmit some data both ways to check if the encryption works */
3625 var L1ctlDlMessage dl;
3626
3627 var octetstring l3 := f_rnd_octstring(16);
3628 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3629
3630 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3631 f_unitdata_mt(link_id, l3);
3632
3633 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3634 f_unitdata_mo(link_id, l3);
3635
3636 /* release the channel */
3637 f_rsl_chan_deact();
3638 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3639 f_rslem_unregister(0, g_chan_nr);
3640}
3641testcase TC_chan_act_a51() runs on test_CT {
3642 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3643 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3644 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3645}
3646testcase TC_chan_act_a52() runs on test_CT {
3647 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3648 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3649 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3650}
3651testcase TC_chan_act_a53() runs on test_CT {
3652 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3653 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3654 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3655}
3656
3657
3658/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3659function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3660 /* L3 payload doesn't matter, as it is passed transparently */
3661 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3662 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3663 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3664
3665 f_l1_tune(L1CTL);
3666
3667 /* first establish a dedicated channel in the clear */
3668 f_est_dchan(false);
3669
3670 /* Establish ABM */
3671 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3672
3673 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3674 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3675 /* expect the L3 to arrive still unencrypted on the MS side */
3676 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3677
3678 /* configure L1 to apply ciphering */
3679 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3680 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3681
3682 /* send first ciphered I-frame in response */
3683 l3 := '0a0b0c0d'O;
3684 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3685 RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3));
3686
3687 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3688 * and hence enable encryption also on the downlink */
3689
3690 /* expect bi-directional communication work in encrypted mode */
3691 f_unitdata_mo(link_id, f_rnd_octstring(15));
3692 f_unitdata_mt(link_id, f_rnd_octstring(15));
3693
3694 /* release the channel */
3695 f_rsl_chan_deact();
3696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3697 f_rslem_unregister(0, g_chan_nr);
3698}
3699testcase TC_encr_cmd_a51() runs on test_CT {
3700 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3701 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3702 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3703}
3704testcase TC_encr_cmd_a52() runs on test_CT {
3705 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3706 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3707 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3708}
3709testcase TC_encr_cmd_a53() runs on test_CT {
3710 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3711 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3712 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3713}
3714
3715private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3716 var LapdmFrame lf;
3717 var octetstring reenc;
3718
3719 /* decode the LAPDm frame */
3720 if (ischosen(exp_match.ab)) {
3721 lf.ab := dec_LapdmFrameAB(enc);
3722 } else {
3723 setverdict(fail, "unsupported frame type");
3724 self.stop;
3725 }
3726
3727 /* check if decoder result matches expectation */
3728 if (not match(lf, exp_match)) {
3729 setverdict(fail, name, ": decoded LAPDm doesn't match");
3730 } else {
3731 log(name, ": matched");
3732 setverdict(pass);
3733 }
3734
3735 /* test if re-encoded frame equals original input */
3736 reenc := enc_LapdmFrame(lf);
3737 if (enc != reenc) {
3738 setverdict(fail, name, ": re-encoded LAPDm frame doesn't match");
3739 } else {
3740 setverdict(pass);
3741 }
3742}
3743
3744testcase TC_lapdm_selftest() runs on test_CT {
3745 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3746 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3747 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3748 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3749 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3750 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3751 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3752}
3753
Harald Welte0472ab42018-03-12 15:02:26 +01003754
3755/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3756/* protocol error as per 44.006 */
3757/* link layer failure (repetition of I-frame N200 times without ACK */
3758/* repetition of SABM or DISC N200 times without ACK */
3759/* receptiom of SABM in multi-frame established state */
3760
3761
3762
3763
Harald Welte883340c2018-02-28 18:59:29 +01003764
Harald Welte68e495b2018-02-25 00:05:57 +01003765/* TODO Areas:
3766
3767* channel activation
3768** with BS_Power / MS_Power, bypassing power control loop
3769** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01003770** with timing advance from initial activation on
3771* mode modify
3772** encryption
3773** multirate
3774* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01003775** unsupported algorithm
3776* handover detection
3777* MS Power Control
3778* BS Power Control
3779* Physical Context
3780* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003781* CCCH Load Indication for PCH and RACH
3782* Delete Indication on AGCH overflow
3783* SMS Broadcast Req / Cmd / CBCH LOad Ind
3784* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003785* error handling
3786* discriminator error
3787** type error
3788** sequence error
3789** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003790* PCU interface
3791** TIME_IND from BTS->PCU
3792** DATA_IND from BTS->PCU
3793** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003794
3795*/
Harald Welte70767382018-02-21 12:16:40 +01003796
3797control {
3798 execute( TC_chan_act_stress() );
3799 execute( TC_chan_act_react() );
3800 execute( TC_chan_deact_not_active() );
3801 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003802 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003803 execute( TC_sacch_filling() );
3804 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003805 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003806 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003807 execute( TC_rach_content() );
3808 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003809 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003810 execute( TC_meas_res_sign_tchf() );
3811 execute( TC_meas_res_sign_tchh() );
3812 execute( TC_meas_res_sign_sdcch4() );
3813 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003814 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003815 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003816 execute( TC_paging_imsi_80percent() );
3817 execute( TC_paging_tmsi_80percent() );
3818 execute( TC_paging_imsi_200percent() );
3819 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003820 execute( TC_rsl_protocol_error() );
3821 execute( TC_rsl_mand_ie_error() );
3822 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003823 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003824 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003825 execute( TC_si_sched_2bis() );
3826 execute( TC_si_sched_2ter() );
3827 execute( TC_si_sched_2ter_2bis() );
3828 execute( TC_si_sched_2quater() );
3829 execute( TC_si_sched_13() );
3830 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003831 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003832 execute( TC_ipa_crcx_twice_not_active() );
3833 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003834 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003835 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003836
3837 execute( TC_pcu_act_req() );
3838 execute( TC_pcu_act_req_wrong_ts() );
3839 execute( TC_pcu_act_req_wrong_bts() );
3840 execute( TC_pcu_act_req_wrong_trx() );
3841 execute( TC_pcu_deact_req() );
3842 execute( TC_pcu_deact_req_wrong_ts() );
3843 execute( TC_pcu_ver_si13() );
3844 execute( TC_pcu_data_req_wrong_bts() );
3845 execute( TC_pcu_data_req_wrong_trx() );
3846 execute( TC_pcu_data_req_wrong_ts() );
3847 execute( TC_pcu_data_req_ts_inactive() );
3848 execute( TC_pcu_data_req_pdtch() );
3849 execute( TC_pcu_data_req_ptcch() );
3850 execute( TC_pcu_data_req_agch() );
3851 execute( TC_pcu_data_req_imm_ass_pch() );
3852 execute( TC_pcu_rach_content() );
3853 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003854
3855 execute( TC_dyn_osmo_pdch_act_deact() );
3856 execute( TC_dyn_osmo_pdch_unsol_deact() );
3857 execute( TC_dyn_osmo_pdch_double_act() );
3858 execute( TC_dyn_osmo_pdch_tchf_act() );
3859 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003860 execute( TC_dyn_ipa_pdch_act_deact() );
3861 execute( TC_dyn_ipa_pdch_tchf_act() );
3862 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3863 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003864
3865 execute( TC_rll_est_ind() );
3866 execute( TC_rll_est_req_DCCH_3() );
3867 execute( TC_rll_est_req_ACCH_3() );
3868 execute( TC_rll_rel_ind_DCCH_0() );
3869 execute( TC_rll_rel_ind_DCCH_3() );
3870 execute( TC_rll_rel_ind_ACCH_0() );
3871 execute( TC_rll_rel_ind_ACCH_3() );
3872 execute( TC_rll_rel_req() );
3873 execute( TC_rll_unit_data_req_DCCH() );
3874 execute( TC_rll_unit_data_req_ACCH() );
3875 execute( TC_rll_unit_data_ind_DCCH() );
3876 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02003877
3878 execute( TC_chan_act_a51() );
3879 execute( TC_chan_act_a52() );
3880 execute( TC_chan_act_a53() );
3881 execute( TC_encr_cmd_a51() );
3882 execute( TC_encr_cmd_a52() );
3883 execute( TC_encr_cmd_a53() );
3884
3885 execute( TC_lapdm_selftest() );
Harald Welte70767382018-02-21 12:16:40 +01003886}
3887
3888
3889}