blob: b77a70a7e2e16a0bdfbe997495b91f7462c8c558 [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) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001243 ul_meas.len := (3+8);
1244 ul_meas.supp_meas_info := {
1245 toa256_mean := l1p.timing_offset_256syms,
1246 toa256_min := ?,
1247 toa256_max := ?,
1248 toa256_std_dev := ?
1249 }
Harald Welte685d5982018-02-27 20:42:05 +01001250 }
Harald Welte70767382018-02-21 12:16:40 +01001251 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
1252 ul_meas.rxlev_f_u := ?;
1253 ul_meas.rxlev_s_u := ?;
1254 ul_meas.rxq_f_u := ?;
1255 ul_meas.rxq_s_u := ?;
1256 var template RSL_IE_BS_Power bs_power := {
1257 reserved := 0,
1258 epc := false,
1259 fpc := false,
1260 power_level := l1p.bs_power_level
1261 };
1262 var template RSL_IE_L1Info l1_info := {
1263 ms_power_lvl := l1p.ms_power_level,
1264 fpc := false,
1265 reserved := 0,
1266 actual_ta := l1p.ms_actual_ta
1267 };
1268 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
1269 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
1270 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1271 ?, t_toffs);
1272}
1273
1274/* verify we regularly receive measurement reports with incrementing numbers */
1275altstep as_meas_res() runs on ConnHdlr {
1276 var RSL_Message rsl;
1277 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1278 /* increment counter of next to-be-expected meas rep */
1279 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1280 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001281 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001282 repeat;
1283 }
1284 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001285 /* increment counter of next to-be-expected meas rep */
1286 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1287 if (g_first_meas_res) {
1288 g_first_meas_res := false;
1289 repeat;
1290 } else {
1291 setverdict(fail, "Received unspecific MEAS RES ", rsl);
1292 self.stop;
1293 }
Harald Welte70767382018-02-21 12:16:40 +01001294 }
1295 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
1296 setverdict(fail, "Received unexpected MEAS RES ", rsl);
1297 self.stop;
1298 }
1299 [] g_Tmeas_exp.timeout {
1300 setverdict(fail, "Didn't receive expected measurement result")
1301 self.stop;
1302 }
1303}
1304
Harald Weltee613f962018-04-18 22:38:16 +02001305private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1306 select (rsl_alg_id) {
1307 case (RSL_ALG_ID_A5_0) { return 0; }
1308 case (RSL_ALG_ID_A5_1) { return 1; }
1309 case (RSL_ALG_ID_A5_2) { return 2; }
1310 case (RSL_ALG_ID_A5_3) { return 3; }
1311 case (RSL_ALG_ID_A5_4) { return 4; }
1312 case (RSL_ALG_ID_A5_5) { return 5; }
1313 case (RSL_ALG_ID_A5_6) { return 6; }
1314 case (RSL_ALG_ID_A5_7) { return 7; }
1315 case else {
1316 setverdict(fail, "Unknwon Algorithm ID");
1317 self.stop;
1318 }
1319 }
1320}
1321
1322private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1323 select (rsl_alg_id) {
1324 case (RSL_ALG_ID_A5_1) { return '000'B; }
1325 case (RSL_ALG_ID_A5_2) { return '001'B; }
1326 case (RSL_ALG_ID_A5_3) { return '010'B; }
1327 case (RSL_ALG_ID_A5_4) { return '011'B; }
1328 case (RSL_ALG_ID_A5_5) { return '100'B; }
1329 case (RSL_ALG_ID_A5_6) { return '101'B; }
1330 case (RSL_ALG_ID_A5_7) { return '110'B; }
1331 case else {
1332 setverdict(fail, "Unknwon Algorithm ID");
1333 self.stop;
1334 }
1335 }
1336}
1337
1338
Harald Welte70767382018-02-21 12:16:40 +01001339/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001340private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001341 var GsmFrameNumber fn;
1342 var ImmediateAssignment imm_ass;
1343 var integer ra := 23;
1344
1345 fn := f_L1CTL_RACH(L1CTL, ra);
1346 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
1347 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
1348
1349 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001350 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001351
1352 /* Send IMM.ASS via CCHAN */
1353 var ChannelDescription ch_desc := {
1354 chan_nr := g_pars.chan_nr,
1355 tsc := 7,
1356 h := false,
1357 arfcn := mp_trx0_arfcn,
1358 maio_hsn := omit
1359 };
1360 var MobileAllocation ma := {
1361 len := 0,
1362 ma := ''B
1363 };
1364 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1365 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1366
1367 /* receive IMM.ASS on MS side */
1368 var ImmediateAssignment ia_um;
1369 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1370 /* enable dedicated mode */
1371 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001372 /* enable encryption, if requested */
1373 if (encr_enable) {
1374 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1375 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1376 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001377
1378 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001379}
1380
1381/* establish DChan, verify existance + contents of measurement reports */
1382function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001383 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001384 RSL.clear;
1385
Harald Welte5398d5e2018-03-10 19:00:24 +01001386 if (mp_bb_trxc_port != -1) {
1387 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1388 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001389
Harald Welte5398d5e2018-03-10 19:00:24 +01001390 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1391 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1392 } else {
1393 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1394 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1395 }
1396 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001397
1398 f_est_dchan();
1399
1400 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1401 * RSL measurement reports on Abis side */
1402 timer T := 8.0;
1403 T.start;
1404 alt {
1405 [] as_l1_sacch();
1406 [] as_meas_res();
1407 [] as_l1_dcch();
1408 [] L1CTL.receive { repeat; }
1409 [g_Tmeas_exp.running] T.timeout {
1410 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1411 * of any earlier errors, so if we reach this timeout, we're good */
1412 setverdict(pass);
1413 }
1414 [] T.timeout {
1415 setverdict(fail, "No MEAS RES received at all");
1416 }
1417 }
1418 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001419 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001420}
Harald Welte0472ab42018-03-12 15:02:26 +01001421
Harald Welte70767382018-02-21 12:16:40 +01001422testcase TC_meas_res_sign_tchf() runs on test_CT {
1423 var ConnHdlr vc_conn;
1424 var ConnHdlrPars pars;
1425 f_init(testcasename());
1426 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1427 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1428 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1429 vc_conn.done;
1430 }
Harald Welte294b0a22018-03-10 23:26:48 +01001431 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001432}
1433testcase TC_meas_res_sign_tchh() runs on test_CT {
1434 var ConnHdlr vc_conn;
1435 var ConnHdlrPars pars;
1436 f_init(testcasename());
1437 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1438 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1439 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1440 vc_conn.done;
1441 }
Harald Welte294b0a22018-03-10 23:26:48 +01001442 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001443}
1444testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1445 var ConnHdlr vc_conn;
1446 var ConnHdlrPars pars;
1447 f_init(testcasename());
1448 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1449 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1450 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1451 vc_conn.done;
1452 }
Harald Welte294b0a22018-03-10 23:26:48 +01001453 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001454}
1455testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1456 var ConnHdlr vc_conn;
1457 var ConnHdlrPars pars;
1458 f_init(testcasename());
1459 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1460 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1461 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1462 vc_conn.done;
1463 }
Harald Welte294b0a22018-03-10 23:26:48 +01001464 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001465}
Harald Welte685d5982018-02-27 20:42:05 +01001466testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1467 var ConnHdlr vc_conn;
1468 var ConnHdlrPars pars;
1469 f_init(testcasename());
1470 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1471 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1472 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1473 pars.l1_pars.toa256_enabled := true;
1474 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1475 vc_conn.done;
1476 }
Harald Welte294b0a22018-03-10 23:26:48 +01001477 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001478}
1479
Harald Welte70767382018-02-21 12:16:40 +01001480
Harald Welte0472ab42018-03-12 15:02:26 +01001481/* 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 +01001482private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001483 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001484 RSL.clear;
1485
1486 f_est_dchan();
1487 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001488 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001489
1490 timer T := 40.0;
1491 T.start;
1492 alt {
1493 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1494 setverdict(pass)
1495 }
1496 [] RSL.receive { repeat };
1497 [] T.timeout {
1498 setverdict(fail, "No CONN FAIL IND received");
1499 }
1500 }
1501 f_rsl_chan_deact();
1502}
1503testcase TC_conn_fail_crit() runs on test_CT {
1504 var ConnHdlr vc_conn;
1505 var ConnHdlrPars pars;
1506 f_init(testcasename());
1507 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1508 pars.t_guard := 60.0;
1509 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1510 vc_conn.done;
1511}
1512
Harald Welte93640c62018-02-25 16:59:33 +01001513/***********************************************************************
1514 * Paging
1515 ***********************************************************************/
1516
Harald Welte68e495b2018-02-25 00:05:57 +01001517function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1518 if (tmsi == 'FFFFFFFF'O) {
1519 return true;
1520 } else {
1521 return false;
1522 }
1523}
Harald Welte70767382018-02-21 12:16:40 +01001524
Harald Welte68e495b2018-02-25 00:05:57 +01001525altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1526runs on test_CT {
1527 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001528 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001529 repeat;
1530 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001531 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001532 var octetstring without_plen :=
1533 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1534 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1535 if (match(rr, tr_PAGING_REQ1)) {
1536 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1537 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1538 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1539 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1540 }
1541 } else if (match(rr, tr_PAGING_REQ2)) {
1542 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1543 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1544 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1545 }
1546 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1547 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1548 }
1549 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1550 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1551 }
1552 } else if (match(rr, tr_PAGING_REQ3)) {
1553 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1554 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1555 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1556 }
1557 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1558 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1559 }
1560 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1561 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1562 }
1563 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1564 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1565 }
1566 }
1567 repeat;
1568 }
1569}
1570
1571type record PagingTestCfg {
1572 boolean combined_ccch,
1573 integer bs_ag_blks_res,
1574 float load_factor,
1575 boolean exp_load_ind,
1576 boolean exp_overload,
1577 boolean use_tmsi
1578}
1579
1580type record PagingTestState {
1581 integer num_paging_sent,
1582 integer num_paging_rcv_msgs,
1583 integer num_paging_rcv_ids,
1584 integer num_overload
1585}
1586
1587/* receive + ignore RSL RF RES IND */
1588altstep as_rsl_res_ind() runs on test_CT {
1589 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1590 repeat;
1591 }
1592}
1593
1594/* Helper function for paging related testing */
1595private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1596 f_init(testcasename());
1597 f_init_l1ctl();
1598 f_l1_tune(L1CTL);
1599
1600 var PagingTestState st := {
1601 num_paging_sent := 0,
1602 num_paging_rcv_msgs := 0,
1603 num_paging_rcv_ids := 0,
1604 num_overload := 0
1605 };
1606
1607 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1608 var float max_pch_imsi_per_sec;
1609 if (cfg.use_tmsi) {
1610 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1611 } else {
1612 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1613 }
1614 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1615 var float interval := 1.0 / pch_blocks_per_sec;
1616 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1617
1618 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1619 /* build mobile Identity */
1620 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1621 if (cfg.use_tmsi) {
1622 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1623 } else {
1624 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1625 }
1626 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1627 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1628
1629 /* Send RSL PAGING COMMAND */
1630 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1631 st.num_paging_sent := st.num_paging_sent + 1;
1632
1633 /* Wait for interval to next PAGING COMMAND */
1634 timer T_itv := interval;
1635 T_itv.start;
1636 alt {
1637 /* check for presence of CCCH LOAD IND (paging load) */
1638 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1639 st.num_overload := st.num_overload + 1;
1640 repeat;
1641 }
1642 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1643 setverdict(fail, "Unexpected PCH Overload");
1644 }
1645 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1646 log("Rx LOAD_IND");
1647 /* FIXME: analyze/verify interval + contents */
1648 repeat;
1649 }
1650 /* check if paging requests arrive on Um side */
1651 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1652 [] L1CTL.receive { repeat; }
1653 [] T_itv.timeout { }
1654 [] as_rsl_res_ind();
1655 }
1656 }
1657
1658 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1659 timer T_wait := 18.0;
1660 T_wait.start;
1661 alt {
1662 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1663 [] L1CTL.receive { repeat; }
1664 /* 65535 == empty paging queue, we can terminate*/
1665 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1666 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1667 [] T_wait.timeout {
1668 setverdict(fail, "Waiting for empty paging queue");
1669 }
1670 [] as_rsl_res_ind();
1671 }
1672
Harald Welte294b0a22018-03-10 23:26:48 +01001673 f_shutdown();
1674
Harald Welte68e495b2018-02-25 00:05:57 +01001675 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1676 " rcvd_ids=", st.num_paging_rcv_ids);
1677 return st;
1678}
1679
1680/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1681 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1682 * - that CCCH LOAD IND (PCH) are being generated
1683 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1684testcase TC_paging_imsi_80percent() runs on test_CT {
1685 var PagingTestCfg cfg := {
1686 combined_ccch := true,
1687 bs_ag_blks_res := 1,
1688 load_factor := 0.8,
1689 exp_load_ind := true,
1690 exp_overload := false,
1691 use_tmsi := false
1692 };
1693 var PagingTestState st := f_TC_paging(cfg);
1694 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1695 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1696 st.num_paging_rcv_ids);
1697 } else {
1698 setverdict(pass);
1699 }
1700}
1701
1702/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1703 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1704 * - that CCCH LOAD IND (PCH) are being generated
1705 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1706testcase TC_paging_tmsi_80percent() runs on test_CT {
1707 var PagingTestCfg cfg := {
1708 combined_ccch := true,
1709 bs_ag_blks_res := 1,
1710 load_factor := 0.8,
1711 exp_load_ind := true,
1712 exp_overload := false,
1713 use_tmsi := true
1714 };
1715 var PagingTestState st := f_TC_paging(cfg);
1716 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1717 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1718 st.num_paging_rcv_ids);
1719 } else {
1720 setverdict(pass);
1721 }
1722}
1723
1724/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1725 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1726 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1727 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1728testcase TC_paging_imsi_200percent() runs on test_CT {
1729 var PagingTestCfg cfg := {
1730 combined_ccch := true,
1731 bs_ag_blks_res := 1,
1732 load_factor := 2.0,
1733 exp_load_ind := true,
1734 exp_overload := true,
1735 use_tmsi := false
1736 };
1737 var PagingTestState st := f_TC_paging(cfg);
1738 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1739 * slots and will fully drain that buffer before returning */
1740 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1741 if (not match(st.num_paging_rcv_ids, tpl)) {
1742 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1743 } else {
1744 setverdict(pass);
1745 }
1746}
1747
1748/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1749 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1750 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1751 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1752testcase TC_paging_tmsi_200percent() runs on test_CT {
1753 var PagingTestCfg cfg := {
1754 combined_ccch := true,
1755 bs_ag_blks_res := 1,
1756 load_factor := 2.0,
1757 exp_load_ind := true,
1758 exp_overload := true,
1759 use_tmsi := true
1760 };
1761 var PagingTestState st := f_TC_paging(cfg);
1762 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1763 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001764 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001765 if (not match(st.num_paging_rcv_ids, tpl)) {
1766 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1767 } else {
1768 setverdict(pass);
1769 }
1770}
1771
1772
Harald Welte93640c62018-02-25 16:59:33 +01001773/***********************************************************************
1774 * Immediate Assignment / AGCH
1775 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02001776const MobileAllocation c_MA_null := {
1777 len := 0,
1778 ma := ''B
1779}
Harald Welte93640c62018-02-25 16:59:33 +01001780
Harald Weltee8d750e2018-06-10 21:41:35 +02001781template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
1782 uint12_t arfcn := 871) := {
1783 chan_nr := chan_nr,
1784 tsc := tsc,
1785 h := false,
1786 arfcn := arfcn,
1787 maio_hsn := omit
1788}
1789
1790private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
1791 return int2str(num_tx) & " sent, "
1792 & int2str(num_rx) & " received, "
1793 & int2str(num_del) & " deleted";
1794}
1795
1796private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
1797 var L1ctlDlMessage l1_dl;
1798 timer T := 10.0;
1799 var integer num_tx := 0;
1800 var integer num_rx := 0;
1801 var integer num_del := 0;
1802 var charstring res_str;
1803 var float rx_ratio;
1804
Harald Welte68e495b2018-02-25 00:05:57 +01001805 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02001806 f_init_l1ctl();
1807 f_l1_tune(L1CTL);
1808
1809 for (var integer i := 0; i < num_total; i := i+1) {
1810 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
1811 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
1812 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01001813 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02001814 num_tx := num_tx+1;
1815 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01001816 }
1817 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02001818 T.start;
1819 alt {
1820 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
1821 num_del := num_del+1;
1822 repeat;
1823 }
1824 [] RSL_CCHAN.receive {
1825 repeat;
1826 }
1827 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
1828 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1829 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
1830 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
1831 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
1832 //setverdict(fail, "Unexpected IMM-ASS values on AGCH: ", rr);
1833 //self.stop;
1834 } else {
1835 num_rx := num_rx+1;
1836 }
1837 repeat;
1838 }
1839 [] L1CTL.receive { repeat; }
1840 [] T.timeout { }
1841 }
1842 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
1843 log("AGCH test: " & res_str);
1844 if (num_rx + num_del != num_tx) {
1845 setverdict(fail, "RX + DEL != TX ?!?: " & res_str);
1846 }
1847 rx_ratio := int2float(num_rx) / int2float(num_tx);
1848 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
1849 setverdict(fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
1850 } else {
1851 setverdict(pass);
1852 }
Harald Welte68e495b2018-02-25 00:05:57 +01001853}
1854
Harald Weltee8d750e2018-06-10 21:41:35 +02001855/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
1856testcase TC_imm_ass_1000_20ms() runs on test_CT {
1857 f_TC_imm_ass(1000, 0.02, 0.25);
1858}
1859
1860/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
1861testcase TC_imm_ass_200_0ms() runs on test_CT {
1862 f_TC_imm_ass(200, 0.0, 0.05);
1863}
1864
1865/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
1866testcase TC_imm_ass_200_76ms() runs on test_CT {
1867 f_TC_imm_ass(150, 0.076, 1.00);
1868}
1869
1870
1871
Harald Welte48494ca2018-02-25 16:59:50 +01001872/***********************************************************************
1873 * BCCH
1874 ***********************************************************************/
1875
1876/* tuple of Frame Number + decoded SI */
1877type record SystemInformationFn {
1878 GsmFrameNumber frame_number,
1879 SystemInformation si
1880}
1881
1882/* an arbitrary-length vector of decoded SI + gsmtap header */
1883type record of SystemInformationFn SystemInformationVector;
1884
1885/* an array of SI-vectors indexed by TC value */
1886type SystemInformationVector SystemInformationVectorPerTc[8];
1887
1888/* determine if a given SI vector contains given SI type at least once */
1889function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1890 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1891 var integer fn_mod51 := arr[i].frame_number mod 51;
1892 if (not bcch_ext and fn_mod51 == 2 or
1893 bcch_ext and fn_mod51 == 6) {
1894 if (arr[i].si.header.message_type == key) {
1895 return true;
1896 }
1897 }
1898 }
1899 return false;
1900}
1901
1902/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1903function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1904 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1905 setverdict(fail, "No ", key, " in TC=", tc, "!");
1906 }
1907}
1908
1909/* check if a given SI vector contains given SI type at least once on any TC */
1910function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1911 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1912 if (f_si_vecslot_contains(arr[tc], key) or
1913 f_si_vecslot_contains(arr[tc], key, true)) {
1914 return true;
1915 }
1916 }
1917 return false;
1918}
1919
1920/* determine if a given SI vector contains given SI type at least N of M times */
1921function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1922 var integer count := 0;
1923 if (sizeof(arr) < m) {
1924 setverdict(fail, "Error: Insufficient SI in array");
1925 self.stop;
1926 }
1927 for (var integer i:= 0; i < m; i := i + 1) {
1928 var integer fn_mod51 := arr[i].frame_number mod 51;
1929 if (not bcch_ext and fn_mod51 == 2 or
1930 bcch_ext and fn_mod51 == 6) {
1931 if (arr[i].si.header.message_type == key) {
1932 count := count + 1;
1933 }
1934 }
1935 }
1936 if (count >= n) {
1937 return true;
1938 } else {
1939 return false;
1940 }
1941}
1942
1943/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1944function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1945 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1946 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1947 }
1948}
1949
1950/* determine if a given SI vector contains given SI type at least once */
1951function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1952 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1953 var integer fn_mod51 := arr[i].frame_number mod 51;
1954 if (not bcch_ext and fn_mod51 == 2 or
1955 bcch_ext and fn_mod51 == 6) {
1956 if (arr[i].si.header.message_type != key) {
1957 return false;
1958 }
1959 }
1960 }
1961 return true;
1962}
1963
1964/* ensure a given TC slot of the SI vector contains only given SI type */
1965function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1966 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1967 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1968 }
1969}
1970
1971/* SI configuration of cell, against which we validate actual SI messages */
1972type set SystemInformationConfig {
1973 boolean bcch_extended,
1974 boolean si1_present,
1975 boolean si2bis_present,
1976 boolean si2ter_present,
1977 boolean si2quater_present,
1978 boolean si7_present,
1979 boolean si8_present,
1980 boolean si9_present,
1981 boolean si13_present,
1982 boolean si13alt_present,
1983 boolean si15_present,
1984 boolean si16_present,
1985 boolean si17_present,
1986 boolean si2n_present,
1987 boolean si21_present,
1988 boolean si22_present
1989}
1990
1991/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1992function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1993 var integer i;
1994 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1995 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001996 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001997 }
1998 }
1999 if (cfg.si1_present) {
2000 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2001 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2002 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2003 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2004 /* make sure *ALL* contain SI1 */
2005 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2006 }
2007 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2008 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2009 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2010 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2011 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2012 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2013
2014 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2015 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2016 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2017 * consecutive occurrences of TC = 4. */
2018 if (cfg.si2bis_present and not cfg.si2ter_present) {
2019 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2020 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2021 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2022 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2023 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2024 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2025 }
2026
2027 if (cfg.si7_present or cfg.si8_present) {
2028 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2029 * if System Information type 4 does not contain all information needed for cell
2030 * selection and reselection. */
2031 if (not cfg.bcch_extended) {
2032 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2033 }
2034 if (cfg.si7_present) {
2035 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2036 }
2037 if (cfg.si8_present) {
2038 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2039 }
2040 }
2041
2042 if (cfg.si2quater_present) {
2043 /* iii) System information type 2 quater is sent if needed, as determined by the system
2044 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2045 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2046 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2047 * within any of 4 consecutive occurrences of TC = 5. */
2048 if (not (cfg.bcch_extended)) {
2049 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2050 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2051 } else {
2052 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2053 }
2054 } else {
2055 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2056 }
2057 }
2058 if (cfg.si9_present) {
2059 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2060 * in system information type 3 as defined in 3GPP TS 44.018. */
2061 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2062 }
2063 if (cfg.si13_present) {
2064 /* vii) System Information type 13 is only related to the GPRS service. System Information
2065 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2066 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2067 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2068 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2069 * within any of 4 consecutive occurrences of TC=4. */
2070 if (not cfg.bcch_extended) {
2071 log("not-bccch-extended");
2072 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2073 } else {
2074 log("bccch-extended");
2075 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2076 }
2077 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
2078 setverdict(fail, "Cannot have SI13alt and SI13");
2079 }
2080 }
2081 if (cfg.si16_present or cfg.si17_present) {
2082 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2083 * should not be sent in a cell where network sharing is used (see rule xv). */
2084 if (cfg.si22_present) {
2085 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2086 }
2087 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
2088 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2089 }
2090 if (not cfg.bcch_extended) {
2091 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2092 }
2093 if (cfg.si16_present) {
2094 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2095 }
2096 if (cfg.si17_present) {
2097 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2098 }
2099 }
2100
2101 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2102 * broadcast information. The frequency with which they are sent is determined by the
2103 * system operator. System Information type 9 identifies the scheduling of System
2104 * Information type 18 and 20 messages. */
2105
2106 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2107 * Information Type 19 is present, then its scheduling shall be indicated in System
2108 * Information Type 9. */
2109
2110 if (cfg.si15_present) {
2111 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2112 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2113 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2114 * 4 consecutive occurrences of TC = 1. */
2115 if (not cfg.bcch_extended) {
2116 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2117 } else {
2118 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2119 }
2120 }
2121 if (cfg.si13alt_present) {
2122 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2123 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2124 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2125 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2126 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2127 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2128 * of TC = 4. */
2129 if (cfg.si13_present) {
2130 testcase.stop("Error: Cannot have SI13alt and SI13");
2131 }
2132 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
2133 setverdict(fail, "Cannot have SI13alt and SI13");
2134 }
2135 if (not cfg.bcch_extended) {
2136 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2137 } else {
2138 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2139 }
2140 }
2141 if (cfg.si2n_present) {
2142 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2143 * as determined by the system operator. In the case that the message is sent on the
2144 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2145 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2146 * consecutive occurrences of TC = 4. */
2147 if (not cfg.bcch_extended) {
2148 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2149 } else {
2150 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2151 }
2152 }
2153 if (cfg.si21_present) {
2154 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2155 * determined by the system operator. If Extended Access Barring is in use in the cell
2156 * then this message is sent at least once within any of 4 consecutive occurrences of
2157 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2158 * cell then this message shall only be sent on BCCH Ext. */
2159 if (not cfg.bcch_extended) {
2160 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2161 } else {
2162 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2163 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
2164 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
2165 }
2166 }
2167 }
2168 if (cfg.si22_present) {
2169 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2170 * should not be sent in a cell where SoLSA is used (see rule viii). System
2171 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2172 * =2 and TC=6. */
2173 if (cfg.si16_present or cfg.si17_present) {
2174 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2175 }
2176 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2177 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2178 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2179 }
2180 if (not cfg.bcch_extended) {
2181 testcase.stop("Error: SI22 requires BCCH Extd!");
2182 } else {
2183 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2184 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2185 }
2186 }
2187}
2188
2189/* sample Systme Information for specified duration via L1CTL */
2190function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2191 timer T := duration;
2192 var SystemInformationVectorPerTc si_per_tc;
2193 var L1ctlDlMessage l1_dl;
2194
2195 /* initialize all per-TC vectors empty */
2196 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2197 si_per_tc[i] := {};
2198 }
2199
2200 /* flush all previous L1 queued msgs */
2201 pt.clear;
2202
2203 T.start;
2204 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002205 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002206 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2207 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2208 log("Ignoring non-RR SI ", l1_dl);
2209 repeat;
2210 }
2211 var SystemInformationFn sig := {
2212 frame_number := l1_dl.dl_info.frame_nr,
2213 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2214 }
2215 var integer tc := f_gsm_compute_tc(sig.frame_number);
2216 log("SI received at TC=", tc, ": ", sig.si);
2217 /* append to the per-TC bucket */
2218 si_per_tc[tc] := si_per_tc[tc] & { sig };
2219 repeat;
2220 }
2221 [] pt.receive { repeat; }
2222 [] T.timeout { }
2223 }
2224
2225 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2226 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2227 }
2228 log("si_per_tc=", si_per_tc);
2229 return si_per_tc;
2230}
2231
2232/* helper function: Set given SI via RSL + validate scheduling.
2233 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2234function f_TC_si_sched() runs on test_CT {
2235 var SystemInformationVectorPerTc si_per_tc;
2236 f_init_l1ctl();
2237 f_l1_tune(L1CTL);
2238
2239 /* Sample + Validate Scheduling */
2240 si_per_tc := f_l1_sample_si(L1CTL);
2241 f_validate_si_scheduling(si_cfg, si_per_tc);
2242
2243 setverdict(pass);
2244}
2245
2246testcase TC_si_sched_default() runs on test_CT {
2247 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002248 /* 2+3+4 are mandatory and set in f_init() */
2249 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002250 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002251}
2252
2253testcase TC_si_sched_1() runs on test_CT {
2254 f_init();
2255 si_cfg.si1_present := true;
2256 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002257 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002258 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002259}
2260
2261testcase TC_si_sched_2bis() runs on test_CT {
2262 f_init();
2263 si_cfg.si2bis_present := true;
2264 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2265 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002266 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002267}
2268
2269testcase TC_si_sched_2ter() runs on test_CT {
2270 f_init();
2271 si_cfg.si2ter_present := true;
2272 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2273 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002274 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002275}
2276
2277testcase TC_si_sched_2ter_2bis() runs on test_CT {
2278 f_init();
2279 si_cfg.si2bis_present := true;
2280 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2281 si_cfg.si2ter_present := true;
2282 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2283 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002284 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002285}
2286
2287testcase TC_si_sched_2quater() runs on test_CT {
2288 f_init();
2289 si_cfg.si2quater_present := true;
2290 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2291 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002292 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002293}
2294
2295testcase TC_si_sched_13() runs on test_CT {
2296 f_init();
2297 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002298 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002299 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002300 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002301}
2302
2303testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2304 f_init();
2305 si_cfg.si2bis_present := true;
2306 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2307 si_cfg.si2ter_present := true;
2308 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2309 si_cfg.si2quater_present := true;
2310 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2311 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002312 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002313 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002314 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002315}
2316
2317
Harald Welte68e495b2018-02-25 00:05:57 +01002318testcase TC_bcch_info() runs on test_CT {
2319 f_init(testcasename());
2320 /* FIXME: enable / disable individual BCCH info */
2321 //ts_RSL_BCCH_INFO(si_type, info);
2322 /* expect no ERROR REPORT after either of them *
2323 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002324 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002325}
2326
Harald Welte93640c62018-02-25 16:59:33 +01002327/***********************************************************************
2328 * Low-Level Protocol Errors / ERROR REPORT
2329 ***********************************************************************/
2330
Harald Welte01d982c2018-02-25 01:31:40 +01002331private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2332 timer T := 5.0;
2333 T.start;
2334 alt {
2335 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2336 setverdict(pass);
2337 }
2338 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2339 setverdict(fail, "Wrong cause in RSL ERR REP");
2340 }
2341 [] RSL_CCHAN.receive {
2342 repeat;
2343 }
2344 [] T.timeout {
2345 setverdict(fail, "Timeout waiting for RSL ERR REP");
2346 }
2347 }
2348}
2349
2350/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2351testcase TC_rsl_protocol_error() runs on test_CT {
2352 f_init(testcasename());
2353 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2354 rsl.ies := omit;
2355 RSL_CCHAN.send(ts_RSL_UD(rsl));
2356
2357 f_exp_err_rep(RSL_ERR_PROTO);
2358}
2359
2360/* Provoke a mandatory IE error and match on ERROR REPORT */
2361testcase TC_rsl_mand_ie_error() runs on test_CT {
2362 f_init(testcasename());
2363
2364 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2365 rsl.ies := { rsl.ies[0] };
2366 RSL_CCHAN.send(ts_RSL_UD(rsl));
2367
2368 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2369}
2370
2371/* Provoke an IE content error and match on ERROR REPORT */
2372testcase TC_rsl_ie_content_error() runs on test_CT {
2373 f_init(testcasename());
2374 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2375 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2376 RSL_CCHAN.send(ts_RSL_UD(rsl));
2377
2378 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2379}
2380
Harald Welte93640c62018-02-25 16:59:33 +01002381/***********************************************************************
2382 * IPA CRCX/MDCX/DLCS media stream handling
2383 ***********************************************************************/
2384
Harald Weltea871a382018-02-25 02:03:14 +01002385/* Send IPA DLCX to inactive lchan */
2386function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002387 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2388 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002389}
2390testcase TC_ipa_dlcx_not_active() runs on test_CT {
2391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2392 f_init(testcasename());
2393 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2394 vc_conn.done;
2395}
Harald Welte68e495b2018-02-25 00:05:57 +01002396
Harald Weltea3f1df92018-02-25 12:49:55 +01002397/* Send IPA CRCX twice to inactive lchan */
2398function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2399 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2400 "IPA CRCX ACK");
2401 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2402 "IPA CRCX NACK");
2403}
2404testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2405 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2406 f_init(testcasename());
2407 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2408 vc_conn.done;
2409}
2410
2411/* Regular sequence of CRCX/MDCX/DLCX */
2412function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2413 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2414 "IPA CRCX ACK");
2415 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2416 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2417 var uint7_t rtp_pt2 := f_rnd_int(127);
2418 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2419 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2420 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2421 "IPA MDCX ACK");
2422 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2423 "IPA DLCX ACK");
2424}
2425testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2426 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2427 f_init(testcasename());
2428 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2429 vc_conn.done;
2430}
2431
Harald Welte3ae11da2018-02-25 13:36:06 +01002432/* Sequence of CRCX, 2x MDCX, DLCX */
2433function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2434 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2435 "IPA CRCX ACK");
2436 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2437 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2438 var uint7_t rtp_pt2 := f_rnd_int(127);
2439 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2440 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2441 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2442 "IPA MDCX ACK");
2443 /* Second MDCX */
2444 remote_ip := f_rnd_int(c_UINT32_MAX);
2445 remote_port := f_rnd_int(c_UINT16_MAX);
2446 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2447 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2448 "IPA MDCX ACK");
2449 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2450 "IPA DLCX ACK");
2451}
2452testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2454 f_init(testcasename());
2455 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2456 vc_conn.done;
2457}
2458
Harald Welte9912eb52018-02-25 13:30:15 +01002459/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2460function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2461 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2462 "IPA CRCX NACK");
2463}
2464testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2465 var ConnHdlrPars pars;
2466 var ConnHdlr vc_conn;
2467 f_init(testcasename());
2468
2469 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2470 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2471 vc_conn.done;
2472
2473 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2474 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2475 vc_conn.done;
2476}
2477
Harald Weltea3f1df92018-02-25 12:49:55 +01002478
Harald Welte883340c2018-02-28 18:59:29 +01002479/***********************************************************************
2480 * PCU Socket related tests
2481 ***********************************************************************/
2482
2483private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2484runs on test_CT {
2485 timer T := 3.0;
2486
2487 /* we don't expect any RTS.req before PDCH are active */
2488 T.start;
2489 alt {
2490 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2491 setverdict(fail, "PCU RTS.req before PDCH active?");
2492 self.stop;
2493 }
2494 [] PCU.receive { repeat; }
2495 [] T.timeout { }
2496 }
2497
2498 /* Send PDCH activate request for known PDCH timeslot */
2499 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2500
2501 /* we now expect RTS.req for this timeslot (only) */
2502 T.start;
2503 alt {
2504 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2505 setverdict(pass);
2506 }
2507 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2508 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2509 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2510 self.stop;
2511 }
2512 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2513 setverdict(fail, "RTS.req for wrong TRX/TS");
2514 self.stop;
2515 }
2516 [] PCU.receive { repeat; }
2517 [exp_success] T.timeout {
2518 setverdict(fail, "Timeout waiting for PCU RTS.req");
2519 }
2520 [not exp_success] T.timeout {
2521 setverdict(pass);
2522 }
2523 }
2524}
2525
2526private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2527runs on test_CT {
2528 timer T := 3.0;
2529
2530 /* Send PDCH activate request for known PDCH timeslot */
2531 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2532
2533 PCU.clear;
2534 /* we now expect no RTS.req for this timeslot */
2535 T.start;
2536 alt {
2537 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2538 setverdict(fail, "Received unexpected PCU RTS.req");
2539 self.stop;
2540 }
2541 [] PCU.receive { repeat; }
2542 [] T.timeout {
2543 setverdict(pass);
2544 }
2545 }
2546}
2547
2548/* PDCH activation via PCU socket; check for presence of RTS.req */
2549testcase TC_pcu_act_req() runs on test_CT {
2550 f_init();
2551 f_TC_pcu_act_req(0, 0, 7, true);
2552}
2553
2554/* PDCH activation via PCU socket on non-PDCU timeslot */
2555testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2556 f_init();
2557 f_TC_pcu_act_req(0, 0, 1, false);
2558}
2559
2560/* PDCH activation via PCU socket on wrong BTS */
2561testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2562 f_init();
2563 f_TC_pcu_act_req(23, 0, 7, false);
2564}
2565
2566/* PDCH activation via PCU socket on wrong TRX */
2567testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2568 f_init();
2569 f_TC_pcu_act_req(0, 23, 7, false);
2570}
2571
2572/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2573testcase TC_pcu_deact_req() runs on test_CT {
2574 f_init();
2575 /* Activate PDCH */
2576 f_TC_pcu_act_req(0, 0, 7, true);
2577 f_sleep(1.0);
2578 /* and De-Activate again */
2579 f_TC_pcu_deact_req(0, 0, 7);
2580}
2581
2582/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2583testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2584 f_init();
2585 f_TC_pcu_deact_req(0, 0, 1);
2586}
2587
2588/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2589testcase TC_pcu_ver_si13() runs on test_CT {
2590 const octetstring si13 := '00010203040506070909'O;
2591 var PCUIF_send_data sd;
2592 timer T:= 3.0;
2593 f_init();
2594
2595 /* Set SI13 via RSL */
2596 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2597 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2598 T.start;
2599 alt {
2600 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2601 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2602 setverdict(pass);
2603 } else {
2604 repeat;
2605 }
2606 }
2607 [] PCU.receive { repeat; }
2608 [] T.timeout {
2609 setverdict(fail, "Timeout waiting for SI13");
2610 self.stop;
2611 }
2612 }
2613}
2614
2615private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2616
2617/* helper function to send a PCU DATA.req */
2618private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2619 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2620runs on test_CT
2621{
2622 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2623 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2624}
2625
2626/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2627private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2628 PCUIF_Sapi sapi, octetstring data)
2629runs on test_CT
2630{
2631 var PCUIF_send_data sd;
2632
2633 timer T := 3.0;
2634 T.start;
2635 alt {
2636 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2637 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2638 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2639 sd.data.u.rts_req.fn, sapi, data);
2640 }
2641 [] PCU.receive { repeat; }
2642 [] T.timeout {
2643 setverdict(fail, "Timeout waiting for RTS.ind");
2644 }
2645 }
2646}
2647
2648/* Send DATA.req on invalid BTS */
2649testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2650 f_init();
2651 f_TC_pcu_act_req(0, 0, 7, true);
2652 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2653 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2654 f_sleep(10.0);
2655}
2656
2657/* Send DATA.req on invalid TRX */
2658testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2659 f_init();
2660 f_TC_pcu_act_req(0, 0, 7, true);
2661 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2662 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2663 f_sleep(10.0);
2664}
2665
2666/* Send DATA.req on invalid timeslot */
2667testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2668 f_init();
2669 f_TC_pcu_act_req(0, 0, 7, true);
2670 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2671 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2672 f_sleep(10.0);
2673}
2674
2675/* Send DATA.req on timeslot that hasn't been activated */
2676testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2677 f_init();
2678 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2679 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2680 f_sleep(2.0);
2681}
2682
2683testcase TC_pcu_data_req_pdtch() runs on test_CT {
2684 f_init();
2685 f_TC_pcu_act_req(0, 0, 7, true);
2686 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2687 /* FIXME: how to check this was actually sent */
2688 f_sleep(2.0);
2689}
2690
2691testcase TC_pcu_data_req_ptcch() runs on test_CT {
2692 f_init();
2693 f_TC_pcu_act_req(0, 0, 7, true);
2694 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2695 /* FIXME: how to check this was actually sent */
2696 f_sleep(2.0);
2697}
2698
2699/* Send AGCH from PCU; check it appears on Um side */
2700testcase TC_pcu_data_req_agch() runs on test_CT {
2701 timer T := 3.0;
2702 f_init();
2703 f_init_l1ctl();
2704 f_l1_tune(L1CTL);
2705
2706 f_TC_pcu_act_req(0, 0, 7, true);
2707 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2708
2709 T.start;
2710 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002711 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002712 setverdict(pass);
2713 }
2714 [] L1CTL.receive { repeat; }
2715 [] T.timeout {
2716 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2717 }
2718 }
2719}
2720
2721/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2722testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2723 var octetstring imm_ass := f_rnd_octstring(23);
2724 f_init();
2725 f_init_l1ctl();
2726 f_l1_tune(L1CTL);
2727
2728 /* append 3 last imsi digits so BTS can compute pagng group */
2729 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2730
2731 timer T := 0.5;
2732 T.start;
2733 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002734 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002735 /* TODO: verify paging group */
2736 setverdict(pass);
2737 }
2738 [] L1CTL.receive { repeat; }
2739 [] T.timeout {
2740 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2741 }
2742 }
2743}
2744
2745/* Send RACH from Um side, expect it to show up on PCU socket */
2746testcase TC_pcu_rach_content() runs on test_CT {
2747 f_init();
2748 f_init_l1ctl();
2749 f_l1_tune(L1CTL);
2750
2751 var GsmFrameNumber fn_last := 0;
2752 for (var integer i := 0; i < 1000; i := i+1) {
2753 var OCT1 ra := f_rnd_ra_ps();
2754 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2755 if (fn == fn_last) {
2756 setverdict(fail, "Two RACH in same FN?!?");
2757 self.stop;
2758 }
2759 fn_last := fn;
2760
2761 timer T := 2.0;
2762 T.start;
2763 alt {
2764 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2765 T.stop;
2766 }
2767 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2768 setverdict(fail, "Unexpected RACH IND");
2769 self.stop;
2770 }
2771 [] PCU.receive { repeat; }
2772 [] T.timeout {
2773 setverdict(fail, "Timeout waiting for RACH IND");
2774 self.stop;
2775 }
2776 }
2777 }
2778 setverdict(pass);
2779}
2780
2781private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2782 var integer strlen := lengthof(str);
2783 for (var integer i := 0; i < len-strlen; i := i+1) {
2784 str := str & pad;
2785 }
2786 return str;
2787}
2788
2789/* Send PAGING via RSL, expect it to shw up on PCU socket */
2790testcase TC_pcu_paging_from_rsl() runs on test_CT {
2791 f_init();
2792
2793 for (var integer i := 0; i < 100; i := i+1) {
2794 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2795 timer T := 3.0;
2796 if (i < 50) {
2797 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2798 } else {
2799 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2800 }
2801 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2802 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2803 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2804
2805 /* Send RSL PAGING COMMAND */
2806 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2807 T.start;
2808 alt {
2809 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2810 }
2811 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2812 setverdict(fail, "Unexpected PAGING REQ");
2813 self.stop;
2814 }
2815 [] PCU.receive { repeat; }
2816 [] T.timeout {
2817 setverdict(fail, "Timeout waiting for PAGING REQ");
2818 self.stop;
2819 }
2820 }
2821 }
2822 setverdict(pass);
2823}
2824
Harald Welte3d04ae62018-04-04 20:29:05 +02002825/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002826 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002827 ***********************************************************************/
2828
2829private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2830runs on ConnHdlr {
2831 var PCUIF_send_data sd;
2832 /* Expect BTS to immediately acknowledge activation as PDCH */
2833 PCU.clear;
2834 f_rsl_chan_act(g_pars.chan_mode);
2835 /* expect INFO_IND on PCU interface listing TS as PDCH */
2836 alt {
2837 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2838 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2839 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2840 self.stop;
2841 }
2842 }
2843 [] PCU.receive { repeat; }
2844 }
2845 /* try to activate this PDCH from the PCU point of view */
2846 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2847 /* FIXME: is there a response? */
2848}
2849
2850private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2851runs on ConnHdlr {
2852 var PCUIF_send_data sd;
2853 /* Send RSL CHAN REL (deactivate) */
2854 PCU.clear;
2855 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2856 /* expect BTS to ask PCU to deactivate the channel */
2857 alt {
2858 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2859 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2860 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2861 self.stop;
2862 }
2863 }
2864 [] PCU.receive { repeat; }
2865 }
2866 /* Emulate PCU asking BTS to deactivate PDCH */
2867 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2868 alt {
2869 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2870 setverdict(pass);
2871 }
2872 [] RSL.receive { repeat; }
2873 }
2874}
2875
2876/* Activate Osmocom-style dynamic PDCH from BSC side */
2877function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2878 var PCUIF_Message first_info;
2879 var integer ts_nr := g_chan_nr.tn;
2880 var integer trx_nr := 0;
2881 var integer bts_nr := 0;
2882 var integer pcu_conn_id := -1;
2883
2884 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2885
2886 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2887 f_sleep(3.0);
2888 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2889 setverdict(pass);
2890}
2891testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2892 var ConnHdlrPars pars;
2893 var ConnHdlr vc_conn;
2894 f_init(testcasename());
2895
2896 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2897 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2898 vc_conn.done;
2899}
2900
2901/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2902function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2903 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002904 var integer pcu_conn_id := -1;
2905
2906 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2907
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002908 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2909 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2910 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002911 setverdict(pass);
2912}
2913testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2914 var ConnHdlrPars pars;
2915 var ConnHdlr vc_conn;
2916 f_init(testcasename());
2917
2918 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2919 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2920 vc_conn.done;
2921}
2922
2923/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2924function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2925 var PCUIF_Message first_info;
2926 var integer ts_nr := g_chan_nr.tn;
2927 var integer trx_nr := 0;
2928 var integer bts_nr := 0;
2929 var integer pcu_conn_id := -1;
2930
2931 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2932
2933 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002934 /* Send a second Chan Activ and expect it to be NACKed */
2935 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2936 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002937 setverdict(pass);
2938}
2939testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2940 var ConnHdlrPars pars;
2941 var ConnHdlr vc_conn;
2942 f_init(testcasename());
2943
2944 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2945 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2946 vc_conn.done;
2947}
2948
2949/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2950function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2951 var PCUIF_Message first_info;
2952 var integer ts_nr := g_chan_nr.tn;
2953 var integer trx_nr := 0;
2954 var integer bts_nr := 0;
2955 var integer pcu_conn_id := -1;
2956 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2957
2958 /* register for the TCH/F channel number */
2959 f_rslem_register(0, chan_nr);
2960
2961 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2962
2963 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2964 "RSL CHAN ACT");
2965 setverdict(pass);
2966}
2967testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2968 var ConnHdlrPars pars;
2969 var ConnHdlr vc_conn;
2970 f_init(testcasename());
2971
2972 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2973 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2974 vc_conn.done;
2975}
2976
2977/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2978function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2979 var PCUIF_Message first_info;
2980 var integer ts_nr := g_chan_nr.tn;
2981 var integer trx_nr := 0;
2982 var integer bts_nr := 0;
2983 var integer pcu_conn_id := -1;
2984 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2985 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2986
2987 /* register for the TCH/H channel numbers */
2988 f_rslem_register(0, chan_nr[0]);
2989 f_rslem_register(0, chan_nr[1]);
2990
2991 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2992
2993 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2994 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2995 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2996 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2997 setverdict(pass);
2998}
2999testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3000 var ConnHdlrPars pars;
3001 var ConnHdlr vc_conn;
3002 f_init(testcasename());
3003
3004 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3005 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3006 vc_conn.done;
3007}
3008
Harald Welte9bbbfb52018-04-05 09:33:19 +02003009/***********************************************************************
3010 * IPA Style Dynamic Timeslot Support
3011 ***********************************************************************/
3012
3013private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3014runs on ConnHdlr {
3015 var PCUIF_send_data sd;
3016 /* Expect BTS to immediately acknowledge activation as PDCH */
3017 PCU.clear;
3018 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3019 /* expect INFO_IND on PCU interface listing TS as PDCH */
3020 alt {
3021 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3022 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
3023 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
3024 self.stop;
3025 }
3026 }
3027 [] PCU.receive { repeat; }
3028 }
3029 /* try to activate this PDCH from the PCU point of view */
3030 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3031 /* FIXME: is there a response? */
3032
3033 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3034}
3035
3036private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3037runs on ConnHdlr {
3038 var PCUIF_send_data sd;
3039 /* Send RSL CHAN REL (deactivate) */
3040 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3041 PCU.clear;
3042 /* expect BTS to ask PCU to deactivate the channel */
3043 alt {
3044 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3045 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
3046 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
3047 self.stop;
3048 }
3049 }
3050 [] PCU.receive { repeat; }
3051 }
3052 /* Emulate PCU asking BTS to deactivate PDCH */
3053 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3054 alt {
3055 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3056 setverdict(pass);
3057 }
3058 [] RSL.receive { repeat; }
3059 }
3060}
3061
3062/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3063function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
3064 var PCUIF_Message first_info;
3065 var integer ts_nr := g_chan_nr.tn;
3066 var integer trx_nr := 0;
3067 var integer bts_nr := 0;
3068 var integer pcu_conn_id := -1;
3069
3070 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3071
3072 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3073 f_sleep(3.0);
3074 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3075
3076 setverdict(pass);
3077
3078}
3079testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
3080 var ConnHdlrPars pars;
3081 var ConnHdlr vc_conn;
3082 f_init();
3083
3084 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3085 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
3086 vc_conn.done;
3087}
3088
3089/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3090function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3091 var PCUIF_Message first_info;
3092 var integer ts_nr := g_chan_nr.tn;
3093 var integer trx_nr := 0;
3094 var integer bts_nr := 0;
3095 var integer pcu_conn_id := -1;
3096
3097 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3098
3099 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3100 "RSL CHAN ACT");
3101 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3102 "RF CHAN REL", true);
3103 setverdict(pass);
3104}
3105testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3106 var ConnHdlrPars pars;
3107 var ConnHdlr vc_conn;
3108 f_init(testcasename());
3109
3110 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3111 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3112 vc_conn.done;
3113}
3114
3115/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3116function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3117 var PCUIF_Message first_info;
3118 var integer ts_nr := g_chan_nr.tn;
3119 var integer trx_nr := 0;
3120 var integer bts_nr := 0;
3121 var integer pcu_conn_id := -1;
3122
3123 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3124
3125 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3126 "RSL CHAN ACT");
3127
3128 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3129 alt {
3130 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3131 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
3132 setverdict(fail, "Unexpected PDCH ACT ACK");
3133 self.stop;
3134 }
3135 [] RSL.receive { repeat; }
3136 }
3137
3138 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3139 "RF CHAN REL", true);
3140 setverdict(pass);
3141}
3142testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3143 var ConnHdlrPars pars;
3144 var ConnHdlr vc_conn;
3145 f_init(testcasename());
3146
3147 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3148 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3149 vc_conn.done;
3150}
3151
3152/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3153function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3154 var PCUIF_Message first_info;
3155 var integer ts_nr := g_chan_nr.tn;
3156 var integer trx_nr := 0;
3157 var integer bts_nr := 0;
3158 var integer pcu_conn_id := -1;
3159
3160 /* register for the TCH/F channel number */
3161 f_rslem_register(0, g_chan_nr);
3162
3163 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3164
3165 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3166
3167 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3168 "RSL CHAN ACT");
3169
3170 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3171
3172 setverdict(pass);
3173}
3174testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3175 var ConnHdlrPars pars;
3176 var ConnHdlr vc_conn;
3177 f_init(testcasename());
3178
3179 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3180 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3181 vc_conn.done;
3182}
3183
3184
Harald Welte0472ab42018-03-12 15:02:26 +01003185/***********************************************************************
3186 * LAPDm / RLL related
3187 ***********************************************************************/
3188
3189private function f_tx_lapdm(template (value) LapdmFrame l,
3190 template (value) RslLinkId link_id) runs on ConnHdlr {
3191 var octetstring l2 := enc_LapdmFrame(valueof(l));
3192 if (valueof(link_id.c) == SACCH) {
3193 /* prepend dummy L1 header */
3194 l2 := '0000'O & l2;
3195 }
3196 log("encoding ", l, " to ", l2);
3197 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3198}
3199
3200type record RllTestCase {
3201 uint3_t sapi,
3202 RslLinkId link_id,
3203 octetstring l3,
3204 boolean exp
3205}
3206type record of RllTestCase RllTestCases;
3207template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3208 sapi := sapi,
3209 link_id := id,
3210 l3 := l3,
3211 exp := exp
3212}
3213
3214/* execute the same callback function with a set of different parameters (tcs) on a
3215 * variety of logical channels */
3216private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3217 var ConnHdlrPars pars;
3218 var ConnHdlr vc_conn;
3219 f_init(testcasename());
3220
3221 /* test on each of the channels we have */
3222 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3223 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3224
3225 /* test each of the test cases on the current channel */
3226 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3227 pars.spec.rll := tcs[j];
3228 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3229 vc_conn := f_start_handler(fn, pars);
3230 vc_conn.done;
3231 }
3232 }
3233
3234 f_shutdown();
3235}
3236
3237/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3238private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3239 var RllTestCase tc := g_pars.spec.rll;
3240 timer T := 3.0;
3241
3242 f_l1_tune(L1CTL);
3243 RSL.clear;
3244
3245 /* activate the logical channel */
3246 f_est_dchan();
3247 L1CTL.clear;
3248
3249 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3250 T.start;
3251 alt {
3252 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3253 if (tc.exp) {
3254 setverdict(pass);
3255 } else {
3256 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3257 }
3258 }
3259 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3260 if (tc.exp) {
3261 setverdict(pass);
3262 } else {
3263 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3264 }
3265 }
3266 [tc.exp] T.timeout {
3267 setverdict(fail, "Timeout waiting for EST IND");
3268 }
3269 [not tc.exp] T.timeout {
3270 setverdict(pass);
3271 }
3272 }
3273
3274 f_rsl_chan_deact();
3275 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3276 f_rslem_unregister(0, g_chan_nr);
3277}
3278testcase TC_rll_est_ind() runs on test_CT {
3279 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003280 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003281 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003282 /* normal SAPI0 establishment */
3283 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003284 /* SAPI 3 doesn't support contention resolution */
3285 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3286 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3287 /* normal SAPI3 establishment on main DCCH */
3288 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3289 /* normal SAPI3 establishment on SACCH */
3290 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3291 };
3292 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3293}
3294
3295/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3296private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3297 var RllTestCase tc := g_pars.spec.rll;
3298 var L1ctlDlMessage dl;
3299 timer T := 3.0;
3300
3301 f_l1_tune(L1CTL);
3302 RSL.clear;
3303
3304 /* activate the logical channel */
3305 f_est_dchan();
3306 L1CTL.clear;
3307
3308 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3309 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3310 T.start;
3311 alt {
3312 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3313 var LapdmFrame lapdm;
3314 var octetstring l2 := dl.payload.data_ind.payload;
3315 if (dl.dl_info.link_id.c == SACCH) {
3316 /* remove L1 header */
3317 l2 := substr(l2, 2, lengthof(l2)-2);
3318 }
3319 lapdm.ab := dec_LapdmFrameAB(l2);
3320 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3321 setverdict(pass);
3322 } else {
3323 repeat;
3324 }
3325 }
3326 [] L1CTL.receive { repeat; }
3327 [] T.timeout {
3328 setverdict(fail, "Timeout waiting for SABM");
3329 self.stop;
3330 }
3331 }
3332
3333 f_rsl_chan_deact();
3334 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3335 f_rslem_unregister(0, g_chan_nr);
3336}
3337testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3338 var RllTestCases tcs := {
3339 /* normal SAPI3 establishment on main DCCH */
3340 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3341 };
3342 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3343}
3344testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3345 var RllTestCases tcs := {
3346 /* normal SAPI3 establishment on SACCH */
3347 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3348 }
3349 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3350}
3351
3352/* altstep to receive a LAPDm frame matching the given template */
3353private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3354 var L1ctlDlMessage dl;
3355 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3356 var LapdmFrame lapdm;
3357 var octetstring l2 := dl.payload.data_ind.payload;
3358 if (dl.dl_info.link_id.c == SACCH) {
3359 /* remove L1 header */
3360 l2 := substr(l2, 2, lengthof(l2)-2);
3361 }
3362 if (ischosen(exp.ab)) {
3363 lapdm.ab := dec_LapdmFrameAB(l2);
3364 } else if (ischosen(exp.b4)) {
3365 lapdm.b4 := dec_LapdmFrameB4(l2);
3366 } else if (ischosen(exp.bbis)) {
3367 lapdm.bbis := dec_LapdmFrameBbis(l2);
3368 }
3369 log("Rx LAPDm ", lapdm);
3370 if (match(lapdm, exp)) {
3371 setverdict(pass);
3372 } else {
3373 repeat;
3374 }
3375 }
3376 [] L1CTL.receive { repeat; }
3377}
3378private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3379 timer T := t;
3380 T.start;
3381 alt {
3382 [] T.timeout {
3383 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3384 self.stop;
3385 }
3386 [] as_l1_exp_lapdm(exp);
3387 }
3388}
3389
3390/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3391private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3392 /* send SABM from MS -> BTS */
3393 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3394 /* expect RLL EST IND on Abis */
3395 alt {
3396 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3397 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3398 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3399 setverdict(fail, "Failing due to RSL_ERROR_IND");
3400 self.stop;
3401 }
3402 [] RSL.receive { repeat; }
3403 }
3404 /* expect UA from BTS -> MS */
3405 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3406}
3407
3408/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3409private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3410 var RllTestCase tc := g_pars.spec.rll;
3411
3412 f_l1_tune(L1CTL);
3413 RSL.clear;
3414
3415 /* activate the logical channel */
3416 f_est_dchan();
3417 L1CTL.clear;
3418
3419 /* first establish the link-layer */
3420 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3421
3422 /* then send the DISC */
3423 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3424 /* ... and expect the REL IND on the RSL side */
3425 alt {
3426 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3427 setverdict(pass);
3428 }
3429 }
3430
3431 /* release the channel */
3432 f_rsl_chan_deact();
3433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3434 f_rslem_unregister(0, g_chan_nr);
3435}
3436testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3437 var RllTestCases tcs := {
3438 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3439 };
3440 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3441}
3442
3443testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3444 var RllTestCases tcs := {
3445 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3446 };
3447 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3448}
3449testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3450 var RllTestCases tcs := {
3451 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3452 };
3453 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3454}
3455testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3456 var RllTestCases tcs := {
3457 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3458 };
3459 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3460}
3461
3462/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3463private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3464 var RllTestCase tc := g_pars.spec.rll;
3465 f_l1_tune(L1CTL);
3466 RSL.clear;
3467
3468 /* activate the logical channel */
3469 f_est_dchan();
3470 L1CTL.clear;
3471
3472 /* first establish the link-layer */
3473 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3474
3475 /* then send the REL REQ via RSL */
3476 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3477 /* ... and expect the DISC on the Um side */
3478 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003479 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003480 /* FIXME: send a UA in resposne to the DISC */
3481 }
3482 }
3483
3484 /* release the channel */
3485 f_rsl_chan_deact();
3486 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3487 f_rslem_unregister(0, g_chan_nr);
3488}
3489testcase TC_rll_rel_req() runs on test_CT {
3490 var RllTestCases tcs := {
3491 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3492 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3493 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3494 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3495 };
3496 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3497}
3498
3499/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3500testcase TC_rll_data_req() runs on test_CT {
3501}
3502
3503/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3504testcase TC_rll_data_ind() runs on test_CT {
3505}
3506
3507/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3508private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3509 var RllTestCase tc := g_pars.spec.rll;
3510
3511 f_l1_tune(L1CTL);
3512 RSL.clear;
3513
3514 f_est_dchan();
3515 L1CTL.clear;
3516
3517 /* Send UNITDATA REQ on RSL side */
3518 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3519 /* Expect it to arrive on the other side */
3520 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003521 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003522 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003523 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003524 }
3525
3526 /* release the channel */
3527 f_rsl_chan_deact();
3528 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3529 f_rslem_unregister(0, g_chan_nr);
3530}
3531testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3532 var octetstring l3 := f_rnd_octstring(15);
3533 var RllTestCases tcs := {
3534 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3535 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3536 };
3537 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3538}
3539testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3540 var octetstring l3 := f_rnd_octstring(19);
3541 var RllTestCases tcs := {
3542 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3543 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3544 };
3545 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3546}
3547
3548/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3549private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3550 var RllTestCase tc := g_pars.spec.rll;
3551
3552 f_l1_tune(L1CTL);
3553 RSL.clear;
3554
3555 f_est_dchan();
3556 L1CTL.clear;
3557
3558 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003559 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003560 /* Expdct RLL UNITDATA IND on RSL side */
3561 alt {
3562 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3563 setverdict(pass);
3564 }
3565 [] RSL.receive { repeat; }
3566 }
3567
3568 /* release the channel */
3569 f_rsl_chan_deact();
3570 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3571 f_rslem_unregister(0, g_chan_nr);
3572}
3573testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3574 var octetstring l3 := f_rnd_octstring(15);
3575 var RllTestCases tcs := {
3576 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3577 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3578 };
3579 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3580}
3581testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3582 var octetstring l3 := f_rnd_octstring(18);
3583 var RllTestCases tcs := {
3584 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3585 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3586 };
3587 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3588}
3589
Harald Weltee613f962018-04-18 22:38:16 +02003590/***********************************************************************
3591 * Encryption Related
3592 ***********************************************************************/
3593
3594/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3595function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3596 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3597 if (link_id.c == SACCH) {
3598 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3599 } else {
3600 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3601 }
3602}
3603
3604/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3605function f_unitdata_mo(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3606 timer T := 3.0;
3607 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3608 T.start;
3609 /* Expect RLL UNITDATA IND on RSL side */
3610 alt {
3611 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3612 setverdict(pass);
3613 }
3614 [] T.timeout {
3615 setverdict(fail, "Timeout waiting for UNIT_DATA_IND");
3616 }
3617 [] RSL.receive { repeat; }
3618 }
3619}
3620
3621/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3622function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3623 f_l1_tune(L1CTL);
3624 f_est_dchan(true);
3625
3626 /* now we actually need to transmit some data both ways to check if the encryption works */
3627 var L1ctlDlMessage dl;
3628
3629 var octetstring l3 := f_rnd_octstring(16);
3630 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3631
3632 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3633 f_unitdata_mt(link_id, l3);
3634
3635 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3636 f_unitdata_mo(link_id, l3);
3637
3638 /* release the channel */
3639 f_rsl_chan_deact();
3640 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3641 f_rslem_unregister(0, g_chan_nr);
3642}
3643testcase TC_chan_act_a51() runs on test_CT {
3644 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3645 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3646 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3647}
3648testcase TC_chan_act_a52() runs on test_CT {
3649 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3650 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3651 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3652}
3653testcase TC_chan_act_a53() runs on test_CT {
3654 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3655 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3656 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3657}
3658
3659
3660/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3661function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3662 /* L3 payload doesn't matter, as it is passed transparently */
3663 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3664 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3665 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3666
3667 f_l1_tune(L1CTL);
3668
3669 /* first establish a dedicated channel in the clear */
3670 f_est_dchan(false);
3671
3672 /* Establish ABM */
3673 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3674
3675 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3676 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3677 /* expect the L3 to arrive still unencrypted on the MS side */
3678 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3679
3680 /* configure L1 to apply ciphering */
3681 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3682 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3683
3684 /* send first ciphered I-frame in response */
3685 l3 := '0a0b0c0d'O;
3686 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3687 RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3));
3688
3689 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3690 * and hence enable encryption also on the downlink */
3691
3692 /* expect bi-directional communication work in encrypted mode */
3693 f_unitdata_mo(link_id, f_rnd_octstring(15));
3694 f_unitdata_mt(link_id, f_rnd_octstring(15));
3695
3696 /* release the channel */
3697 f_rsl_chan_deact();
3698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3699 f_rslem_unregister(0, g_chan_nr);
3700}
3701testcase TC_encr_cmd_a51() runs on test_CT {
3702 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3703 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3704 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3705}
3706testcase TC_encr_cmd_a52() runs on test_CT {
3707 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3708 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3709 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3710}
3711testcase TC_encr_cmd_a53() runs on test_CT {
3712 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3713 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3714 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3715}
3716
3717private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3718 var LapdmFrame lf;
3719 var octetstring reenc;
3720
3721 /* decode the LAPDm frame */
3722 if (ischosen(exp_match.ab)) {
3723 lf.ab := dec_LapdmFrameAB(enc);
3724 } else {
3725 setverdict(fail, "unsupported frame type");
3726 self.stop;
3727 }
3728
3729 /* check if decoder result matches expectation */
3730 if (not match(lf, exp_match)) {
3731 setverdict(fail, name, ": decoded LAPDm doesn't match");
3732 } else {
3733 log(name, ": matched");
3734 setverdict(pass);
3735 }
3736
3737 /* test if re-encoded frame equals original input */
3738 reenc := enc_LapdmFrame(lf);
3739 if (enc != reenc) {
3740 setverdict(fail, name, ": re-encoded LAPDm frame doesn't match");
3741 } else {
3742 setverdict(pass);
3743 }
3744}
3745
3746testcase TC_lapdm_selftest() runs on test_CT {
3747 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3748 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3749 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3750 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3751 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3752 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3753 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3754}
3755
Harald Welte0472ab42018-03-12 15:02:26 +01003756
3757/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3758/* protocol error as per 44.006 */
3759/* link layer failure (repetition of I-frame N200 times without ACK */
3760/* repetition of SABM or DISC N200 times without ACK */
3761/* receptiom of SABM in multi-frame established state */
3762
3763
3764
3765
Harald Welte883340c2018-02-28 18:59:29 +01003766
Harald Welte68e495b2018-02-25 00:05:57 +01003767/* TODO Areas:
3768
3769* channel activation
3770** with BS_Power / MS_Power, bypassing power control loop
3771** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01003772** with timing advance from initial activation on
3773* mode modify
3774** encryption
3775** multirate
3776* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01003777** unsupported algorithm
3778* handover detection
3779* MS Power Control
3780* BS Power Control
3781* Physical Context
3782* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003783* CCCH Load Indication for PCH and RACH
3784* Delete Indication on AGCH overflow
3785* SMS Broadcast Req / Cmd / CBCH LOad Ind
3786* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003787* error handling
3788* discriminator error
3789** type error
3790** sequence error
3791** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003792* PCU interface
3793** TIME_IND from BTS->PCU
3794** DATA_IND from BTS->PCU
3795** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003796
3797*/
Harald Welte70767382018-02-21 12:16:40 +01003798
3799control {
3800 execute( TC_chan_act_stress() );
3801 execute( TC_chan_act_react() );
3802 execute( TC_chan_deact_not_active() );
3803 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003804 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003805 execute( TC_sacch_filling() );
3806 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003807 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003808 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003809 execute( TC_rach_content() );
3810 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003811 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003812 execute( TC_meas_res_sign_tchf() );
3813 execute( TC_meas_res_sign_tchh() );
3814 execute( TC_meas_res_sign_sdcch4() );
3815 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003816 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003817 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003818 execute( TC_paging_imsi_80percent() );
3819 execute( TC_paging_tmsi_80percent() );
3820 execute( TC_paging_imsi_200percent() );
3821 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003822 execute( TC_rsl_protocol_error() );
3823 execute( TC_rsl_mand_ie_error() );
3824 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003825 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003826 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003827 execute( TC_si_sched_2bis() );
3828 execute( TC_si_sched_2ter() );
3829 execute( TC_si_sched_2ter_2bis() );
3830 execute( TC_si_sched_2quater() );
3831 execute( TC_si_sched_13() );
3832 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003833 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003834 execute( TC_ipa_crcx_twice_not_active() );
3835 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003836 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003837 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003838
3839 execute( TC_pcu_act_req() );
3840 execute( TC_pcu_act_req_wrong_ts() );
3841 execute( TC_pcu_act_req_wrong_bts() );
3842 execute( TC_pcu_act_req_wrong_trx() );
3843 execute( TC_pcu_deact_req() );
3844 execute( TC_pcu_deact_req_wrong_ts() );
3845 execute( TC_pcu_ver_si13() );
3846 execute( TC_pcu_data_req_wrong_bts() );
3847 execute( TC_pcu_data_req_wrong_trx() );
3848 execute( TC_pcu_data_req_wrong_ts() );
3849 execute( TC_pcu_data_req_ts_inactive() );
3850 execute( TC_pcu_data_req_pdtch() );
3851 execute( TC_pcu_data_req_ptcch() );
3852 execute( TC_pcu_data_req_agch() );
3853 execute( TC_pcu_data_req_imm_ass_pch() );
3854 execute( TC_pcu_rach_content() );
3855 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003856
3857 execute( TC_dyn_osmo_pdch_act_deact() );
3858 execute( TC_dyn_osmo_pdch_unsol_deact() );
3859 execute( TC_dyn_osmo_pdch_double_act() );
3860 execute( TC_dyn_osmo_pdch_tchf_act() );
3861 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003862 execute( TC_dyn_ipa_pdch_act_deact() );
3863 execute( TC_dyn_ipa_pdch_tchf_act() );
3864 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3865 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003866
3867 execute( TC_rll_est_ind() );
3868 execute( TC_rll_est_req_DCCH_3() );
3869 execute( TC_rll_est_req_ACCH_3() );
3870 execute( TC_rll_rel_ind_DCCH_0() );
3871 execute( TC_rll_rel_ind_DCCH_3() );
3872 execute( TC_rll_rel_ind_ACCH_0() );
3873 execute( TC_rll_rel_ind_ACCH_3() );
3874 execute( TC_rll_rel_req() );
3875 execute( TC_rll_unit_data_req_DCCH() );
3876 execute( TC_rll_unit_data_req_ACCH() );
3877 execute( TC_rll_unit_data_ind_DCCH() );
3878 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02003879
3880 execute( TC_chan_act_a51() );
3881 execute( TC_chan_act_a52() );
3882 execute( TC_chan_act_a53() );
3883 execute( TC_encr_cmd_a51() );
3884 execute( TC_encr_cmd_a52() );
3885 execute( TC_encr_cmd_a53() );
3886
3887 execute( TC_lapdm_selftest() );
Harald Welte70767382018-02-21 12:16:40 +01003888}
3889
3890
3891}