blob: 36fa55cd5d0a576708aed5f184a79b83aca2cc11 [file] [log] [blame]
Harald Welte08332302019-08-01 09:54:40 +02001module CBC_Tests {
2
3import from Osmocom_Types all;
4
5import from BSSAP_Types all;
6import from BSSMAP_Templates all;
7import from CBSP_Types all;
8import from CBSP_Templates all;
9import from CBSP_Adapter all;
10import from CBSP_CodecPort all;
11import from Socket_API_Definitions all;
12
13import from HTTP_Adapter all;
14import from HTTPmsg_Types all;
15import from ECBE_Types all;
16
17modulepar {
18 charstring mp_cbc_host := "127.0.0.1";
19 integer mp_cbc_port := 48049;
20 integer mp_ecbe_port := 12345;
21};
22
23type component test_CT extends CBSP_Adapter_CT, http_CT {
24};
25
26/*********************************************************************************
27 * ECBE (REST) interface
28 *********************************************************************************/
29
30function f_ecbe_tx_post_cbs(EcbeCbcMessage cbc)
31runs on http_CT {
32 var charstring body := oct2char(enc_EcbeCbcMessage(cbc));
33 log("TX POST CBS: ", body);
34 var HTTPMessage http_resp;
35 f_http_tx_request(url := "/api/ecbe/v1/message", method := "POST", body := body);
36}
37
38function f_ecbe_rx_resp(template integer exp_sts := (200..299))
39runs on http_CT return HTTPResponse {
40 var HTTPMessage http_resp := f_http_rx_response(tr_HTTP_Resp(exp_sts), tout := 20.0);
41 return http_resp.response;
42}
43
44/* run a HTTP POST to add a new CBC message */
45function f_ecbe_post_cbs(EcbeCbcMessage cbc, template integer exp_sts := 201)
46runs on http_CT return HTTPResponse {
47 f_ecbe_tx_post_cbs(cbc);
48 return f_ecbe_rx_resp(exp_sts)
49}
50
51function f_ecbe_tx_delete_cbs(integer msg_id)
52runs on http_CT {
53 f_http_tx_request("/api/ecbe/v1/message/" & int2str(msg_id), method := "DELETE");
54}
55
56/* run a HTTP GET on specified URL expecting json in RSRES format as response */
57function f_ecbe_delete_cbs(integer msg_id, template integer exp_sts := 200)
58runs on http_CT return HTTPResponse {
59 f_ecbe_tx_delete_cbs(msg_id);
60 return f_ecbe_rx_resp(exp_sts);
61}
62
63
64altstep as_cbsp_reset(integer idx) runs on CBSP_Adapter_CT {
65 var CBSP_RecvFrom rf;
66 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESET)) -> value rf {
67 var CBSP_IE ie;
68 f_cbsp_find_ie(rf.msg, CBSP_IEI_CELL_LIST, ie);
69 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx],
70 ts_CBSP_RESET_COMPL(ie.body.cell_list.cell_id)));
71 }
72}
73
74private function f_cbs2ecbe_category(CBSP_Category cat_in) return EcbeCategory
75{
76 select (cat_in) {
77 case (CBSP_CATEG_HIGH_PRIO) { return high_priority; }
78 case (CBSP_CATEG_BACKGROUND) { return background; }
79 case (CBSP_CATEG_NORMAL) { return normal; }
80 case else { mtc.stop }
81 }
82}
83
84private function f_cbs2ecbe_page(CBS_MessageContent inp) return EcbePage
85{
86 return hex2str(oct2hex(inp.payload));
87}
88
89/* convert from CBS_Message to EcbeCbcMessage */
90function f_cbs2ecbe(CBS_Message inp, charstring cbe_name) return EcbeCbcMessage
91{
92 var EcbeCbcMessage ret := {
93 cbe_name := cbe_name,
94 category := f_cbs2ecbe_category(inp.category),
95 repetition_period := inp.rep_period,
96 num_of_bcast := inp.num_bcast_req,
97 scope := { scope_plmn := {} },
98 smscb_message := {
99 serial_nr := {
100 serial_nr_encoded := inp.ser_nr
101 },
102 message_id := inp.msg_id,
103 payload := {
104 payload_encoded := {
105 dcs := inp.dcs,
106 pages := { } /* appended below */
107 }
108 }
109 }
110 };
111 for (var integer i := 0; i < lengthof(inp.content); i := i+1) {
112 ret.smscb_message.payload.payload_encoded.pages :=
113 ret.smscb_message.payload.payload_encoded.pages & { f_cbs2ecbe_page(inp.content[i]) };
114 }
115 return ret;
116}
117
118/*********************************************************************************
119 * CBSP interface
120 *********************************************************************************/
121
122/* receive + acknowledge KEEP-ALIVE */
123altstep as_cbsp_keepalive_ack(integer idx) runs on CBSP_Adapter_CT {
124 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_KEEP_ALIVE)) {
125 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], ts_CBSP_KEEP_ALIVE_COMPL));
126 }
127}
128
129/* receive + ignore RESTART */
130altstep as_cbsp_restart(integer idx) runs on CBSP_Adapter_CT {
131 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESTART));
132}
133
134private function f_init(boolean raw := false) runs on test_CT {
135 f_http_init(mp_cbc_host, mp_ecbe_port);
136 CBSP_Adapter.f_connect(mp_cbc_host, mp_cbc_port, "", -1);
137
138 if (not raw) {
139 var BSSMAP_FIELD_CellIdentificationList cell_list := {
140 cIl_allInBSS := ''O
141 };
142 activate(as_cbsp_keepalive_ack(0));
143 activate(as_cbsp_restart(0));
144 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_CBS, CBSP_RI_DATA_LOST));
145 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_EMERG, CBSP_RI_DATA_LOST));
146 as_cbsp_reset(0);
147 }
148}
149
150/* test whether or not we receive a valid KEEP-ALIVE from the CBC */
151testcase TC_rx_keepalive() runs on test_CT {
152 var CBSP_PDU rx;
153 var CBSP_IE ie;
154
155 f_init();
156 rx := f_cbsp_exp(tr_CBSP_KEEP_ALIVE(?));
157 f_cbsp_find_ie(rx, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, ie);
158
159 setverdict(pass);
160}
161
162/* test whether CBC terminates connection if KEEP-ALIVE is not answered by BSC */
163testcase TC_rx_keepalive_timeout() runs on test_CT {
164 var CBSP_PDU rx;
165 var CBSP_IE ie;
166 var integer ka_rep_per_s;
167
168 f_init();
169 rx := f_cbsp_exp(tr_CBSP_KEEP_ALIVE(?));
170 f_cbsp_find_ie(rx, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, ie);
171
172 /* sleep for longer than the keep-alive period */
173 ka_rep_per_s := f_cbsp_period2s(ie.body.keep_alive_rep_period);
174 f_sleep(int2float(ka_rep_per_s + 5));
175
176 /* expect the CBSP connection to be closed */
177 CBSP[0].receive(PortEvent:{connClosed:=?})
178
179 setverdict(pass);
180}
181
182type record CBS_Message {
183 uint16_t msg_id,
184 uint16_t ser_nr,
185 uint16_t old_ser_nr optional,
186 BSSMAP_FIELD_CellIdentificationList cell_list,
187 uint8_t channel_ind,
188 CBSP_Category category,
189 uint16_t rep_period,
190 uint16_t num_bcast_req,
191 uint8_t dcs,
192 CBS_MessageContents content
193};
194type record CBS_MessageContent {
195 octetstring payload,
196 uint8_t user_len
197};
198type record of CBS_MessageContent CBS_MessageContents;
199
200/* handle a CBSP-WRITE-REPLACE and respond to it with COMPLETE or FAILURE depending on arguments */
201private function f_cbsp_write(CBS_Message msg, integer idx := 0,
202 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
203 template (omit) CBSP_FailureListItems tx_fail_list := omit,
204 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit)
205runs on test_CT {
206 var template CBSP_IEs content_ies := {};
207 var template (present) CBSP_PDU rx_templ;
208 var CBSP_RecvFrom rf;
209 for (var integer i := 0; i < lengthof(msg.content); i := i+1) {
210 //content_ies[i] := tr_CbspMsgContent(msg.content[i].payload, msg.content[i].user_len);
211 content_ies[i] := tr_CbspMsgContent(?, ?);
212 }
213 rx_templ := tr_CBSP_WRITE_CBS(msg.msg_id, msg.ser_nr, msg.cell_list, msg.channel_ind,
214 msg.category, msg.rep_period, msg.num_bcast_req, msg.dcs,
215 content_ies);
216 alt {
217 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
218 var template (value) CBSP_PDU tx;
219 if (istemplatekind(tx_fail_list, "omit")) {
220 var template (value) BSSMAP_FIELD_CellIdentificationList tx_list;
221 if (istemplatekind(tx_cell_list, "omit")) {
222 /* use the "expected list" when confirming the write-replace */
223 tx_list := msg.cell_list;
224 } else {
225 /* use an user-provided different list of cells */
226 tx_list := valueof(tx_cell_list);
227 }
228 if (istemplatekind(tx_compl_list, "omit")) {
229 tx := ts_CBSP_WRITE_CBS_COMPL(msg.msg_id, msg.ser_nr, tx_list, msg.channel_ind);
230 } else {
231 tx := ts_CBSP_REPLACE_CBS_COMPL(msg.msg_id, msg.ser_nr, msg.old_ser_nr,
232 valueof(tx_compl_list), tx_list,
233 msg.channel_ind);
234 }
235 } else {
236 tx := ts_CBSP_WRITE_CBS_FAIL(msg.msg_id, msg.ser_nr, valueof(tx_fail_list),
237 omit, tx_cell_list, msg.channel_ind);
238 }
239 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
240 }
241 [] as_cbsp_keepalive_ack(idx) { repeat; }
242 [] CBSP[idx].receive {
243 setverdict(fail, "Received unexpected CBSP in index ", idx);
244 }
245 }
246}
247
248/* handle a CBSP-KILL and respond to it with COMPLETE or FAILURE depending on arguments */
249private function f_cbsp_handle_kill(integer idx, uint16_t msg_id, uint16_t ser_nr,
250 template BSSMAP_FIELD_CellIdentificationList exp_list,
251 template (omit) BSSMAP_FIELD_CellIdentificationList tx_list,
252 template (omit) CBSP_FailureListItems tx_fail_list := omit,
253 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit,
254 template (omit) uint8_t channel_ind := omit)
255runs on test_CT {
256 var template (present) CBSP_PDU rx_templ;
257 var CBSP_RecvFrom rf;
258
259 rx_templ := tr_CBSP_KILL(msg_id, ser_nr, exp_list, channel_ind);
260 alt {
261 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
262 var template (value) CBSP_PDU tx;
263 if (istemplatekind(tx_fail_list, "omit")) {
264 tx := ts_CBSP_KILL_COMPL(msg_id, ser_nr, tx_compl_list, tx_list, channel_ind);
265 } else {
266 tx := ts_CBSP_KILL_FAIL(msg_id, ser_nr, valueof(tx_fail_list), tx_compl_list,
267 tx_list, channel_ind);
268 }
269 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
270 }
271 [] as_cbsp_keepalive_ack(idx) { repeat; }
272 [] CBSP[idx].receive {
273 setverdict(fail, "Received unexpected CBSP in index ", idx);
274 }
275 }
276}
277
278private const BSSMAP_FIELD_CellIdentificationList cil_BSS := {
279 cIl_allInBSS := ''O
280};
281
282testcase TC_write_replace() runs on test_CT {
283 f_init();
284 var CBS_Message msg := {
285 msg_id := 42,
286 ser_nr := 16752,
287 old_ser_nr := omit,
288 cell_list := cil_BSS,
289 channel_ind := 0,
290 category := CBSP_CATEG_NORMAL,
291 rep_period := 5,
292 num_bcast_req := 3,
293 dcs := 1,
294 content := {
295 { '00'O, 1 }
296 }
297 };
298 f_cbsp_write(msg);
299 f_sleep(100.0);
300}
301
302testcase TC_selftest() runs on test_CT {
303 const octetstring c_load_q := '0700000d0400080000f110012345671200'O;
304 const octetstring c_load_q_compl := '0800000f0a000a0000f1100123456700001200'O;
305 const octetstring c_reset := '1000000b0400080000f11001234567'O;
306 const octetstring c_reset_compl := '1100000b0400080000f11001234567'O;
307 const octetstring c_msg_sts_q := '0a0000130e022b0200000400080000f110012345671200'O;
308 const octetstring c_msg_sts_q_fail := '0c0000140e022b0200000900090000f11001234567021200'O;
309 const octetstring c_kill := '040000110e00000200000400080000f11001234567'O;
310 const octetstring c_kill_fail := '060000120e00000200000900090000f1100123456702'O;
311 const octetstring c_write_repl := '010000c70e022b0300300400080000f110012345671200050006000407000613020c400107f4f29c9e769f5de337b90c921d1b8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d100'O;
312 const octetstring c_write_repl_compl := '020000130e022b0300300400080000f110012345671200'O;
313 const octetstring c_write_repl_fail := '030000140e022b0300300900090000f110012345670d1200'O;
314 const octetstring c_msg_s_q := '0a0000130e022b0200900400080000f110012345671200'O;
315 const octetstring c_msg_s_q_compl := '0b0000160e022b02009008000b0000f110012345670008001200'O;
316 const octetstring c_kill_compl := '050000160e022b02008008000b0000f110012345670006001200'O;
317
318 log(dec_CBSP_PDU(c_load_q));
319 log(dec_CBSP_PDU(c_load_q_compl));
320 log(dec_CBSP_PDU(c_reset));
321 log(dec_CBSP_PDU(c_reset_compl));
322 log(dec_CBSP_PDU(c_msg_sts_q));
323 log(dec_CBSP_PDU(c_msg_sts_q_fail));
324 log(dec_CBSP_PDU(c_kill));
325 log(dec_CBSP_PDU(c_kill_fail));
326 log(dec_CBSP_PDU(c_write_repl));
327 log(dec_CBSP_PDU(c_write_repl_compl));
328 log(dec_CBSP_PDU(c_write_repl_fail));
329 log(dec_CBSP_PDU(c_msg_s_q));
330 log(dec_CBSP_PDU(c_msg_s_q_compl));
331 log(dec_CBSP_PDU(c_kill_compl));
332}
333
334import from SABP_Types all;
335import from SABP_Templates all;
336import from SABP_IEs all;
337import from SABP_PDU_Descriptions all;
338
339testcase TC_selftest_sabp() runs on test_CT {
340 const octetstring c_write := '00000080930000080006000211120007000240c0000f0010000113f0030282ec0613f0030282ec070001400100000d0002012a000900020000000400010100000056029f01b4d90d064297d9ec37e8fe96b3c9a0303bdd68341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d10012'O;
341
342 log(dec_SABP_PDU(c_write));
343 log(enc_SABP_PDU(dec_SABP_PDU(c_write)));
344
345 var template (value) Service_Areas_List sa_list := {
346 ts_SabpSai('62F224'O, '0023'O, '0042'O)
347 };
348 var template (value) SABP_PDU tx;
349
350 tx := ts_SABP_Write(int2bit(1, 16), int2bit(1, 16), sa_list, 23, 42, '00000000'B, '01011010'B);
351 log("Write: ", enc_SABP_PDU(valueof(tx)))
352
353 var Service_Areas_List sa_list2 := { valueof(ts_SabpSai('62F224'O, '1000'O, '0042'O)) };
354 for (var integer i := 0; i < 2500; i := i+1) {
355 sa_list2 := sa_list2 & {valueof(ts_SabpSai('62F224'O, '2000'O, int2oct(i,2))) };
356 }
357 tx := ts_SABP_Write(int2bit(2, 16), int2bit(2, 16), sa_list2, 23, 42, '00000000'B, '01011010'B);
358 log("Write: ", enc_SABP_PDU(valueof(tx)))
359
360 tx := ts_SABP_Restart(sa_list);
361 log("Restart: ", enc_SABP_PDU(valueof(tx)));
362}
363
364/*********************************************************************************
365 * ECBE interface (verifying expected procedures on CBSP)
366 *********************************************************************************/
367
368function f_create_and_delete(CBS_Message msg,
369 template (omit) BSSMAP_FIELD_CellIdentificationList cell_list_success)
370runs on test_CT {
371 var EcbeCbcMessage ecbe := f_cbs2ecbe(msg, "TTCN-3");
372 f_ecbe_tx_post_cbs(ecbe);
373 f_cbsp_write(msg, 0, cell_list_success);
374 f_ecbe_rx_resp(201);
375
376 f_sleep(2.0);
377
378 f_ecbe_tx_delete_cbs(msg.msg_id);
379 /* FIXME: cbc segfaults if we terminate here (if we don't wait for Connect_result? */
380 f_cbsp_handle_kill(0, msg.msg_id, msg.ser_nr, cell_list_success, cell_list_success);
381 f_ecbe_rx_resp(200);
382}
383
384private template (value) CBS_Message t_CBSmsg(uint16_t msg_id, uint16_t ser_nr) := {
385 msg_id := msg_id,
386 ser_nr := ser_nr,
387 old_ser_nr := omit,
388 cell_list := cil_BSS,
389 channel_ind := 0,
390 category := CBSP_CATEG_NORMAL,
391 rep_period := 5,
392 num_bcast_req := 3,
393 dcs := 1,
394 content := {
395 { '00'O, 1 }
396 }
397};
398
399/* specify a variety of different Cell Identifier formats to extend test coverage */
400testcase TC_ecbe_create_delete_cgi() runs on test_CT {
401 f_init();
402 var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
403 var template (value) CBS_Message msg := t_CBSmsg(43, 16752);
404
405 cell_list_success := ts_BSSMAP_CIL_CGI({
406 ts_BSSMAP_CI_CGI('901'H, '70'H, 23, 42),
407 ts_BSSMAP_CI_CGI('901'H, '70'H, 24, 42),
408 ts_BSSMAP_CI_CGI('901'H, '70'H, 24, 43)
409 });
410 f_create_and_delete(valueof(msg), cell_list_success);
411}
412testcase TC_ecbe_create_delete_lac_ci() runs on test_CT {
413 f_init();
414 var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
415 var template (value) CBS_Message msg := t_CBSmsg(44, 16752);
416 cell_list_success := ts_BSSMAP_CIL_LAC_CI({
417 ts_BSSMAP_CI_LAC_CI(10001, 50001),
418 ts_BSSMAP_CI_LAC_CI(10002, 50002),
419 ts_BSSMAP_CI_LAC_CI(10003, 50003)
420 });
421 f_create_and_delete(valueof(msg), cell_list_success);
422}
423testcase TC_ecbe_create_delete_lac() runs on test_CT {
424 f_init();
425 var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
426 var template (value) CBS_Message msg := t_CBSmsg(45, 16752);
427 cell_list_success := ts_BSSMAP_CIL_LAC({
428 ts_BSSMAP_CI_LAC(10001),
429 ts_BSSMAP_CI_LAC(10002),
430 ts_BSSMAP_CI_LAC(10003)
431 });
432 f_create_and_delete(valueof(msg), cell_list_success);
433}
434testcase TC_ecbe_create_delete_ci() runs on test_CT {
435 f_init();
436 var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
437 var template (value) CBS_Message msg := t_CBSmsg(46, 16752);
438 cell_list_success := ts_BSSMAP_CIL_CI({
439 ts_BSSMAP_CI_CI(50001),
440 ts_BSSMAP_CI_CI(50002),
441 ts_BSSMAP_CI_CI(50003)
442 });
443 f_create_and_delete(valueof(msg), cell_list_success);
444}
445testcase TC_ecbe_create_delete_lai() runs on test_CT {
446 f_init();
447 var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
448 var template (value) CBS_Message msg := t_CBSmsg(47, 16752);
449 cell_list_success := ts_BSSMAP_CIL_LAI({
450 ts_BSSMAP_CI_LAI('901'H, '70'H, 25),
451 ts_BSSMAP_CI_LAI('901'H, '70'H, 26),
452 ts_BSSMAP_CI_LAI('901'H, '70'H, 27)
453 });
454 f_create_and_delete(valueof(msg), cell_list_success);
455}
456
457control {
458 execute( TC_rx_keepalive() );
459 execute( TC_rx_keepalive_timeout() );
460 execute( TC_ecbe_create_delete_cgi() );
461 execute( TC_ecbe_create_delete_lac_ci() );
462 execute( TC_ecbe_create_delete_lac() );
463 execute( TC_ecbe_create_delete_ci() );
464 execute( TC_ecbe_create_delete_lai() );
465}
466
467}