blob: 10447477d61a5eeb05135c871c309b058729f5fa [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 {
344 /* shut down all "externally interfaced" components first to avoid unclean shutdown */
345 vc_IPA.stop;
346 vc_RSL.stop;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200347 f_ipa_ctrl_stop();
Harald Welte294b0a22018-03-10 23:26:48 +0100348}
349
Harald Welte68e495b2018-02-25 00:05:57 +0100350/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
351function f_init_l1ctl() runs on test_CT {
352 map(self:L1CTL, system:L1CTL);
353 f_connect_reset(L1CTL);
354}
355
Harald Welte70767382018-02-21 12:16:40 +0100356type function void_fn(charstring id) runs on ConnHdlr;
357
358/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200359function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100360runs on test_CT return ConnHdlr {
361 var charstring id := testcasename();
362 var ConnHdlr vc_conn;
363
364 vc_conn := ConnHdlr.create(id);
365 /* connect to RSL Emulation main component */
366 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
367 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200368 if (pcu_comp) {
369 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
370 * it from the test_CT and connect it to the component. This obviously only
371 * works for one component, i.e. no concurrency */
372 unmap(self:PCU, system:PCU);
373 map(vc_conn:PCU, system:PCU);
374 }
Harald Welte70767382018-02-21 12:16:40 +0100375
376 vc_conn.start(f_handler_init(fn, id, pars));
377 return vc_conn;
378}
379
Harald Welte7484fc42018-02-24 14:09:45 +0100380template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
381 streamId := sid,
382 rsl := rsl
383}
384
385template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
386 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
387 streamId := sid,
388 rsl := rsl
389}
390
Harald Welte70767382018-02-21 12:16:40 +0100391private altstep as_Tguard() runs on ConnHdlr {
392 [] g_Tguard.timeout {
393 setverdict(fail, "Tguard timeout");
394 self.stop;
395 }
396}
397
Harald Welte68e495b2018-02-25 00:05:57 +0100398private function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200399 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100400}
401
402private function f_trxc_connect() runs on ConnHdlr {
403 map(self:BB_TRXC, system:BB_TRXC);
404 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100405 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
406 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200407 if (not ispresent(res.connId)) {
408 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
409 self.stop;
410 }
Harald Welte70767382018-02-21 12:16:40 +0100411 g_bb_trxc_conn_id := res.connId;
412}
413
414private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100415 var TrxcMessage ret;
416 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100417}
418
419private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100420 var TrxcMessage ret;
421 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100422}
423
424/* first function started in ConnHdlr component */
425private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
426runs on ConnHdlr {
427 g_pars := pars;
428 g_chan_nr := pars.chan_nr;
429
430 map(self:L1CTL, system:L1CTL);
431 f_connect_reset(L1CTL);
432
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_bb_trxc_port != -1) {
434 f_trxc_connect();
435 }
Harald Welte70767382018-02-21 12:16:40 +0100436
437 g_Tguard.start(pars.t_guard);
438 activate(as_Tguard());
439
440 f_rslem_register(0, pars.chan_nr);
441
442 /* call the user-supplied test case function */
443 fn.apply(id);
444}
445
Harald Welteb1726c92018-03-30 11:56:38 +0200446function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
447 boolean ignore_other := false)
448runs on ConnHdlr return RSL_Message {
449 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100450 timer T := 3.0;
451 RSL.send(tx);
452 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100453 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200454 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100455 T.stop;
456 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100457 }
Harald Welte1eba3742018-02-25 12:48:14 +0100458 [] T.timeout {
459 setverdict(fail, "Timeout expecting " & id);
460 self.stop;
461 }
Harald Welte21240e62018-03-11 21:43:35 +0100462 [not ignore_other] as_l1_sacch();
463 [not ignore_other] as_meas_res();
464 [not ignore_other] as_l1_dcch();
465 [not ignore_other] RSL.receive {
Harald Welte1eba3742018-02-25 12:48:14 +0100466 setverdict(fail, "Unexpected RSL message received");
Harald Welteb1726c92018-03-30 11:56:38 +0200467 self.stop;
Harald Welte70767382018-02-21 12:16:40 +0100468 }
Harald Welte21240e62018-03-11 21:43:35 +0100469 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100470 }
Harald Welteb1726c92018-03-30 11:56:38 +0200471 return rx;
472}
473
474function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
475 boolean ignore_other := false)
476runs on ConnHdlr {
477 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100478}
479
Harald Weltee613f962018-04-18 22:38:16 +0200480function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false)
481runs on ConnHdlr {
482 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
483 if (encr_enable) {
484 /* append encryption related IEs, if requested */
485 var RSL_IE_EncryptionInfo encr_info;
486 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
487 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
488encr_info})) };
489 }
490 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100491}
492
Harald Welte70767382018-02-21 12:16:40 +0100493function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100494 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 +0100495 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100496}
497
Harald Welte70767382018-02-21 12:16:40 +0100498private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
499 template RSL_IE_ChannelMode chan_mode,
500 float t_guard := 20.0) := {
501 chan_nr := valueof(chan_nr),
502 chan_mode := valueof(chan_mode),
503 t_guard := t_guard,
504 l1_pars := {
505 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100506 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100507 meas_ul := {
508 full := {
509 rxlev := dbm2rxlev(-53),
510 rxqual := 0
511 },
512 sub := {
513 rxlev := dbm2rxlev(-53),
514 rxqual := 0
515 }
516 },
517 timing_offset_256syms := 0,
518 bs_power_level := 0,
519 ms_power_level := 0,
520 ms_actual_ta := 0
Harald Welte0472ab42018-03-12 15:02:26 +0100521 },
Harald Weltee613f962018-04-18 22:38:16 +0200522 spec := omit,
523 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100524}
525
Harald Welte93640c62018-02-25 16:59:33 +0100526/***********************************************************************
527 * Channel Activation / Deactivation
528 ***********************************************************************/
529
Harald Welte70767382018-02-21 12:16:40 +0100530/* Stress test: Do 500 channel activations/deactivations in rapid succession */
531function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
532 for (var integer i := 0; i < 500; i := i+1) {
533 f_rsl_chan_act(g_pars.chan_mode);
534 f_rsl_chan_deact();
535 }
536 setverdict(pass);
537}
538testcase TC_chan_act_stress() runs on test_CT {
539 var ConnHdlr vc_conn;
540 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
541 f_init(testcasename());
542 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
543 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100544 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100545}
546
547/* Test if re-activation of an already active channel fails as expected */
548function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
549 f_rsl_chan_act(g_pars.chan_mode);
550 /* attempt to activate the same lchan again -> expect reject */
551 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
552 alt {
553 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
554 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
555 }
556 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
557 setverdict(pass);
558 }
559 }
560 f_rsl_chan_deact();
561}
562testcase TC_chan_act_react() runs on test_CT {
563 var ConnHdlr vc_conn;
564 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100565 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100566 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
567 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100568 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100569}
570
571/* Attempt to de-activate a channel that's not active */
572function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
573 timer T := 3.0;
574 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
575 T.start;
576 alt {
577 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
578 setverdict(pass);
579 }
580 [] T.timeout {
581 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
582 }
583 }
584}
585testcase TC_chan_deact_not_active() runs on test_CT {
586 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100587 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100588 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
589 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100590 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100591}
592
593/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
594function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
595 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
596 alt {
597 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
598 setverdict(fail, "Unexpected CHAN ACT ACK");
599 }
600 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
601 setverdict(pass);
602 }
603 }
604}
605private type record WrongChanNrCase {
606 RslChannelNr chan_nr,
607 charstring description
608}
609private type record of WrongChanNrCase WrongChanNrCases;
610private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
611 chan_nr := chan_nr,
612 description := desc
613}
614
615testcase TC_chan_act_wrong_nr() runs on test_CT {
616 var ConnHdlr vc_conn;
617 var ConnHdlrPars pars;
618
Harald Welte294b0a22018-03-10 23:26:48 +0100619 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100620
621 var WrongChanNrCases wrong := {
622 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
623 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
624 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
625 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
626 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
627 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
628 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
629 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
630 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
631 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
632 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
633 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
634 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
635 };
636
637 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
638 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
639 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
640 vc_conn.done;
641 }
Harald Welte294b0a22018-03-10 23:26:48 +0100642 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
Harald Weltee613f962018-04-18 22:38:16 +0200645/* execute the same callback function on a variety of logical channels */
646private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
647 var ConnHdlr vc_conn;
648 f_init(testcasename());
649
650 /* test on each of the channels we have */
651 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
652 pars.chan_nr := valueof(g_AllChanTypes[i]);
653
654 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
655 vc_conn := f_start_handler(fn, pars);
656 vc_conn.done;
657 }
658
659 f_shutdown();
660}
661
Harald Welte93640c62018-02-25 16:59:33 +0100662/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100663 * SACCH handling
664 ***********************************************************************/
665
666private function f_exp_sacch(boolean exp) runs on ConnHdlr {
667 timer T_sacch := 3.0;
668 T_sacch.start;
669 alt {
670 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
671 setverdict(fail, "Received SACCH when not expecting it");
672 }
673 [not exp] T_sacch.timeout {
674 setverdict(pass);
675 }
676 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
677 setverdict(pass);
678 }
679 [exp] T_sacch.timeout {
680 setverdict(fail, "Timeout waiting for SACCH on ", g_chan_nr);
681 }
682 [] L1CTL.receive { repeat; }
683 [] RSL.receive { repeat; }
684 }
685}
686
687/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
688private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
689 f_l1_tune(L1CTL);
690 RSL.clear;
691
692 /* activate the logical channel */
693 f_est_dchan();
694 L1CTL.clear;
695
696 /* check that SACCH actually are received as expected */
697 f_exp_sacch(true);
698
699 /* deactivate SACCH on the logical channel */
700 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
701 f_sleep(1.0);
702 L1CTL.clear;
703
704 /* check that no SACCH are received anymore */
705 f_exp_sacch(false);
706
707 /* release the channel */
708 f_rsl_chan_deact();
709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
710}
711testcase TC_deact_sacch() runs on test_CT {
712 var ConnHdlr vc_conn;
713 var ConnHdlrPars pars;
714 f_init();
715 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
716 //for (var integer i := 0; i < 1; i := i+1) {
717 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
718 log(testcasename(), ": Starting for ", g_AllChannels[i]);
719 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
720 vc_conn.done;
721 }
722 /* TODO: do the above in parallel, rather than sequentially? */
723 f_shutdown();
724}
725
Harald Welte55700662018-03-12 13:15:43 +0100726/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100727private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
728 var L1ctlDlMessage dl;
729 /* check that the specified SI5 value is actually sent */
730 timer T_sacch := 3.0;
731 L1CTL.clear;
732 T_sacch.start;
733 alt {
734 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
735 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
736 if (match(l3, l3_exp)) {
737 setverdict(pass);
738 } else {
739 repeat;
740 }
741 }
742 [] L1CTL.receive { repeat; }
743 [] T_sacch.timeout {
744 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
745 self.stop;
746 }
747 }
748}
749
Harald Welte55700662018-03-12 13:15:43 +0100750/* verify that given SACCH payload is not present */
751private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
752 var L1ctlDlMessage dl;
753 /* check that the specified SI5 value is actually sent */
754 timer T_sacch := 3.0;
755 L1CTL.clear;
756 T_sacch.start;
757 alt {
758 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
759 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
760 if (match(l3, l3_exp)) {
761 setverdict(fail, "Received unexpected SACCH ", dl);
762 self.stop;
763 } else {
764 repeat;
765 }
766 }
767 [] L1CTL.receive { repeat; }
768 [] T_sacch.timeout {
769 setverdict(pass);
770 }
771 }
772}
773
Harald Welte629cc6b2018-03-11 17:19:05 +0100774/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100775private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
776 /* Set a known default SACCH filling for SI5 */
777 var octetstring si5 := f_rnd_octstring(19);
778 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
779
780 f_l1_tune(L1CTL);
781 RSL.clear;
782
783 /* activate the logical channel */
784 f_est_dchan();
785
786 /* check that the specified SI5 value is actually sent */
787 f_sacch_present(si5);
788
789 /* release the channel */
790 RSL.clear;
791 f_rsl_chan_deact();
792 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
793}
794testcase TC_sacch_filling() runs on test_CT {
795 var ConnHdlr vc_conn;
796 var ConnHdlrPars pars;
797 f_init();
798 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
799 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
800 log(testcasename(), ": Starting for ", g_AllChannels[i]);
801 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
802 vc_conn.done;
803 }
804 /* TODO: do the above in parallel, rather than sequentially? */
805 f_shutdown();
806}
807
Harald Welte629cc6b2018-03-11 17:19:05 +0100808/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100809private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
810 /* Set a known default SACCH filling for SI5 */
811 var octetstring si5 := f_rnd_octstring(19);
812 var octetstring si5_diff := f_rnd_octstring(19);
813 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
814
815 f_l1_tune(L1CTL);
816 RSL.clear;
817
818 log("Activating channel, expecting standard SI5");
819 /* activate the logical channel */
820 f_est_dchan();
821 /* check that the specified SI5 value is actually sent */
822 f_sacch_present(si5);
823
824 /* set channel-specific different SI5 */
825 log("Setting channel specific SACCH INFO, expecting it");
826 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
827 /* check that the specified lchan-specific value is now used */
828 f_sacch_present(si5_diff);
829
830 /* deactivate the channel and re-activate it, this should result in default SI5 */
831 log("De-activating and re-activating channel, expecting standard SI5");
832 f_rsl_chan_deact();
833 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
834 /* Verify that the TRX-wide default SACCH filling is present again */
835 f_sacch_present(si5);
836
837 /* release the channel */
838 RSL.clear;
839 f_rsl_chan_deact();
840 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
841}
842testcase TC_sacch_info_mod() runs on test_CT {
843 var ConnHdlr vc_conn;
844 var ConnHdlrPars pars;
845 f_init();
846 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
847 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
848 log(testcasename(), ": Starting for ", g_AllChannels[i]);
849 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
850 vc_conn.done;
851 }
852 /* TODO: do the above in parallel, rather than sequentially? */
853 f_shutdown();
854}
855
Harald Welte075d84c2018-03-12 13:07:24 +0100856/* Test SACCH scheduling of multiple different SI message types */
857private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
858 var octetstring si5 := f_rnd_octstring(19);
859 var octetstring si5bis := f_rnd_octstring(19);
860 var octetstring si5ter := f_rnd_octstring(19);
861 var octetstring si6 := f_rnd_octstring(19);
862
863 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
864 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
865 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
866 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
867
868 f_l1_tune(L1CTL);
869 RSL.clear;
870
871 /* activate the logical channel */
872 f_est_dchan();
873 L1CTL.clear;
874
875 /* check that SACCH actually are received as expected */
876 f_sacch_present(si5);
877 f_sacch_present(si5bis);
878 f_sacch_present(si5ter);
879 f_sacch_present(si6);
880
881 /* release the channel */
882 f_rsl_chan_deact();
883 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
884}
885testcase TC_sacch_multi() runs on test_CT {
886 var ConnHdlr vc_conn;
887 var ConnHdlrPars pars;
888 f_init();
889 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
890 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
891 log(testcasename(), ": Starting for ", g_AllChannels[i]);
892 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
893 vc_conn.done;
894 }
895 /* TODO: do the above in parallel, rather than sequentially? */
896 f_shutdown();
897}
898
Harald Welte55700662018-03-12 13:15:43 +0100899/* Test if SACH information is modified as expected */
900private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
901 var octetstring si5 := f_rnd_octstring(19);
902 var octetstring si6 := f_rnd_octstring(19);
903
904 /* First, configure both SI5 and SI6 to be transmitted */
905 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
906 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
907
908 f_l1_tune(L1CTL);
909 RSL.clear;
910
911 /* activate the logical channel */
912 f_est_dchan();
913 L1CTL.clear;
914
915 /* check that SACCH actually are received as expected */
916 f_sacch_present(si5);
917 f_sacch_present(si6);
918
919 /* disable SI6 */
920 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
921
922 /* check that SI5 is still transmitted */
923 f_sacch_present(si5);
924 /* check if SI6 is now gone */
925 f_sacch_missing(si6);
926
927 /* release the channel */
928 f_rsl_chan_deact();
929 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
930}
931testcase TC_sacch_multi_chg() runs on test_CT {
932 var ConnHdlr vc_conn;
933 var ConnHdlrPars pars;
934 f_init();
935 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
936 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
937 log(testcasename(), ": Starting for ", g_AllChannels[i]);
938 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
939 vc_conn.done;
940 }
941 /* TODO: do the above in parallel, rather than sequentially? */
942 f_shutdown();
943}
944
Harald Welte075d84c2018-03-12 13:07:24 +0100945/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
946/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100947
948
949/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100950 * RACH Handling
951 ***********************************************************************/
952
Harald Welte8c24c2b2018-02-26 08:31:31 +0100953/* like L1SAP_IS_PACKET_RACH */
954private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100955 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100956 return true;
957 }
958 return false;
959}
960
961/* generate a random RACH for circuit-switched */
962private function f_rnd_ra_cs() return OCT1 {
963 var OCT1 ra;
964 do {
965 ra := f_rnd_octstring(1);
966 } while (ra_is_ps(ra));
967 return ra;
968}
969
Harald Welte883340c2018-02-28 18:59:29 +0100970/* generate a random RACH for packet-switched */
971private function f_rnd_ra_ps() return OCT1 {
972 var OCT1 ra;
973 do {
974 ra := f_rnd_octstring(1);
975 } while (not ra_is_ps(ra));
976 return ra;
977}
978
Harald Welte8c24c2b2018-02-26 08:31:31 +0100979/* Send 1000 RACH requests and check their RA+FN on the RSL side */
980testcase TC_rach_content() runs on test_CT {
981 f_init(testcasename());
982 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100983 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100984
Harald Welte8c24c2b2018-02-26 08:31:31 +0100985 var GsmFrameNumber fn_last := 0;
986 for (var integer i := 0; i < 1000; i := i+1) {
987 var OCT1 ra := f_rnd_ra_cs();
988 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
989 if (fn == fn_last) {
990 setverdict(fail, "Two RACH in same FN?!?");
991 self.stop;
992 }
993 fn_last := fn;
994
995 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100996 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100997 alt {
998 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
999 T.stop;
1000 }
1001 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
1002 setverdict(fail, "Unexpected CHAN RQD");
1003 self.stop;
1004 }
1005 [] RSL_CCHAN.receive { repeat; }
1006 [] T.timeout {
1007 setverdict(fail, "Timeout waiting for CHAN RQD");
1008 self.stop;
1009 }
1010 }
1011 }
1012 setverdict(pass);
Harald Welte294b0a22018-03-10 23:26:48 +01001013 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001014}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001015
1016/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1017testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001019 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001020 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001021 f_l1_tune(L1CTL);
1022
1023 var GsmFrameNumber fn_last := 0;
1024 for (var integer i := 0; i < 1000; i := i+1) {
1025 var OCT1 ra := f_rnd_ra_cs();
1026 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1027 if (fn == fn_last) {
1028 setverdict(fail, "Two RACH in same FN?!?");
1029 self.stop;
1030 }
1031 fn_last := fn;
1032 }
1033 var integer rsl_chrqd := 0;
1034 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001035 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001036 alt {
1037 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1038 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001039 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001040 repeat;
1041 }
1042 [] RSL_CCHAN.receive { repeat; }
1043 [] T.timeout { }
1044 }
1045 if (rsl_chrqd == 1000) {
1046 setverdict(pass);
1047 } else {
1048 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
1049 }
Harald Welte294b0a22018-03-10 23:26:48 +01001050 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001051}
1052
Harald Welte54a2a2d2018-02-26 09:14:05 +01001053private function f_main_trxc_connect() runs on test_CT {
1054 map(self:BB_TRXC, system:BB_TRXC);
1055 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +01001056 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
1057 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001058 if (not ispresent(res.connId)) {
1059 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
1060 self.stop;
1061 }
Harald Welte54a2a2d2018-02-26 09:14:05 +01001062 g_bb_trxc_conn_id := res.connId;
1063}
1064
1065private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001066 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001067 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +01001068 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001069 f_sleep(0.5);
1070
1071 /* Transmit RACH request + wait for confirmation */
1072 var OCT1 ra := f_rnd_ra_cs();
1073 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1074
1075 /* Check for expected result */
1076 timer T := 1.5;
1077 T.start;
1078 alt {
1079 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1080 setverdict(pass);
1081 }
1082 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +01001083 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001084 }
1085 [] RSL_CCHAN.receive { repeat; }
1086 [not expect_pass] T.timeout {
1087 setverdict(pass);
1088 }
1089 [expect_pass] T.timeout {
1090 setverdict(fail, "Timeout waiting for CHAN RQD");
1091 }
1092 }
1093}
1094
1095/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1096testcase TC_rach_max_ta() runs on test_CT {
1097 f_init(testcasename());
1098 f_init_l1ctl();
1099 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001100 f_sleep(1.0);
1101
1102 /* default max-ta is 63 (full range of GSM timing advance */
1103
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001104 /* We allow early arrival up to 2 symbols */
1105 f_rach_toffs(-1*256, true);
1106 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001107 f_rach_toffs(-10*256, false);
1108
1109 /* 0 / 32 / 63 bits is legal / permitted */
1110 f_rach_toffs(0, true);
1111 f_rach_toffs(32*256, true);
1112 f_rach_toffs(63*256, true);
1113
1114 /* more than 63 bits is not legal / permitted */
1115 f_rach_toffs(64*256, false);
1116 f_rach_toffs(127*256, false);
Harald Welte294b0a22018-03-10 23:26:48 +01001117 f_shutdown();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001118}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001119
Harald Welte93640c62018-02-25 16:59:33 +01001120/***********************************************************************
1121 * Measurement Processing / Reporting
1122 ***********************************************************************/
1123
Harald Welte70767382018-02-21 12:16:40 +01001124template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1125 spare := '0'B,
1126 lpd := 0,
1127 sapi := sapi,
1128 c_r := c_r,
1129 ea := true
1130}
1131
Harald Welted879bd92018-03-12 15:01:23 +01001132template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001133 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001134 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001135 len := 0, /* overwritten */
1136 m := false,
1137 el := 1,
1138 payload := pl
1139}
1140
1141/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1142altstep as_l1_sacch() runs on ConnHdlr {
1143 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001144 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001145 log("SACCH received: ", l1_dl.payload.data_ind.payload);
1146 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001147 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001148 log("LAPDm: ", lb);
Harald Welted879bd92018-03-12 15:01:23 +01001149 var octetstring pl := '0000'O & enc_LapdmFrameAB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001150 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001151 repeat;
1152 }
1153}
1154
1155altstep as_l1_dcch() runs on ConnHdlr {
1156 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001157 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001158 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1159 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001160 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001161 repeat;
1162 }
1163}
1164
1165type record MeasElem {
1166 uint6_t rxlev,
1167 uint3_t rxqual
1168}
1169
1170type record MeasElemFS {
1171 MeasElem full,
1172 MeasElem sub
1173}
1174
1175type record ConnL1Pars {
1176 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001177 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001178 MeasElemFS meas_ul,
1179 int16_t timing_offset_256syms,
1180 uint5_t bs_power_level,
1181 uint5_t ms_power_level,
1182 uint8_t ms_actual_ta
1183}
1184
1185/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1186private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1187 return 63 + (toffs256s/256);
1188}
1189
Harald Welted5684392018-03-10 18:22:04 +01001190private function f_max(integer a, integer b) return integer {
1191 if (a > b) {
1192 return a;
1193 } else {
1194 return b;
1195 }
1196}
1197
1198private function f_min(integer a, integer b) return integer {
1199 if (a < b) {
1200 return a;
1201 } else {
1202 return b;
1203 }
1204}
1205
1206/* compute negative tolerance val-tolerance, ensure >= min */
1207private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1208 val := val - tolerance;
1209 return f_max(val, min);
1210}
1211
1212/* compute positive tolerance val+tolerance, ensure <= max */
1213private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1214 val := val + tolerance;
1215 return f_min(val, max);
1216}
1217
1218/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1219private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1220return template integer {
1221 var template integer ret;
1222 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1223 return ret;
1224}
1225
1226
Harald Welte70767382018-02-21 12:16:40 +01001227/* build a template for matching measurement results against */
1228private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1229 var ConnL1Pars l1p := g_pars.l1_pars;
1230 var template RSL_IE_UplinkMeas ul_meas := {
1231 len := 3,
1232 rfu := '0'B,
1233 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001234 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001235 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001236 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001237 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001238 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1239 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001240 supp_meas_info := omit
1241 };
Harald Welte685d5982018-02-27 20:42:05 +01001242 if (l1p.toa256_enabled) {
1243 ul_meas.len := 5;
1244 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
1245 }
Harald Welte70767382018-02-21 12:16:40 +01001246 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
1247 ul_meas.rxlev_f_u := ?;
1248 ul_meas.rxlev_s_u := ?;
1249 ul_meas.rxq_f_u := ?;
1250 ul_meas.rxq_s_u := ?;
1251 var template RSL_IE_BS_Power bs_power := {
1252 reserved := 0,
1253 epc := false,
1254 fpc := false,
1255 power_level := l1p.bs_power_level
1256 };
1257 var template RSL_IE_L1Info l1_info := {
1258 ms_power_lvl := l1p.ms_power_level,
1259 fpc := false,
1260 reserved := 0,
1261 actual_ta := l1p.ms_actual_ta
1262 };
1263 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
1264 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
1265 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1266 ?, t_toffs);
1267}
1268
1269/* verify we regularly receive measurement reports with incrementing numbers */
1270altstep as_meas_res() runs on ConnHdlr {
1271 var RSL_Message rsl;
1272 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1273 /* increment counter of next to-be-expected meas rep */
1274 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1275 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001276 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001277 repeat;
1278 }
1279 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001280 /* increment counter of next to-be-expected meas rep */
1281 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1282 if (g_first_meas_res) {
1283 g_first_meas_res := false;
1284 repeat;
1285 } else {
1286 setverdict(fail, "Received unspecific MEAS RES ", rsl);
1287 self.stop;
1288 }
Harald Welte70767382018-02-21 12:16:40 +01001289 }
1290 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
1291 setverdict(fail, "Received unexpected MEAS RES ", rsl);
1292 self.stop;
1293 }
1294 [] g_Tmeas_exp.timeout {
1295 setverdict(fail, "Didn't receive expected measurement result")
1296 self.stop;
1297 }
1298}
1299
Harald Weltee613f962018-04-18 22:38:16 +02001300private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1301 select (rsl_alg_id) {
1302 case (RSL_ALG_ID_A5_0) { return 0; }
1303 case (RSL_ALG_ID_A5_1) { return 1; }
1304 case (RSL_ALG_ID_A5_2) { return 2; }
1305 case (RSL_ALG_ID_A5_3) { return 3; }
1306 case (RSL_ALG_ID_A5_4) { return 4; }
1307 case (RSL_ALG_ID_A5_5) { return 5; }
1308 case (RSL_ALG_ID_A5_6) { return 6; }
1309 case (RSL_ALG_ID_A5_7) { return 7; }
1310 case else {
1311 setverdict(fail, "Unknwon Algorithm ID");
1312 self.stop;
1313 }
1314 }
1315}
1316
1317private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1318 select (rsl_alg_id) {
1319 case (RSL_ALG_ID_A5_1) { return '000'B; }
1320 case (RSL_ALG_ID_A5_2) { return '001'B; }
1321 case (RSL_ALG_ID_A5_3) { return '010'B; }
1322 case (RSL_ALG_ID_A5_4) { return '011'B; }
1323 case (RSL_ALG_ID_A5_5) { return '100'B; }
1324 case (RSL_ALG_ID_A5_6) { return '101'B; }
1325 case (RSL_ALG_ID_A5_7) { return '110'B; }
1326 case else {
1327 setverdict(fail, "Unknwon Algorithm ID");
1328 self.stop;
1329 }
1330 }
1331}
1332
1333
Harald Welte70767382018-02-21 12:16:40 +01001334/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001335private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001336 var GsmFrameNumber fn;
1337 var ImmediateAssignment imm_ass;
1338 var integer ra := 23;
1339
1340 fn := f_L1CTL_RACH(L1CTL, ra);
1341 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
1342 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
1343
1344 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001345 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001346
1347 /* Send IMM.ASS via CCHAN */
1348 var ChannelDescription ch_desc := {
1349 chan_nr := g_pars.chan_nr,
1350 tsc := 7,
1351 h := false,
1352 arfcn := mp_trx0_arfcn,
1353 maio_hsn := omit
1354 };
1355 var MobileAllocation ma := {
1356 len := 0,
1357 ma := ''B
1358 };
1359 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1360 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1361
1362 /* receive IMM.ASS on MS side */
1363 var ImmediateAssignment ia_um;
1364 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1365 /* enable dedicated mode */
1366 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001367 /* enable encryption, if requested */
1368 if (encr_enable) {
1369 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1370 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1371 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001372
1373 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001374}
1375
1376/* establish DChan, verify existance + contents of measurement reports */
1377function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001378 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001379 RSL.clear;
1380
Harald Welte5398d5e2018-03-10 19:00:24 +01001381 if (mp_bb_trxc_port != -1) {
1382 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1383 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001384
Harald Welte5398d5e2018-03-10 19:00:24 +01001385 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1386 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1387 } else {
1388 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1389 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1390 }
1391 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001392
1393 f_est_dchan();
1394
1395 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1396 * RSL measurement reports on Abis side */
1397 timer T := 8.0;
1398 T.start;
1399 alt {
1400 [] as_l1_sacch();
1401 [] as_meas_res();
1402 [] as_l1_dcch();
1403 [] L1CTL.receive { repeat; }
1404 [g_Tmeas_exp.running] T.timeout {
1405 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1406 * of any earlier errors, so if we reach this timeout, we're good */
1407 setverdict(pass);
1408 }
1409 [] T.timeout {
1410 setverdict(fail, "No MEAS RES received at all");
1411 }
1412 }
1413 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001415}
Harald Welte0472ab42018-03-12 15:02:26 +01001416
Harald Welte70767382018-02-21 12:16:40 +01001417testcase TC_meas_res_sign_tchf() runs on test_CT {
1418 var ConnHdlr vc_conn;
1419 var ConnHdlrPars pars;
1420 f_init(testcasename());
1421 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1422 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1423 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1424 vc_conn.done;
1425 }
Harald Welte294b0a22018-03-10 23:26:48 +01001426 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001427}
1428testcase TC_meas_res_sign_tchh() runs on test_CT {
1429 var ConnHdlr vc_conn;
1430 var ConnHdlrPars pars;
1431 f_init(testcasename());
1432 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1433 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1434 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1435 vc_conn.done;
1436 }
Harald Welte294b0a22018-03-10 23:26:48 +01001437 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001438}
1439testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1440 var ConnHdlr vc_conn;
1441 var ConnHdlrPars pars;
1442 f_init(testcasename());
1443 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1444 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1445 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1446 vc_conn.done;
1447 }
Harald Welte294b0a22018-03-10 23:26:48 +01001448 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001449}
1450testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1451 var ConnHdlr vc_conn;
1452 var ConnHdlrPars pars;
1453 f_init(testcasename());
1454 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1455 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1456 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1457 vc_conn.done;
1458 }
Harald Welte294b0a22018-03-10 23:26:48 +01001459 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001460}
Harald Welte685d5982018-02-27 20:42:05 +01001461testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1462 var ConnHdlr vc_conn;
1463 var ConnHdlrPars pars;
1464 f_init(testcasename());
1465 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1466 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1467 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1468 pars.l1_pars.toa256_enabled := true;
1469 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1470 vc_conn.done;
1471 }
Harald Welte294b0a22018-03-10 23:26:48 +01001472 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001473}
1474
Harald Welte70767382018-02-21 12:16:40 +01001475
Harald Welte0472ab42018-03-12 15:02:26 +01001476/* 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 +01001477private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001478 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001479 RSL.clear;
1480
1481 f_est_dchan();
1482 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001483 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001484
1485 timer T := 40.0;
1486 T.start;
1487 alt {
1488 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1489 setverdict(pass)
1490 }
1491 [] RSL.receive { repeat };
1492 [] T.timeout {
1493 setverdict(fail, "No CONN FAIL IND received");
1494 }
1495 }
1496 f_rsl_chan_deact();
1497}
1498testcase TC_conn_fail_crit() runs on test_CT {
1499 var ConnHdlr vc_conn;
1500 var ConnHdlrPars pars;
1501 f_init(testcasename());
1502 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1503 pars.t_guard := 60.0;
1504 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1505 vc_conn.done;
1506}
1507
Harald Welte93640c62018-02-25 16:59:33 +01001508/***********************************************************************
1509 * Paging
1510 ***********************************************************************/
1511
Harald Welte68e495b2018-02-25 00:05:57 +01001512function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1513 if (tmsi == 'FFFFFFFF'O) {
1514 return true;
1515 } else {
1516 return false;
1517 }
1518}
Harald Welte70767382018-02-21 12:16:40 +01001519
Harald Welte68e495b2018-02-25 00:05:57 +01001520altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1521runs on test_CT {
1522 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001523 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001524 repeat;
1525 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001526 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001527 var octetstring without_plen :=
1528 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1529 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1530 if (match(rr, tr_PAGING_REQ1)) {
1531 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1532 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1533 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1534 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1535 }
1536 } else if (match(rr, tr_PAGING_REQ2)) {
1537 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1538 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1539 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1540 }
1541 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1542 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1543 }
1544 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1545 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1546 }
1547 } else if (match(rr, tr_PAGING_REQ3)) {
1548 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1549 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1550 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1551 }
1552 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1553 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1554 }
1555 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1556 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1557 }
1558 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1559 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1560 }
1561 }
1562 repeat;
1563 }
1564}
1565
1566type record PagingTestCfg {
1567 boolean combined_ccch,
1568 integer bs_ag_blks_res,
1569 float load_factor,
1570 boolean exp_load_ind,
1571 boolean exp_overload,
1572 boolean use_tmsi
1573}
1574
1575type record PagingTestState {
1576 integer num_paging_sent,
1577 integer num_paging_rcv_msgs,
1578 integer num_paging_rcv_ids,
1579 integer num_overload
1580}
1581
1582/* receive + ignore RSL RF RES IND */
1583altstep as_rsl_res_ind() runs on test_CT {
1584 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1585 repeat;
1586 }
1587}
1588
1589/* Helper function for paging related testing */
1590private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1591 f_init(testcasename());
1592 f_init_l1ctl();
1593 f_l1_tune(L1CTL);
1594
1595 var PagingTestState st := {
1596 num_paging_sent := 0,
1597 num_paging_rcv_msgs := 0,
1598 num_paging_rcv_ids := 0,
1599 num_overload := 0
1600 };
1601
1602 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1603 var float max_pch_imsi_per_sec;
1604 if (cfg.use_tmsi) {
1605 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1606 } else {
1607 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1608 }
1609 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1610 var float interval := 1.0 / pch_blocks_per_sec;
1611 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1612
1613 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1614 /* build mobile Identity */
1615 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1616 if (cfg.use_tmsi) {
1617 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1618 } else {
1619 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1620 }
1621 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1622 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1623
1624 /* Send RSL PAGING COMMAND */
1625 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1626 st.num_paging_sent := st.num_paging_sent + 1;
1627
1628 /* Wait for interval to next PAGING COMMAND */
1629 timer T_itv := interval;
1630 T_itv.start;
1631 alt {
1632 /* check for presence of CCCH LOAD IND (paging load) */
1633 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1634 st.num_overload := st.num_overload + 1;
1635 repeat;
1636 }
1637 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1638 setverdict(fail, "Unexpected PCH Overload");
1639 }
1640 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1641 log("Rx LOAD_IND");
1642 /* FIXME: analyze/verify interval + contents */
1643 repeat;
1644 }
1645 /* check if paging requests arrive on Um side */
1646 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1647 [] L1CTL.receive { repeat; }
1648 [] T_itv.timeout { }
1649 [] as_rsl_res_ind();
1650 }
1651 }
1652
1653 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1654 timer T_wait := 18.0;
1655 T_wait.start;
1656 alt {
1657 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1658 [] L1CTL.receive { repeat; }
1659 /* 65535 == empty paging queue, we can terminate*/
1660 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1661 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1662 [] T_wait.timeout {
1663 setverdict(fail, "Waiting for empty paging queue");
1664 }
1665 [] as_rsl_res_ind();
1666 }
1667
Harald Welte294b0a22018-03-10 23:26:48 +01001668 f_shutdown();
1669
Harald Welte68e495b2018-02-25 00:05:57 +01001670 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1671 " rcvd_ids=", st.num_paging_rcv_ids);
1672 return st;
1673}
1674
1675/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1676 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1677 * - that CCCH LOAD IND (PCH) are being generated
1678 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1679testcase TC_paging_imsi_80percent() runs on test_CT {
1680 var PagingTestCfg cfg := {
1681 combined_ccch := true,
1682 bs_ag_blks_res := 1,
1683 load_factor := 0.8,
1684 exp_load_ind := true,
1685 exp_overload := false,
1686 use_tmsi := false
1687 };
1688 var PagingTestState st := f_TC_paging(cfg);
1689 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1690 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1691 st.num_paging_rcv_ids);
1692 } else {
1693 setverdict(pass);
1694 }
1695}
1696
1697/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1698 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1699 * - that CCCH LOAD IND (PCH) are being generated
1700 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1701testcase TC_paging_tmsi_80percent() runs on test_CT {
1702 var PagingTestCfg cfg := {
1703 combined_ccch := true,
1704 bs_ag_blks_res := 1,
1705 load_factor := 0.8,
1706 exp_load_ind := true,
1707 exp_overload := false,
1708 use_tmsi := true
1709 };
1710 var PagingTestState st := f_TC_paging(cfg);
1711 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1712 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1713 st.num_paging_rcv_ids);
1714 } else {
1715 setverdict(pass);
1716 }
1717}
1718
1719/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1720 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1721 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1722 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1723testcase TC_paging_imsi_200percent() runs on test_CT {
1724 var PagingTestCfg cfg := {
1725 combined_ccch := true,
1726 bs_ag_blks_res := 1,
1727 load_factor := 2.0,
1728 exp_load_ind := true,
1729 exp_overload := true,
1730 use_tmsi := false
1731 };
1732 var PagingTestState st := f_TC_paging(cfg);
1733 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1734 * slots and will fully drain that buffer before returning */
1735 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1736 if (not match(st.num_paging_rcv_ids, tpl)) {
1737 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1738 } else {
1739 setverdict(pass);
1740 }
1741}
1742
1743/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1744 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1745 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1746 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1747testcase TC_paging_tmsi_200percent() runs on test_CT {
1748 var PagingTestCfg cfg := {
1749 combined_ccch := true,
1750 bs_ag_blks_res := 1,
1751 load_factor := 2.0,
1752 exp_load_ind := true,
1753 exp_overload := true,
1754 use_tmsi := true
1755 };
1756 var PagingTestState st := f_TC_paging(cfg);
1757 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1758 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001759 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001760 if (not match(st.num_paging_rcv_ids, tpl)) {
1761 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1762 } else {
1763 setverdict(pass);
1764 }
1765}
1766
1767
Harald Welte93640c62018-02-25 16:59:33 +01001768/***********************************************************************
1769 * Immediate Assignment / AGCH
1770 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001771const MobileAllocation c_MA_null := {
1772 len := 0,
1773 ma := ''B
1774}
Harald Welte93640c62018-02-25 16:59:33 +01001775
Harald Weltee8d750e2018-06-10 21:41:35 +02001776template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1777 uint12_t arfcn := 871) := {
1778 chan_nr := chan_nr,
1779 tsc := tsc,
1780 h := false,
1781 arfcn := arfcn,
1782 maio_hsn := omit
1783}
1784
1785private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1786 return int2str(num_tx) & " sent, "
1787 & int2str(num_rx) & " received, "
1788 & int2str(num_del) & " deleted";
1789}
1790
1791private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1792 var L1ctlDlMessage l1_dl;
1793 timer T := 10.0;
1794 var integer num_tx := 0;
1795 var integer num_rx := 0;
1796 var integer num_del := 0;
1797 var charstring res_str;
1798 var float rx_ratio;
1799
Harald Welte68e495b2018-02-25 00:05:57 +01001800 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001801 f_init_l1ctl();
1802 f_l1_tune(L1CTL);
1803
1804 for (var integer i := 0; i < num_total; i := i+1) {
1805 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1806 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1807 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001808 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001809 num_tx := num_tx+1;
1810 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001811 }
1812 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02001813 T.start;
1814 alt {
1815 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
1816 num_del := num_del+1;
1817 repeat;
1818 }
1819 [] RSL_CCHAN.receive {
1820 repeat;
1821 }
1822 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
1823 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1824 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
1825 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
1826 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
1827 //setverdict(fail, "Unexpected IMM-ASS values on AGCH: ", rr);
1828 //self.stop;
1829 } else {
1830 num_rx := num_rx+1;
1831 }
1832 repeat;
1833 }
1834 [] L1CTL.receive { repeat; }
1835 [] T.timeout { }
1836 }
1837 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
1838 log("AGCH test: " & res_str);
1839 if (num_rx + num_del != num_tx) {
1840 setverdict(fail, "RX + DEL != TX ?!?: " & res_str);
1841 }
1842 rx_ratio := int2float(num_rx) / int2float(num_tx);
1843 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
1844 setverdict(fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
1845 } else {
1846 setverdict(pass);
1847 }
Harald Welte68e495b2018-02-25 00:05:57 +01001848}
1849
Harald Weltee8d750e2018-06-10 21:41:35 +02001850/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
1851testcase TC_imm_ass_1000_20ms() runs on test_CT {
1852 f_TC_imm_ass(1000, 0.02, 0.25);
1853}
1854
1855/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
1856testcase TC_imm_ass_200_0ms() runs on test_CT {
1857 f_TC_imm_ass(200, 0.0, 0.05);
1858}
1859
1860/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
1861testcase TC_imm_ass_200_76ms() runs on test_CT {
1862 f_TC_imm_ass(150, 0.076, 1.00);
1863}
1864
1865
1866
Harald Welte48494ca2018-02-25 16:59:50 +01001867/***********************************************************************
1868 * BCCH
1869 ***********************************************************************/
1870
1871/* tuple of Frame Number + decoded SI */
1872type record SystemInformationFn {
1873 GsmFrameNumber frame_number,
1874 SystemInformation si
1875}
1876
1877/* an arbitrary-length vector of decoded SI + gsmtap header */
1878type record of SystemInformationFn SystemInformationVector;
1879
1880/* an array of SI-vectors indexed by TC value */
1881type SystemInformationVector SystemInformationVectorPerTc[8];
1882
1883/* determine if a given SI vector contains given SI type at least once */
1884function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1885 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1886 var integer fn_mod51 := arr[i].frame_number mod 51;
1887 if (not bcch_ext and fn_mod51 == 2 or
1888 bcch_ext and fn_mod51 == 6) {
1889 if (arr[i].si.header.message_type == key) {
1890 return true;
1891 }
1892 }
1893 }
1894 return false;
1895}
1896
1897/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1898function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1899 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1900 setverdict(fail, "No ", key, " in TC=", tc, "!");
1901 }
1902}
1903
1904/* check if a given SI vector contains given SI type at least once on any TC */
1905function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1906 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1907 if (f_si_vecslot_contains(arr[tc], key) or
1908 f_si_vecslot_contains(arr[tc], key, true)) {
1909 return true;
1910 }
1911 }
1912 return false;
1913}
1914
1915/* determine if a given SI vector contains given SI type at least N of M times */
1916function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1917 var integer count := 0;
1918 if (sizeof(arr) < m) {
1919 setverdict(fail, "Error: Insufficient SI in array");
1920 self.stop;
1921 }
1922 for (var integer i:= 0; i < m; i := i + 1) {
1923 var integer fn_mod51 := arr[i].frame_number mod 51;
1924 if (not bcch_ext and fn_mod51 == 2 or
1925 bcch_ext and fn_mod51 == 6) {
1926 if (arr[i].si.header.message_type == key) {
1927 count := count + 1;
1928 }
1929 }
1930 }
1931 if (count >= n) {
1932 return true;
1933 } else {
1934 return false;
1935 }
1936}
1937
1938/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1939function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1940 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1941 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1942 }
1943}
1944
1945/* determine if a given SI vector contains given SI type at least once */
1946function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1947 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1948 var integer fn_mod51 := arr[i].frame_number mod 51;
1949 if (not bcch_ext and fn_mod51 == 2 or
1950 bcch_ext and fn_mod51 == 6) {
1951 if (arr[i].si.header.message_type != key) {
1952 return false;
1953 }
1954 }
1955 }
1956 return true;
1957}
1958
1959/* ensure a given TC slot of the SI vector contains only given SI type */
1960function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1961 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1962 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1963 }
1964}
1965
1966/* SI configuration of cell, against which we validate actual SI messages */
1967type set SystemInformationConfig {
1968 boolean bcch_extended,
1969 boolean si1_present,
1970 boolean si2bis_present,
1971 boolean si2ter_present,
1972 boolean si2quater_present,
1973 boolean si7_present,
1974 boolean si8_present,
1975 boolean si9_present,
1976 boolean si13_present,
1977 boolean si13alt_present,
1978 boolean si15_present,
1979 boolean si16_present,
1980 boolean si17_present,
1981 boolean si2n_present,
1982 boolean si21_present,
1983 boolean si22_present
1984}
1985
1986/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1987function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1988 var integer i;
1989 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1990 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001991 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001992 }
1993 }
1994 if (cfg.si1_present) {
1995 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1996 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1997 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1998 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1999 /* make sure *ALL* contain SI1 */
2000 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2001 }
2002 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2003 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2004 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2005 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2006 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2007 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2008
2009 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2010 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2011 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2012 * consecutive occurrences of TC = 4. */
2013 if (cfg.si2bis_present and not cfg.si2ter_present) {
2014 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2015 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2016 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2017 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2018 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2019 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2020 }
2021
2022 if (cfg.si7_present or cfg.si8_present) {
2023 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2024 * if System Information type 4 does not contain all information needed for cell
2025 * selection and reselection. */
2026 if (not cfg.bcch_extended) {
2027 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2028 }
2029 if (cfg.si7_present) {
2030 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2031 }
2032 if (cfg.si8_present) {
2033 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2034 }
2035 }
2036
2037 if (cfg.si2quater_present) {
2038 /* iii) System information type 2 quater is sent if needed, as determined by the system
2039 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2040 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2041 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2042 * within any of 4 consecutive occurrences of TC = 5. */
2043 if (not (cfg.bcch_extended)) {
2044 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2045 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2046 } else {
2047 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2048 }
2049 } else {
2050 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2051 }
2052 }
2053 if (cfg.si9_present) {
2054 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2055 * in system information type 3 as defined in 3GPP TS 44.018. */
2056 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2057 }
2058 if (cfg.si13_present) {
2059 /* vii) System Information type 13 is only related to the GPRS service. System Information
2060 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2061 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2062 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2063 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2064 * within any of 4 consecutive occurrences of TC=4. */
2065 if (not cfg.bcch_extended) {
2066 log("not-bccch-extended");
2067 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2068 } else {
2069 log("bccch-extended");
2070 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2071 }
2072 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
2073 setverdict(fail, "Cannot have SI13alt and SI13");
2074 }
2075 }
2076 if (cfg.si16_present or cfg.si17_present) {
2077 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2078 * should not be sent in a cell where network sharing is used (see rule xv). */
2079 if (cfg.si22_present) {
2080 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2081 }
2082 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
2083 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2084 }
2085 if (not cfg.bcch_extended) {
2086 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2087 }
2088 if (cfg.si16_present) {
2089 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2090 }
2091 if (cfg.si17_present) {
2092 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2093 }
2094 }
2095
2096 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2097 * broadcast information. The frequency with which they are sent is determined by the
2098 * system operator. System Information type 9 identifies the scheduling of System
2099 * Information type 18 and 20 messages. */
2100
2101 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2102 * Information Type 19 is present, then its scheduling shall be indicated in System
2103 * Information Type 9. */
2104
2105 if (cfg.si15_present) {
2106 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2107 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2108 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2109 * 4 consecutive occurrences of TC = 1. */
2110 if (not cfg.bcch_extended) {
2111 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2112 } else {
2113 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2114 }
2115 }
2116 if (cfg.si13alt_present) {
2117 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2118 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2119 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2120 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2121 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2122 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2123 * of TC = 4. */
2124 if (cfg.si13_present) {
2125 testcase.stop("Error: Cannot have SI13alt and SI13");
2126 }
2127 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
2128 setverdict(fail, "Cannot have SI13alt and SI13");
2129 }
2130 if (not cfg.bcch_extended) {
2131 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2132 } else {
2133 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2134 }
2135 }
2136 if (cfg.si2n_present) {
2137 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2138 * as determined by the system operator. In the case that the message is sent on the
2139 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2140 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2141 * consecutive occurrences of TC = 4. */
2142 if (not cfg.bcch_extended) {
2143 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2144 } else {
2145 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2146 }
2147 }
2148 if (cfg.si21_present) {
2149 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2150 * determined by the system operator. If Extended Access Barring is in use in the cell
2151 * then this message is sent at least once within any of 4 consecutive occurrences of
2152 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2153 * cell then this message shall only be sent on BCCH Ext. */
2154 if (not cfg.bcch_extended) {
2155 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2156 } else {
2157 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2158 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
2159 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
2160 }
2161 }
2162 }
2163 if (cfg.si22_present) {
2164 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2165 * should not be sent in a cell where SoLSA is used (see rule viii). System
2166 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2167 * =2 and TC=6. */
2168 if (cfg.si16_present or cfg.si17_present) {
2169 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2170 }
2171 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2172 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2173 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2174 }
2175 if (not cfg.bcch_extended) {
2176 testcase.stop("Error: SI22 requires BCCH Extd!");
2177 } else {
2178 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2179 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2180 }
2181 }
2182}
2183
2184/* sample Systme Information for specified duration via L1CTL */
2185function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2186 timer T := duration;
2187 var SystemInformationVectorPerTc si_per_tc;
2188 var L1ctlDlMessage l1_dl;
2189
2190 /* initialize all per-TC vectors empty */
2191 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2192 si_per_tc[i] := {};
2193 }
2194
2195 /* flush all previous L1 queued msgs */
2196 pt.clear;
2197
2198 T.start;
2199 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002200 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002201 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2202 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2203 log("Ignoring non-RR SI ", l1_dl);
2204 repeat;
2205 }
2206 var SystemInformationFn sig := {
2207 frame_number := l1_dl.dl_info.frame_nr,
2208 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2209 }
2210 var integer tc := f_gsm_compute_tc(sig.frame_number);
2211 log("SI received at TC=", tc, ": ", sig.si);
2212 /* append to the per-TC bucket */
2213 si_per_tc[tc] := si_per_tc[tc] & { sig };
2214 repeat;
2215 }
2216 [] pt.receive { repeat; }
2217 [] T.timeout { }
2218 }
2219
2220 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2221 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2222 }
2223 log("si_per_tc=", si_per_tc);
2224 return si_per_tc;
2225}
2226
2227/* helper function: Set given SI via RSL + validate scheduling.
2228 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2229function f_TC_si_sched() runs on test_CT {
2230 var SystemInformationVectorPerTc si_per_tc;
2231 f_init_l1ctl();
2232 f_l1_tune(L1CTL);
2233
2234 /* Sample + Validate Scheduling */
2235 si_per_tc := f_l1_sample_si(L1CTL);
2236 f_validate_si_scheduling(si_cfg, si_per_tc);
2237
2238 setverdict(pass);
2239}
2240
2241testcase TC_si_sched_default() runs on test_CT {
2242 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002243 /* 2+3+4 are mandatory and set in f_init() */
2244 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002245 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002246}
2247
2248testcase TC_si_sched_1() runs on test_CT {
2249 f_init();
2250 si_cfg.si1_present := true;
2251 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002252 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002253 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002254}
2255
2256testcase TC_si_sched_2bis() runs on test_CT {
2257 f_init();
2258 si_cfg.si2bis_present := true;
2259 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2260 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002261 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002262}
2263
2264testcase TC_si_sched_2ter() runs on test_CT {
2265 f_init();
2266 si_cfg.si2ter_present := true;
2267 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2268 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002269 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002270}
2271
2272testcase TC_si_sched_2ter_2bis() runs on test_CT {
2273 f_init();
2274 si_cfg.si2bis_present := true;
2275 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2276 si_cfg.si2ter_present := true;
2277 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2278 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002279 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002280}
2281
2282testcase TC_si_sched_2quater() runs on test_CT {
2283 f_init();
2284 si_cfg.si2quater_present := true;
2285 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2286 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002287 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002288}
2289
2290testcase TC_si_sched_13() runs on test_CT {
2291 f_init();
2292 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002293 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002294 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002295 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002296}
2297
2298testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2299 f_init();
2300 si_cfg.si2bis_present := true;
2301 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2302 si_cfg.si2ter_present := true;
2303 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2304 si_cfg.si2quater_present := true;
2305 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2306 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002307 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002308 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002309 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002310}
2311
2312
Harald Welte68e495b2018-02-25 00:05:57 +01002313testcase TC_bcch_info() runs on test_CT {
2314 f_init(testcasename());
2315 /* FIXME: enable / disable individual BCCH info */
2316 //ts_RSL_BCCH_INFO(si_type, info);
2317 /* expect no ERROR REPORT after either of them *
2318 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002319 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002320}
2321
Harald Welte93640c62018-02-25 16:59:33 +01002322/***********************************************************************
2323 * Low-Level Protocol Errors / ERROR REPORT
2324 ***********************************************************************/
2325
Harald Welte01d982c2018-02-25 01:31:40 +01002326private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2327 timer T := 5.0;
2328 T.start;
2329 alt {
2330 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2331 setverdict(pass);
2332 }
2333 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2334 setverdict(fail, "Wrong cause in RSL ERR REP");
2335 }
2336 [] RSL_CCHAN.receive {
2337 repeat;
2338 }
2339 [] T.timeout {
2340 setverdict(fail, "Timeout waiting for RSL ERR REP");
2341 }
2342 }
2343}
2344
2345/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2346testcase TC_rsl_protocol_error() runs on test_CT {
2347 f_init(testcasename());
2348 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2349 rsl.ies := omit;
2350 RSL_CCHAN.send(ts_RSL_UD(rsl));
2351
2352 f_exp_err_rep(RSL_ERR_PROTO);
2353}
2354
2355/* Provoke a mandatory IE error and match on ERROR REPORT */
2356testcase TC_rsl_mand_ie_error() runs on test_CT {
2357 f_init(testcasename());
2358
2359 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2360 rsl.ies := { rsl.ies[0] };
2361 RSL_CCHAN.send(ts_RSL_UD(rsl));
2362
2363 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2364}
2365
2366/* Provoke an IE content error and match on ERROR REPORT */
2367testcase TC_rsl_ie_content_error() runs on test_CT {
2368 f_init(testcasename());
2369 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2370 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2371 RSL_CCHAN.send(ts_RSL_UD(rsl));
2372
2373 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2374}
2375
Harald Welte93640c62018-02-25 16:59:33 +01002376/***********************************************************************
2377 * IPA CRCX/MDCX/DLCS media stream handling
2378 ***********************************************************************/
2379
Harald Weltea871a382018-02-25 02:03:14 +01002380/* Send IPA DLCX to inactive lchan */
2381function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002382 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2383 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002384}
2385testcase TC_ipa_dlcx_not_active() runs on test_CT {
2386 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2387 f_init(testcasename());
2388 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2389 vc_conn.done;
2390}
Harald Welte68e495b2018-02-25 00:05:57 +01002391
Harald Weltea3f1df92018-02-25 12:49:55 +01002392/* Send IPA CRCX twice to inactive lchan */
2393function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2394 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2395 "IPA CRCX ACK");
2396 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2397 "IPA CRCX NACK");
2398}
2399testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2400 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2401 f_init(testcasename());
2402 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2403 vc_conn.done;
2404}
2405
2406/* Regular sequence of CRCX/MDCX/DLCX */
2407function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2408 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2409 "IPA CRCX ACK");
2410 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2411 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2412 var uint7_t rtp_pt2 := f_rnd_int(127);
2413 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2414 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2415 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2416 "IPA MDCX ACK");
2417 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2418 "IPA DLCX ACK");
2419}
2420testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2421 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2422 f_init(testcasename());
2423 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2424 vc_conn.done;
2425}
2426
Harald Welte3ae11da2018-02-25 13:36:06 +01002427/* Sequence of CRCX, 2x MDCX, DLCX */
2428function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2429 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2430 "IPA CRCX ACK");
2431 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2432 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2433 var uint7_t rtp_pt2 := f_rnd_int(127);
2434 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2435 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2436 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2437 "IPA MDCX ACK");
2438 /* Second MDCX */
2439 remote_ip := f_rnd_int(c_UINT32_MAX);
2440 remote_port := f_rnd_int(c_UINT16_MAX);
2441 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2442 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2443 "IPA MDCX ACK");
2444 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2445 "IPA DLCX ACK");
2446}
2447testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2448 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2449 f_init(testcasename());
2450 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2451 vc_conn.done;
2452}
2453
Harald Welte9912eb52018-02-25 13:30:15 +01002454/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2455function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2456 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2457 "IPA CRCX NACK");
2458}
2459testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2460 var ConnHdlrPars pars;
2461 var ConnHdlr vc_conn;
2462 f_init(testcasename());
2463
2464 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2465 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2466 vc_conn.done;
2467
2468 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2469 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2470 vc_conn.done;
2471}
2472
Harald Weltea3f1df92018-02-25 12:49:55 +01002473
Harald Welte883340c2018-02-28 18:59:29 +01002474/***********************************************************************
2475 * PCU Socket related tests
2476 ***********************************************************************/
2477
2478private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2479runs on test_CT {
2480 timer T := 3.0;
2481
2482 /* we don't expect any RTS.req before PDCH are active */
2483 T.start;
2484 alt {
2485 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2486 setverdict(fail, "PCU RTS.req before PDCH active?");
2487 self.stop;
2488 }
2489 [] PCU.receive { repeat; }
2490 [] T.timeout { }
2491 }
2492
2493 /* Send PDCH activate request for known PDCH timeslot */
2494 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2495
2496 /* we now expect RTS.req for this timeslot (only) */
2497 T.start;
2498 alt {
2499 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2500 setverdict(pass);
2501 }
2502 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2503 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2504 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2505 self.stop;
2506 }
2507 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2508 setverdict(fail, "RTS.req for wrong TRX/TS");
2509 self.stop;
2510 }
2511 [] PCU.receive { repeat; }
2512 [exp_success] T.timeout {
2513 setverdict(fail, "Timeout waiting for PCU RTS.req");
2514 }
2515 [not exp_success] T.timeout {
2516 setverdict(pass);
2517 }
2518 }
2519}
2520
2521private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2522runs on test_CT {
2523 timer T := 3.0;
2524
2525 /* Send PDCH activate request for known PDCH timeslot */
2526 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2527
2528 PCU.clear;
2529 /* we now expect no RTS.req for this timeslot */
2530 T.start;
2531 alt {
2532 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2533 setverdict(fail, "Received unexpected PCU RTS.req");
2534 self.stop;
2535 }
2536 [] PCU.receive { repeat; }
2537 [] T.timeout {
2538 setverdict(pass);
2539 }
2540 }
2541}
2542
2543/* PDCH activation via PCU socket; check for presence of RTS.req */
2544testcase TC_pcu_act_req() runs on test_CT {
2545 f_init();
2546 f_TC_pcu_act_req(0, 0, 7, true);
2547}
2548
2549/* PDCH activation via PCU socket on non-PDCU timeslot */
2550testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2551 f_init();
2552 f_TC_pcu_act_req(0, 0, 1, false);
2553}
2554
2555/* PDCH activation via PCU socket on wrong BTS */
2556testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2557 f_init();
2558 f_TC_pcu_act_req(23, 0, 7, false);
2559}
2560
2561/* PDCH activation via PCU socket on wrong TRX */
2562testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2563 f_init();
2564 f_TC_pcu_act_req(0, 23, 7, false);
2565}
2566
2567/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2568testcase TC_pcu_deact_req() runs on test_CT {
2569 f_init();
2570 /* Activate PDCH */
2571 f_TC_pcu_act_req(0, 0, 7, true);
2572 f_sleep(1.0);
2573 /* and De-Activate again */
2574 f_TC_pcu_deact_req(0, 0, 7);
2575}
2576
2577/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2578testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2579 f_init();
2580 f_TC_pcu_deact_req(0, 0, 1);
2581}
2582
2583/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2584testcase TC_pcu_ver_si13() runs on test_CT {
2585 const octetstring si13 := '00010203040506070909'O;
2586 var PCUIF_send_data sd;
2587 timer T:= 3.0;
2588 f_init();
2589
2590 /* Set SI13 via RSL */
2591 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2592 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2593 T.start;
2594 alt {
2595 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2596 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2597 setverdict(pass);
2598 } else {
2599 repeat;
2600 }
2601 }
2602 [] PCU.receive { repeat; }
2603 [] T.timeout {
2604 setverdict(fail, "Timeout waiting for SI13");
2605 self.stop;
2606 }
2607 }
2608}
2609
2610private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2611
2612/* helper function to send a PCU DATA.req */
2613private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2614 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2615runs on test_CT
2616{
2617 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2618 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2619}
2620
2621/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2622private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2623 PCUIF_Sapi sapi, octetstring data)
2624runs on test_CT
2625{
2626 var PCUIF_send_data sd;
2627
2628 timer T := 3.0;
2629 T.start;
2630 alt {
2631 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2632 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2633 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2634 sd.data.u.rts_req.fn, sapi, data);
2635 }
2636 [] PCU.receive { repeat; }
2637 [] T.timeout {
2638 setverdict(fail, "Timeout waiting for RTS.ind");
2639 }
2640 }
2641}
2642
2643/* Send DATA.req on invalid BTS */
2644testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2645 f_init();
2646 f_TC_pcu_act_req(0, 0, 7, true);
2647 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2648 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2649 f_sleep(10.0);
2650}
2651
2652/* Send DATA.req on invalid TRX */
2653testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2654 f_init();
2655 f_TC_pcu_act_req(0, 0, 7, true);
2656 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2657 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2658 f_sleep(10.0);
2659}
2660
2661/* Send DATA.req on invalid timeslot */
2662testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2663 f_init();
2664 f_TC_pcu_act_req(0, 0, 7, true);
2665 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2666 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2667 f_sleep(10.0);
2668}
2669
2670/* Send DATA.req on timeslot that hasn't been activated */
2671testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2672 f_init();
2673 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2674 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2675 f_sleep(2.0);
2676}
2677
2678testcase TC_pcu_data_req_pdtch() runs on test_CT {
2679 f_init();
2680 f_TC_pcu_act_req(0, 0, 7, true);
2681 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2682 /* FIXME: how to check this was actually sent */
2683 f_sleep(2.0);
2684}
2685
2686testcase TC_pcu_data_req_ptcch() runs on test_CT {
2687 f_init();
2688 f_TC_pcu_act_req(0, 0, 7, true);
2689 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2690 /* FIXME: how to check this was actually sent */
2691 f_sleep(2.0);
2692}
2693
2694/* Send AGCH from PCU; check it appears on Um side */
2695testcase TC_pcu_data_req_agch() runs on test_CT {
2696 timer T := 3.0;
2697 f_init();
2698 f_init_l1ctl();
2699 f_l1_tune(L1CTL);
2700
2701 f_TC_pcu_act_req(0, 0, 7, true);
2702 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2703
2704 T.start;
2705 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002706 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002707 setverdict(pass);
2708 }
2709 [] L1CTL.receive { repeat; }
2710 [] T.timeout {
2711 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2712 }
2713 }
2714}
2715
2716/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2717testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2718 var octetstring imm_ass := f_rnd_octstring(23);
2719 f_init();
2720 f_init_l1ctl();
2721 f_l1_tune(L1CTL);
2722
2723 /* append 3 last imsi digits so BTS can compute pagng group */
2724 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2725
2726 timer T := 0.5;
2727 T.start;
2728 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002729 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002730 /* TODO: verify paging group */
2731 setverdict(pass);
2732 }
2733 [] L1CTL.receive { repeat; }
2734 [] T.timeout {
2735 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2736 }
2737 }
2738}
2739
2740/* Send RACH from Um side, expect it to show up on PCU socket */
2741testcase TC_pcu_rach_content() runs on test_CT {
2742 f_init();
2743 f_init_l1ctl();
2744 f_l1_tune(L1CTL);
2745
2746 var GsmFrameNumber fn_last := 0;
2747 for (var integer i := 0; i < 1000; i := i+1) {
2748 var OCT1 ra := f_rnd_ra_ps();
2749 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2750 if (fn == fn_last) {
2751 setverdict(fail, "Two RACH in same FN?!?");
2752 self.stop;
2753 }
2754 fn_last := fn;
2755
2756 timer T := 2.0;
2757 T.start;
2758 alt {
2759 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2760 T.stop;
2761 }
2762 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2763 setverdict(fail, "Unexpected RACH IND");
2764 self.stop;
2765 }
2766 [] PCU.receive { repeat; }
2767 [] T.timeout {
2768 setverdict(fail, "Timeout waiting for RACH IND");
2769 self.stop;
2770 }
2771 }
2772 }
2773 setverdict(pass);
2774}
2775
2776private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2777 var integer strlen := lengthof(str);
2778 for (var integer i := 0; i < len-strlen; i := i+1) {
2779 str := str & pad;
2780 }
2781 return str;
2782}
2783
2784/* Send PAGING via RSL, expect it to shw up on PCU socket */
2785testcase TC_pcu_paging_from_rsl() runs on test_CT {
2786 f_init();
2787
2788 for (var integer i := 0; i < 100; i := i+1) {
2789 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2790 timer T := 3.0;
2791 if (i < 50) {
2792 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2793 } else {
2794 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2795 }
2796 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2797 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2798 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2799
2800 /* Send RSL PAGING COMMAND */
2801 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2802 T.start;
2803 alt {
2804 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2805 }
2806 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2807 setverdict(fail, "Unexpected PAGING REQ");
2808 self.stop;
2809 }
2810 [] PCU.receive { repeat; }
2811 [] T.timeout {
2812 setverdict(fail, "Timeout waiting for PAGING REQ");
2813 self.stop;
2814 }
2815 }
2816 }
2817 setverdict(pass);
2818}
2819
Harald Welte3d04ae62018-04-04 20:29:05 +02002820/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002821 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002822 ***********************************************************************/
2823
2824private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2825runs on ConnHdlr {
2826 var PCUIF_send_data sd;
2827 /* Expect BTS to immediately acknowledge activation as PDCH */
2828 PCU.clear;
2829 f_rsl_chan_act(g_pars.chan_mode);
2830 /* expect INFO_IND on PCU interface listing TS as PDCH */
2831 alt {
2832 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2833 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2834 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2835 self.stop;
2836 }
2837 }
2838 [] PCU.receive { repeat; }
2839 }
2840 /* try to activate this PDCH from the PCU point of view */
2841 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2842 /* FIXME: is there a response? */
2843}
2844
2845private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2846runs on ConnHdlr {
2847 var PCUIF_send_data sd;
2848 /* Send RSL CHAN REL (deactivate) */
2849 PCU.clear;
2850 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2851 /* expect BTS to ask PCU to deactivate the channel */
2852 alt {
2853 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2854 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2855 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2856 self.stop;
2857 }
2858 }
2859 [] PCU.receive { repeat; }
2860 }
2861 /* Emulate PCU asking BTS to deactivate PDCH */
2862 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2863 alt {
2864 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2865 setverdict(pass);
2866 }
2867 [] RSL.receive { repeat; }
2868 }
2869}
2870
2871/* Activate Osmocom-style dynamic PDCH from BSC side */
2872function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2873 var PCUIF_Message first_info;
2874 var integer ts_nr := g_chan_nr.tn;
2875 var integer trx_nr := 0;
2876 var integer bts_nr := 0;
2877 var integer pcu_conn_id := -1;
2878
2879 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2880
2881 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2882 f_sleep(3.0);
2883 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2884 setverdict(pass);
2885}
2886testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2887 var ConnHdlrPars pars;
2888 var ConnHdlr vc_conn;
2889 f_init(testcasename());
2890
2891 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2892 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2893 vc_conn.done;
2894}
2895
2896/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2897function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2898 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002899 var integer pcu_conn_id := -1;
2900
2901 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2902
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002903 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2904 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2905 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002906 setverdict(pass);
2907}
2908testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2909 var ConnHdlrPars pars;
2910 var ConnHdlr vc_conn;
2911 f_init(testcasename());
2912
2913 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2914 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2915 vc_conn.done;
2916}
2917
2918/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2919function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2920 var PCUIF_Message first_info;
2921 var integer ts_nr := g_chan_nr.tn;
2922 var integer trx_nr := 0;
2923 var integer bts_nr := 0;
2924 var integer pcu_conn_id := -1;
2925
2926 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2927
2928 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002929 /* Send a second Chan Activ and expect it to be NACKed */
2930 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2931 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002932 setverdict(pass);
2933}
2934testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2935 var ConnHdlrPars pars;
2936 var ConnHdlr vc_conn;
2937 f_init(testcasename());
2938
2939 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2940 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2941 vc_conn.done;
2942}
2943
2944/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2945function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2946 var PCUIF_Message first_info;
2947 var integer ts_nr := g_chan_nr.tn;
2948 var integer trx_nr := 0;
2949 var integer bts_nr := 0;
2950 var integer pcu_conn_id := -1;
2951 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2952
2953 /* register for the TCH/F channel number */
2954 f_rslem_register(0, chan_nr);
2955
2956 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2957
2958 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2959 "RSL CHAN ACT");
2960 setverdict(pass);
2961}
2962testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2963 var ConnHdlrPars pars;
2964 var ConnHdlr vc_conn;
2965 f_init(testcasename());
2966
2967 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2968 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2969 vc_conn.done;
2970}
2971
2972/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2973function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2974 var PCUIF_Message first_info;
2975 var integer ts_nr := g_chan_nr.tn;
2976 var integer trx_nr := 0;
2977 var integer bts_nr := 0;
2978 var integer pcu_conn_id := -1;
2979 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2980 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2981
2982 /* register for the TCH/H channel numbers */
2983 f_rslem_register(0, chan_nr[0]);
2984 f_rslem_register(0, chan_nr[1]);
2985
2986 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2987
2988 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2989 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2990 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2991 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2992 setverdict(pass);
2993}
2994testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
2995 var ConnHdlrPars pars;
2996 var ConnHdlr vc_conn;
2997 f_init(testcasename());
2998
2999 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3000 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3001 vc_conn.done;
3002}
3003
Harald Welte9bbbfb52018-04-05 09:33:19 +02003004/***********************************************************************
3005 * IPA Style Dynamic Timeslot Support
3006 ***********************************************************************/
3007
3008private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3009runs on ConnHdlr {
3010 var PCUIF_send_data sd;
3011 /* Expect BTS to immediately acknowledge activation as PDCH */
3012 PCU.clear;
3013 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3014 /* expect INFO_IND on PCU interface listing TS as PDCH */
3015 alt {
3016 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3017 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
3018 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
3019 self.stop;
3020 }
3021 }
3022 [] PCU.receive { repeat; }
3023 }
3024 /* try to activate this PDCH from the PCU point of view */
3025 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3026 /* FIXME: is there a response? */
3027
3028 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3029}
3030
3031private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3032runs on ConnHdlr {
3033 var PCUIF_send_data sd;
3034 /* Send RSL CHAN REL (deactivate) */
3035 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3036 PCU.clear;
3037 /* expect BTS to ask PCU to deactivate the channel */
3038 alt {
3039 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3040 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
3041 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
3042 self.stop;
3043 }
3044 }
3045 [] PCU.receive { repeat; }
3046 }
3047 /* Emulate PCU asking BTS to deactivate PDCH */
3048 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3049 alt {
3050 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3051 setverdict(pass);
3052 }
3053 [] RSL.receive { repeat; }
3054 }
3055}
3056
3057/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3058function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3059 var PCUIF_Message first_info;
3060 var integer ts_nr := g_chan_nr.tn;
3061 var integer trx_nr := 0;
3062 var integer bts_nr := 0;
3063 var integer pcu_conn_id := -1;
3064
3065 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3066
3067 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3068 f_sleep(3.0);
3069 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3070
3071 setverdict(pass);
3072
3073}
3074testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3075 var ConnHdlrPars pars;
3076 var ConnHdlr vc_conn;
3077 f_init();
3078
3079 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3080 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3081 vc_conn.done;
3082}
3083
3084/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3085function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3086 var PCUIF_Message first_info;
3087 var integer ts_nr := g_chan_nr.tn;
3088 var integer trx_nr := 0;
3089 var integer bts_nr := 0;
3090 var integer pcu_conn_id := -1;
3091
3092 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3093
3094 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3095 "RSL CHAN ACT");
3096 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3097 "RF CHAN REL", true);
3098 setverdict(pass);
3099}
3100testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3101 var ConnHdlrPars pars;
3102 var ConnHdlr vc_conn;
3103 f_init(testcasename());
3104
3105 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3106 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3107 vc_conn.done;
3108}
3109
3110/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3111function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3112 var PCUIF_Message first_info;
3113 var integer ts_nr := g_chan_nr.tn;
3114 var integer trx_nr := 0;
3115 var integer bts_nr := 0;
3116 var integer pcu_conn_id := -1;
3117
3118 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3119
3120 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3121 "RSL CHAN ACT");
3122
3123 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3124 alt {
3125 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3126 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
3127 setverdict(fail, "Unexpected PDCH ACT ACK");
3128 self.stop;
3129 }
3130 [] RSL.receive { repeat; }
3131 }
3132
3133 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3134 "RF CHAN REL", true);
3135 setverdict(pass);
3136}
3137testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3138 var ConnHdlrPars pars;
3139 var ConnHdlr vc_conn;
3140 f_init(testcasename());
3141
3142 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3143 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3144 vc_conn.done;
3145}
3146
3147/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3148function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3149 var PCUIF_Message first_info;
3150 var integer ts_nr := g_chan_nr.tn;
3151 var integer trx_nr := 0;
3152 var integer bts_nr := 0;
3153 var integer pcu_conn_id := -1;
3154
3155 /* register for the TCH/F channel number */
3156 f_rslem_register(0, g_chan_nr);
3157
3158 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3159
3160 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3161
3162 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3163 "RSL CHAN ACT");
3164
3165 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3166
3167 setverdict(pass);
3168}
3169testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3170 var ConnHdlrPars pars;
3171 var ConnHdlr vc_conn;
3172 f_init(testcasename());
3173
3174 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3175 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3176 vc_conn.done;
3177}
3178
3179
Harald Welte0472ab42018-03-12 15:02:26 +01003180/***********************************************************************
3181 * LAPDm / RLL related
3182 ***********************************************************************/
3183
3184private function f_tx_lapdm(template (value) LapdmFrame l,
3185 template (value) RslLinkId link_id) runs on ConnHdlr {
3186 var octetstring l2 := enc_LapdmFrame(valueof(l));
3187 if (valueof(link_id.c) == SACCH) {
3188 /* prepend dummy L1 header */
3189 l2 := '0000'O & l2;
3190 }
3191 log("encoding ", l, " to ", l2);
3192 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3193}
3194
3195type record RllTestCase {
3196 uint3_t sapi,
3197 RslLinkId link_id,
3198 octetstring l3,
3199 boolean exp
3200}
3201type record of RllTestCase RllTestCases;
3202template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3203 sapi := sapi,
3204 link_id := id,
3205 l3 := l3,
3206 exp := exp
3207}
3208
3209/* execute the same callback function with a set of different parameters (tcs) on a
3210 * variety of logical channels */
3211private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3212 var ConnHdlrPars pars;
3213 var ConnHdlr vc_conn;
3214 f_init(testcasename());
3215
3216 /* test on each of the channels we have */
3217 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3218 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3219
3220 /* test each of the test cases on the current channel */
3221 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3222 pars.spec.rll := tcs[j];
3223 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3224 vc_conn := f_start_handler(fn, pars);
3225 vc_conn.done;
3226 }
3227 }
3228
3229 f_shutdown();
3230}
3231
3232/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3233private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3234 var RllTestCase tc := g_pars.spec.rll;
3235 timer T := 3.0;
3236
3237 f_l1_tune(L1CTL);
3238 RSL.clear;
3239
3240 /* activate the logical channel */
3241 f_est_dchan();
3242 L1CTL.clear;
3243
3244 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3245 T.start;
3246 alt {
3247 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3248 if (tc.exp) {
3249 setverdict(pass);
3250 } else {
3251 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3252 }
3253 }
3254 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3255 if (tc.exp) {
3256 setverdict(pass);
3257 } else {
3258 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3259 }
3260 }
3261 [tc.exp] T.timeout {
3262 setverdict(fail, "Timeout waiting for EST IND");
3263 }
3264 [not tc.exp] T.timeout {
3265 setverdict(pass);
3266 }
3267 }
3268
3269 f_rsl_chan_deact();
3270 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3271 f_rslem_unregister(0, g_chan_nr);
3272}
3273testcase TC_rll_est_ind() runs on test_CT {
3274 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003275 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003276 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003277 /* normal SAPI0 establishment */
3278 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003279 /* SAPI 3 doesn't support contention resolution */
3280 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3281 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3282 /* normal SAPI3 establishment on main DCCH */
3283 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3284 /* normal SAPI3 establishment on SACCH */
3285 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3286 };
3287 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3288}
3289
3290/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3291private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3292 var RllTestCase tc := g_pars.spec.rll;
3293 var L1ctlDlMessage dl;
3294 timer T := 3.0;
3295
3296 f_l1_tune(L1CTL);
3297 RSL.clear;
3298
3299 /* activate the logical channel */
3300 f_est_dchan();
3301 L1CTL.clear;
3302
3303 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3304 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3305 T.start;
3306 alt {
3307 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3308 var LapdmFrame lapdm;
3309 var octetstring l2 := dl.payload.data_ind.payload;
3310 if (dl.dl_info.link_id.c == SACCH) {
3311 /* remove L1 header */
3312 l2 := substr(l2, 2, lengthof(l2)-2);
3313 }
3314 lapdm.ab := dec_LapdmFrameAB(l2);
3315 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3316 setverdict(pass);
3317 } else {
3318 repeat;
3319 }
3320 }
3321 [] L1CTL.receive { repeat; }
3322 [] T.timeout {
3323 setverdict(fail, "Timeout waiting for SABM");
3324 self.stop;
3325 }
3326 }
3327
3328 f_rsl_chan_deact();
3329 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3330 f_rslem_unregister(0, g_chan_nr);
3331}
3332testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3333 var RllTestCases tcs := {
3334 /* normal SAPI3 establishment on main DCCH */
3335 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3336 };
3337 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3338}
3339testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3340 var RllTestCases tcs := {
3341 /* normal SAPI3 establishment on SACCH */
3342 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3343 }
3344 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3345}
3346
3347/* altstep to receive a LAPDm frame matching the given template */
3348private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3349 var L1ctlDlMessage dl;
3350 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3351 var LapdmFrame lapdm;
3352 var octetstring l2 := dl.payload.data_ind.payload;
3353 if (dl.dl_info.link_id.c == SACCH) {
3354 /* remove L1 header */
3355 l2 := substr(l2, 2, lengthof(l2)-2);
3356 }
3357 if (ischosen(exp.ab)) {
3358 lapdm.ab := dec_LapdmFrameAB(l2);
3359 } else if (ischosen(exp.b4)) {
3360 lapdm.b4 := dec_LapdmFrameB4(l2);
3361 } else if (ischosen(exp.bbis)) {
3362 lapdm.bbis := dec_LapdmFrameBbis(l2);
3363 }
3364 log("Rx LAPDm ", lapdm);
3365 if (match(lapdm, exp)) {
3366 setverdict(pass);
3367 } else {
3368 repeat;
3369 }
3370 }
3371 [] L1CTL.receive { repeat; }
3372}
3373private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3374 timer T := t;
3375 T.start;
3376 alt {
3377 [] T.timeout {
3378 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3379 self.stop;
3380 }
3381 [] as_l1_exp_lapdm(exp);
3382 }
3383}
3384
3385/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3386private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3387 /* send SABM from MS -> BTS */
3388 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3389 /* expect RLL EST IND on Abis */
3390 alt {
3391 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3392 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3393 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3394 setverdict(fail, "Failing due to RSL_ERROR_IND");
3395 self.stop;
3396 }
3397 [] RSL.receive { repeat; }
3398 }
3399 /* expect UA from BTS -> MS */
3400 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3401}
3402
3403/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3404private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3405 var RllTestCase tc := g_pars.spec.rll;
3406
3407 f_l1_tune(L1CTL);
3408 RSL.clear;
3409
3410 /* activate the logical channel */
3411 f_est_dchan();
3412 L1CTL.clear;
3413
3414 /* first establish the link-layer */
3415 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3416
3417 /* then send the DISC */
3418 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3419 /* ... and expect the REL IND on the RSL side */
3420 alt {
3421 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3422 setverdict(pass);
3423 }
3424 }
3425
3426 /* release the channel */
3427 f_rsl_chan_deact();
3428 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3429 f_rslem_unregister(0, g_chan_nr);
3430}
3431testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3432 var RllTestCases tcs := {
3433 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3434 };
3435 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3436}
3437
3438testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3439 var RllTestCases tcs := {
3440 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3441 };
3442 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3443}
3444testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3445 var RllTestCases tcs := {
3446 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3447 };
3448 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3449}
3450testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3451 var RllTestCases tcs := {
3452 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3453 };
3454 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3455}
3456
3457/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3458private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3459 var RllTestCase tc := g_pars.spec.rll;
3460 f_l1_tune(L1CTL);
3461 RSL.clear;
3462
3463 /* activate the logical channel */
3464 f_est_dchan();
3465 L1CTL.clear;
3466
3467 /* first establish the link-layer */
3468 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3469
3470 /* then send the REL REQ via RSL */
3471 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3472 /* ... and expect the DISC on the Um side */
3473 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003474 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003475 /* FIXME: send a UA in resposne to the DISC */
3476 }
3477 }
3478
3479 /* release the channel */
3480 f_rsl_chan_deact();
3481 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3482 f_rslem_unregister(0, g_chan_nr);
3483}
3484testcase TC_rll_rel_req() runs on test_CT {
3485 var RllTestCases tcs := {
3486 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3487 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3488 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3489 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3490 };
3491 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3492}
3493
3494/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3495testcase TC_rll_data_req() runs on test_CT {
3496}
3497
3498/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3499testcase TC_rll_data_ind() runs on test_CT {
3500}
3501
3502/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3503private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3504 var RllTestCase tc := g_pars.spec.rll;
3505
3506 f_l1_tune(L1CTL);
3507 RSL.clear;
3508
3509 f_est_dchan();
3510 L1CTL.clear;
3511
3512 /* Send UNITDATA REQ on RSL side */
3513 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3514 /* Expect it to arrive on the other side */
3515 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003516 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003517 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003518 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003519 }
3520
3521 /* release the channel */
3522 f_rsl_chan_deact();
3523 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3524 f_rslem_unregister(0, g_chan_nr);
3525}
3526testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3527 var octetstring l3 := f_rnd_octstring(15);
3528 var RllTestCases tcs := {
3529 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3530 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3531 };
3532 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3533}
3534testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3535 var octetstring l3 := f_rnd_octstring(19);
3536 var RllTestCases tcs := {
3537 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3538 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3539 };
3540 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3541}
3542
3543/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3544private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3545 var RllTestCase tc := g_pars.spec.rll;
3546
3547 f_l1_tune(L1CTL);
3548 RSL.clear;
3549
3550 f_est_dchan();
3551 L1CTL.clear;
3552
3553 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003554 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003555 /* Expdct RLL UNITDATA IND on RSL side */
3556 alt {
3557 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3558 setverdict(pass);
3559 }
3560 [] RSL.receive { repeat; }
3561 }
3562
3563 /* release the channel */
3564 f_rsl_chan_deact();
3565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3566 f_rslem_unregister(0, g_chan_nr);
3567}
3568testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3569 var octetstring l3 := f_rnd_octstring(15);
3570 var RllTestCases tcs := {
3571 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3572 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3573 };
3574 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3575}
3576testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3577 var octetstring l3 := f_rnd_octstring(18);
3578 var RllTestCases tcs := {
3579 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3580 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3581 };
3582 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3583}
3584
Harald Weltee613f962018-04-18 22:38:16 +02003585/***********************************************************************
3586 * Encryption Related
3587 ***********************************************************************/
3588
3589/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3590function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3591 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3592 if (link_id.c == SACCH) {
3593 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3594 } else {
3595 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3596 }
3597}
3598
3599/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3600function f_unitdata_mo(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3601 timer T := 3.0;
3602 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3603 T.start;
3604 /* Expect RLL UNITDATA IND on RSL side */
3605 alt {
3606 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3607 setverdict(pass);
3608 }
3609 [] T.timeout {
3610 setverdict(fail, "Timeout waiting for UNIT_DATA_IND");
3611 }
3612 [] RSL.receive { repeat; }
3613 }
3614}
3615
3616/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3617function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3618 f_l1_tune(L1CTL);
3619 f_est_dchan(true);
3620
3621 /* now we actually need to transmit some data both ways to check if the encryption works */
3622 var L1ctlDlMessage dl;
3623
3624 var octetstring l3 := f_rnd_octstring(16);
3625 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3626
3627 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3628 f_unitdata_mt(link_id, l3);
3629
3630 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3631 f_unitdata_mo(link_id, l3);
3632
3633 /* release the channel */
3634 f_rsl_chan_deact();
3635 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3636 f_rslem_unregister(0, g_chan_nr);
3637}
3638testcase TC_chan_act_a51() runs on test_CT {
3639 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3640 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3641 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3642}
3643testcase TC_chan_act_a52() runs on test_CT {
3644 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3645 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3646 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3647}
3648testcase TC_chan_act_a53() runs on test_CT {
3649 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3650 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3651 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3652}
3653
3654
3655/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3656function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3657 /* L3 payload doesn't matter, as it is passed transparently */
3658 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3659 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3660 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3661
3662 f_l1_tune(L1CTL);
3663
3664 /* first establish a dedicated channel in the clear */
3665 f_est_dchan(false);
3666
3667 /* Establish ABM */
3668 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3669
3670 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3671 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3672 /* expect the L3 to arrive still unencrypted on the MS side */
3673 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3674
3675 /* configure L1 to apply ciphering */
3676 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3677 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3678
3679 /* send first ciphered I-frame in response */
3680 l3 := '0a0b0c0d'O;
3681 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3682 RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3));
3683
3684 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3685 * and hence enable encryption also on the downlink */
3686
3687 /* expect bi-directional communication work in encrypted mode */
3688 f_unitdata_mo(link_id, f_rnd_octstring(15));
3689 f_unitdata_mt(link_id, f_rnd_octstring(15));
3690
3691 /* release the channel */
3692 f_rsl_chan_deact();
3693 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3694 f_rslem_unregister(0, g_chan_nr);
3695}
3696testcase TC_encr_cmd_a51() runs on test_CT {
3697 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3698 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3699 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3700}
3701testcase TC_encr_cmd_a52() runs on test_CT {
3702 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3703 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3704 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3705}
3706testcase TC_encr_cmd_a53() runs on test_CT {
3707 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3708 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3709 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3710}
3711
3712private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3713 var LapdmFrame lf;
3714 var octetstring reenc;
3715
3716 /* decode the LAPDm frame */
3717 if (ischosen(exp_match.ab)) {
3718 lf.ab := dec_LapdmFrameAB(enc);
3719 } else {
3720 setverdict(fail, "unsupported frame type");
3721 self.stop;
3722 }
3723
3724 /* check if decoder result matches expectation */
3725 if (not match(lf, exp_match)) {
3726 setverdict(fail, name, ": decoded LAPDm doesn't match");
3727 } else {
3728 log(name, ": matched");
3729 setverdict(pass);
3730 }
3731
3732 /* test if re-encoded frame equals original input */
3733 reenc := enc_LapdmFrame(lf);
3734 if (enc != reenc) {
3735 setverdict(fail, name, ": re-encoded LAPDm frame doesn't match");
3736 } else {
3737 setverdict(pass);
3738 }
3739}
3740
3741testcase TC_lapdm_selftest() runs on test_CT {
3742 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3743 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3744 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3745 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3746 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3747 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3748 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3749}
3750
Harald Welte0472ab42018-03-12 15:02:26 +01003751
3752/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3753/* protocol error as per 44.006 */
3754/* link layer failure (repetition of I-frame N200 times without ACK */
3755/* repetition of SABM or DISC N200 times without ACK */
3756/* receptiom of SABM in multi-frame established state */
3757
3758
3759
3760
Harald Welte883340c2018-02-28 18:59:29 +01003761
Harald Welte68e495b2018-02-25 00:05:57 +01003762/* TODO Areas:
3763
3764* channel activation
3765** with BS_Power / MS_Power, bypassing power control loop
3766** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01003767** with timing advance from initial activation on
3768* mode modify
3769** encryption
3770** multirate
3771* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01003772** unsupported algorithm
3773* handover detection
3774* MS Power Control
3775* BS Power Control
3776* Physical Context
3777* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003778* CCCH Load Indication for PCH and RACH
3779* Delete Indication on AGCH overflow
3780* SMS Broadcast Req / Cmd / CBCH LOad Ind
3781* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003782* error handling
3783* discriminator error
3784** type error
3785** sequence error
3786** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003787* PCU interface
3788** TIME_IND from BTS->PCU
3789** DATA_IND from BTS->PCU
3790** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003791
3792*/
Harald Welte70767382018-02-21 12:16:40 +01003793
3794control {
3795 execute( TC_chan_act_stress() );
3796 execute( TC_chan_act_react() );
3797 execute( TC_chan_deact_not_active() );
3798 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003799 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003800 execute( TC_sacch_filling() );
3801 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003802 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003803 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003804 execute( TC_rach_content() );
3805 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003806 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003807 execute( TC_meas_res_sign_tchf() );
3808 execute( TC_meas_res_sign_tchh() );
3809 execute( TC_meas_res_sign_sdcch4() );
3810 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003811 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003812 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003813 execute( TC_paging_imsi_80percent() );
3814 execute( TC_paging_tmsi_80percent() );
3815 execute( TC_paging_imsi_200percent() );
3816 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003817 execute( TC_rsl_protocol_error() );
3818 execute( TC_rsl_mand_ie_error() );
3819 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003820 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003821 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003822 execute( TC_si_sched_2bis() );
3823 execute( TC_si_sched_2ter() );
3824 execute( TC_si_sched_2ter_2bis() );
3825 execute( TC_si_sched_2quater() );
3826 execute( TC_si_sched_13() );
3827 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003828 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003829 execute( TC_ipa_crcx_twice_not_active() );
3830 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003831 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003832 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003833
3834 execute( TC_pcu_act_req() );
3835 execute( TC_pcu_act_req_wrong_ts() );
3836 execute( TC_pcu_act_req_wrong_bts() );
3837 execute( TC_pcu_act_req_wrong_trx() );
3838 execute( TC_pcu_deact_req() );
3839 execute( TC_pcu_deact_req_wrong_ts() );
3840 execute( TC_pcu_ver_si13() );
3841 execute( TC_pcu_data_req_wrong_bts() );
3842 execute( TC_pcu_data_req_wrong_trx() );
3843 execute( TC_pcu_data_req_wrong_ts() );
3844 execute( TC_pcu_data_req_ts_inactive() );
3845 execute( TC_pcu_data_req_pdtch() );
3846 execute( TC_pcu_data_req_ptcch() );
3847 execute( TC_pcu_data_req_agch() );
3848 execute( TC_pcu_data_req_imm_ass_pch() );
3849 execute( TC_pcu_rach_content() );
3850 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003851
3852 execute( TC_dyn_osmo_pdch_act_deact() );
3853 execute( TC_dyn_osmo_pdch_unsol_deact() );
3854 execute( TC_dyn_osmo_pdch_double_act() );
3855 execute( TC_dyn_osmo_pdch_tchf_act() );
3856 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003857 execute( TC_dyn_ipa_pdch_act_deact() );
3858 execute( TC_dyn_ipa_pdch_tchf_act() );
3859 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3860 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003861
3862 execute( TC_rll_est_ind() );
3863 execute( TC_rll_est_req_DCCH_3() );
3864 execute( TC_rll_est_req_ACCH_3() );
3865 execute( TC_rll_rel_ind_DCCH_0() );
3866 execute( TC_rll_rel_ind_DCCH_3() );
3867 execute( TC_rll_rel_ind_ACCH_0() );
3868 execute( TC_rll_rel_ind_ACCH_3() );
3869 execute( TC_rll_rel_req() );
3870 execute( TC_rll_unit_data_req_DCCH() );
3871 execute( TC_rll_unit_data_req_ACCH() );
3872 execute( TC_rll_unit_data_ind_DCCH() );
3873 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02003874
3875 execute( TC_chan_act_a51() );
3876 execute( TC_chan_act_a52() );
3877 execute( TC_chan_act_a53() );
3878 execute( TC_encr_cmd_a51() );
3879 execute( TC_encr_cmd_a52() );
3880 execute( TC_encr_cmd_a53() );
3881
3882 execute( TC_lapdm_selftest() );
Harald Welte70767382018-02-21 12:16:40 +01003883}
3884
3885
3886}