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