blob: fd3f907c9788abfa90add1b57b21c5b2dff26cfa [file] [log] [blame]
Harald Weltefaa42922019-03-04 18:31:11 +01001module RemsimBankd_Tests {
2
3/* Integration Tests for osmo-remsim-bankd
4 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
12 * This test suite tests osmo-remsim-bankd by attaching to the external interfaces
13 * such as RSPRO for simulated clients + server.
14 */
15
16import from Osmocom_Types all;
17import from IPA_Emulation all;
18import from Misc_Helpers all;
19
Harald Welte90732952019-11-22 00:39:43 +010020import from VPCD_Types all;
21import from VPCD_CodecPort all;
22import from VPCD_Adapter all;
23
Harald Weltefaa42922019-03-04 18:31:11 +010024import from RSPRO all;
25import from RSRES all;
26import from RSPRO_Types all;
27import from RSPRO_Server all;
28import from REMSIM_Tests all;
29
30modulepar {
31 integer mp_bank_id := 1;
32 integer mp_num_slots := 8;
33}
34
35/* We implement a RSPRO server to simulate the remsim-server and a
36 RSPRO client to simulate a remsim-client connecting to bankd */
Harald Welte90732952019-11-22 00:39:43 +010037type component bankd_test_CT extends rspro_server_CT, rspro_client_CT, VPCD_Adapter_CT {
Harald Weltefaa42922019-03-04 18:31:11 +010038}
39
40private function f_init(boolean start_client := false) runs on bankd_test_CT {
41 var ComponentIdentity srv_comp_id := valueof(ts_CompId(remsimServer, "ttcn-server"));
42
43 f_rspro_srv_init(0, mp_server_ip, mp_server_port, srv_comp_id);
44
45 if (start_client) {
46 f_init_client(0);
47 }
48}
49
50private function f_init_client(integer i := 0) runs on rspro_client_CT {
51 var ComponentIdentity clnt_comp_id := valueof(ts_CompId(remsimClient, "ttcn-client"));
52 f_rspro_init(rspro[0], mp_bankd_ip, mp_bankd_port, clnt_comp_id, 0);
53 rspro[0].rspro_client_slot := { clientId := 23+i, slotNr := 0 };
54}
55
56
57
58/* Test if the bankd disconnects the TCP/IPA session if we don't respond to connectBankReq */
59testcase TC_connectBankReq_timeout() runs on bankd_test_CT {
60 timer T := 20.0;
61 f_init();
62
63 f_rspro_srv_exp(tr_RSPRO_ConnectBankReq(?, ?, ?));
64 T.start;
65 alt {
66 [] RSPRO_SRV[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
67 setverdict(pass);
68 }
69 [] RSPRO_SRV[0].receive { repeat; }
70 [] T.timeout {
71 setverdict(fail, "Timeout waiting for disconnect");
72 }
73 }
74}
75
76/* accept an inbound connection from bankd to simulated server */
77testcase TC_connectBankReq() runs on bankd_test_CT {
78 f_init();
79
80 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
81 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
82}
83
84/* attempt to create a mapping */
85testcase TC_createMapping() runs on bankd_test_CT {
86 f_init();
87 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +010088 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +010089 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
90 var ClientSlot cs := { clientId := 23, slotNr := 42 };
91 f_rspro_srv_create_slotmap(cs, bs);
92 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
93}
94
95/* attempt to create a mapping for a slot that already has a mapping */
96testcase TC_createMapping_busySlot() runs on bankd_test_CT {
97 f_init();
98 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +010099 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100100 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
101 var ClientSlot cs := { clientId := 23, slotNr := 42 };
Harald Weltebca0ecd2019-12-04 21:53:29 +0100102 /* create the mapping the first time */
Harald Weltefaa42922019-03-04 18:31:11 +0100103 f_rspro_srv_create_slotmap(cs, bs);
Harald Weltebca0ecd2019-12-04 21:53:29 +0100104 /* re-create the mapping a second time */
105 f_rspro_srv_create_slotmap(cs, bs);
Harald Weltefaa42922019-03-04 18:31:11 +0100106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
107}
108
109/* attempt to create a mapping for an out-of-range slot number */
110testcase TC_createMapping_invalidSlot() runs on bankd_test_CT {
111 f_init();
112 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100113 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100114 var BankSlot bs := { bankId := mp_bank_id, slotNr := 200 };
115 var ClientSlot cs := { clientId := 23, slotNr := 42 };
116 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalSlotId);
117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
118}
119
120/* attempt to create a mapping for an invalid bankID */
121testcase TC_createMapping_invalidBank() runs on bankd_test_CT {
122 f_init();
123 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100124 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100125 var BankSlot bs := { bankId := 200, slotNr := 0 };
126 var ClientSlot cs := { clientId := 23, slotNr := 42 };
127 f_rspro_srv_create_slotmap(cs, bs, exp_res := illegalBankId);
128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
129}
130
131/* attempt to remove a non-existant mapping */
132testcase TC_removeMapping_unknownMap() runs on bankd_test_CT {
133 f_init();
134 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100135 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100136 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
137 var ClientSlot cs := { clientId := 23, slotNr := 42 };
138 f_rspro_srv_remove_slotmap(cs, bs, exp_res := unknownSlotmap);
139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
140}
141
142/* add and then remove a mapping, expect both to be successful */
143testcase TC_removeMapping() runs on bankd_test_CT {
144 f_init();
145 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100146 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100147 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
148 var ClientSlot cs := { clientId := 23, slotNr := 42 };
149 f_rspro_srv_create_slotmap(cs, bs);
150 f_rspro_srv_remove_slotmap(cs, bs);
151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
152}
153
154/* connect from client to bankd without specifying a clientId */
155testcase TC_clientConnect_missingSlot() runs on bankd_test_CT {
156 f_init_client(0);
157 RSPRO[0].send(ts_RSPRO_ConnectClientReq(rspro[0].rspro_id, omit));
158 f_rspro_exp(tr_RSPRO_ConnectClientRes(?, ResultCode:illegalClientId), 0);
159 f_rspro_exp_disconnect(0);
160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
161}
162
163/* connect from client to bankd using a clientId for which bankd has no map */
164testcase TC_clientConnect_unknown() runs on bankd_test_CT {
165 f_init_client(0);
166 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
168}
169
170/* connect from client to bankd using a clientSlot for which bankd has no map */
171
172
173/* first connect client, then later add matching mapping from server */
174testcase TC_clientConnect_createMapping() runs on bankd_test_CT {
175 f_init_client(0);
176 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
177
178 f_init();
179 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
180
181 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
182 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
183 f_sleep(10.0);
184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
185}
186
187
188/* first add mapping, then connect matching client */
189testcase TC_createMapping_clientConnect() runs on bankd_test_CT {
190 /* FIXME: this would only be done in f_init_client(), but we need it before */
191 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
192
193 f_init();
194 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100195 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100196
197 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
198 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
199
200 f_sleep(1.0);
201
202 f_init_client(0);
203 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
204 /* FIXME: how to determine that bank correctly mapped us */
205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
206}
207
Harald Weltebeba4e52019-12-04 22:09:12 +0100208/* first add mapping, then connect client, then change mapping (expect disconnect) */
209testcase TC_createMapping_connectClient_changeMapping() runs on bankd_test_CT {
210 /* FIXME: this would only be done in f_init_client(), but we need it before */
211 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
212
213 f_init();
214 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
215 f_rspro_srv_reset_state(ok);
216
217 /* create slotmap */
218 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
219 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
220
221 f_sleep(1.0);
222
223 /* connect client */
224 f_init_client(0);
225 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
226 /* FIXME: how to determine that bank correctly mapped us */
227
228 /* create another mapping for the same bank-slot */
229 var ClientSlot cs := { clientId := 987, slotNr := 654 };
230 f_rspro_srv_create_slotmap(cs, bs);
231
232 /* expect client to be disconnected */
233 timer T := 5.0;
234 T.start;
235 alt {
236 [] RSPRO[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
237 setverdict(pass);
238 }
239 [] RSPRO[0].receive {
240 setverdict(fail, "Unexpected RSPRO on client connection");
241 }
242 [] T.timeout {
243 setverdict(fail, "Timeout waiting for client being disconnected");
244 }
245 }
246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
247}
248
249/* first add mapping, then connect client, then re-crete mapping (expect no disconnect) */
250testcase TC_createMapping_connectClient_recreateMapping() runs on bankd_test_CT {
251 /* FIXME: this would only be done in f_init_client(), but we need it before */
252 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
253
254 f_init();
255 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
256 f_rspro_srv_reset_state(ok);
257
258 /* create slotmap */
259 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
260 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
261
262 f_sleep(1.0);
263
264 /* connect client */
265 f_init_client(0);
266 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
267 /* FIXME: how to determine that bank correctly mapped us */
268
269 /* re-create same mapping for the same bank-slot */
270 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
271
272 /* expect client not to be disconnected */
273 timer T := 5.0;
274 T.start;
275 alt {
276 [] RSPRO[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
277 setverdict(fail, "Unexpected client disconnect");
278 }
279 [] RSPRO[0].receive {
280 repeat;
281 }
282 [] T.timeout {
283 setverdict(pass);
284 }
285 }
286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
287}
288
Harald Weltefaa42922019-03-04 18:31:11 +0100289
290
291/* add mapping, connect matching client, disconnect + reconnect */
292testcase TC_createMapping_clientReconnect() runs on bankd_test_CT {
293 /* FIXME: this would only be done in f_init_client(), but we need it before */
294 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
295
296 f_init();
297 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100298 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100299
300 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
301 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
302
303 f_sleep(1.0);
304
305 f_init_client(0);
306 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
307 /* TODO: works only with empty slot, as setAtrReq isn't handled */
308 /* FIXME: how to determine that bank correctly mapped us */
309 f_sleep(5.0);
310 f_rspro_fini(rspro[0], 0);
311
312 f_init_client(0);
313 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
314 /* FIXME: how to determine that bank correctly mapped us */
315 f_sleep(5.0);
316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
317}
318
319
320
321/* remove mapping while client is connected */
322testcase TC_removeMapping_connected() runs on bankd_test_CT {
323 f_init_client(0);
324 f_rspro_connect_client(0, tr_Status_ok_or_nocard);
325 /* TODO: works only with empty slot, as setAtrReq isn't handled */
326
327 f_init();
328 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
329
330 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
331 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
332 /* FIXME: how to determine that bank correctly mapped us */
333 f_sleep(5.0);
334 f_rspro_srv_remove_slotmap(rspro[0].rspro_client_slot, bs);
335 f_rspro_exp_disconnect(0);
336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
337}
338
Harald Welte90732952019-11-22 00:39:43 +0100339private altstep as_vpcd() runs on VPCD_Adapter_CT {
340 [] VPCD.receive(tr_VPCD_Recv(g_vpcd_conn_id, tr_VPCD_CTRL_ATR)) {
341 f_vpcd_send(ts_VPCD_DATA('3B9F96801FC78031A073BE21136743200718000001A5'O));
342 repeat;
343 }
344 [] VPCD.receive(tr_VPCD_Recv(g_vpcd_conn_id, tr_VPCD_CTRL_OFF)) {
345 repeat;
346 }
347 [] VPCD.receive(tr_VPCD_Recv(g_vpcd_conn_id, tr_VPCD_CTRL_ON)) {
348 repeat;
349 }
350}
351
352/* transceive a TPDU from modem to card (and back) */
353function f_rspro_xceive_mdm2card_vpcd(integer idx, BankSlot bs, template (value) octetstring data,
354 template (value) TpduFlags flags, template (value) octetstring res) runs on bankd_test_CT return octetstring {
355 var RsproPDU rx;
356 RSPRO[idx].send(ts_RSPRO_TpduModemToCard(rspro[idx].rspro_client_slot, bs, flags, data));
357 f_vpcd_exp(tr_VPCD_DATA(data));
358 f_vpcd_send(ts_VPCD_DATA(res));
359 rx := f_rspro_exp(tr_RSPRO_TpduCardToModem(bs, rspro[idx].rspro_client_slot, ?, ?));
360 if (rx.msg.tpduCardToModem.data != valueof(res)) {
361 setverdict(fail, "Expected ", res, " from card, but got ", rx.msg.tpduCardToModem.data);
362 }
363 return rx.msg.tpduCardToModem.data;
364}
365
366
Harald Weltefaa42922019-03-04 18:31:11 +0100367/* first add mapping, then connect matching client and exchange some TPDUs */
368testcase TC_createMapping_exchangeTPDU() runs on bankd_test_CT {
369 /* FIXME: this would only be done in f_init_client(), but we need it before */
370 rspro[0].rspro_client_slot := { clientId := 23+0, slotNr := 0 };
371
Harald Welte90732952019-11-22 00:39:43 +0100372 VPCD_Adapter.f_connect();
373 activate(as_vpcd());
374 f_sleep(2.0);
375
Harald Weltefaa42922019-03-04 18:31:11 +0100376 f_init();
377 as_connectBankReq(bid := mp_bank_id, nslots := mp_num_slots);
Harald Welted14ad4c2019-12-04 21:30:29 +0100378 f_rspro_srv_reset_state(ok);
Harald Weltefaa42922019-03-04 18:31:11 +0100379
380 var BankSlot bs := { bankId := mp_bank_id, slotNr := 0 };
381 f_rspro_srv_create_slotmap(rspro[0].rspro_client_slot, bs);
382
383 f_sleep(1.0);
384
385 f_init_client(0);
386 f_rspro_connect_client(0, ok);
387 /* FIXME: how to determine that bank correctly mapped us */
388 f_rspro_exp(tr_RSPRO_SetAtrReq(rspro[0].rspro_client_slot, ?));
389
390 var TpduFlags f := {tpduHeaderPresent:=true, finalPart:=true, procByteContinueTx:=false,
391 procByteContinueRx:=false};
392 for (var integer i := 0; i < 10; i:=i+1) {
Harald Welte90732952019-11-22 00:39:43 +0100393 f_rspro_xceive_mdm2card_vpcd(0, bs, 'A0A40000023F00'O, f, '9000'O);
Harald Weltefaa42922019-03-04 18:31:11 +0100394 }
395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, pass);
396}
397
398
399
400control {
401 execute( TC_connectBankReq_timeout() );
402 execute( TC_connectBankReq() );
403
404 execute( TC_createMapping() );
405 execute( TC_createMapping_busySlot() );
406 execute( TC_createMapping_invalidSlot() );
407 execute( TC_createMapping_invalidBank() );
408
409 execute( TC_removeMapping_unknownMap() );
410 execute( TC_removeMapping() );
411
412 execute( TC_clientConnect_missingSlot() );
413 execute( TC_clientConnect_unknown() );
414 execute( TC_clientConnect_createMapping() );
415 execute( TC_createMapping_clientConnect() );
416 execute( TC_createMapping_clientReconnect() );
417 execute( TC_removeMapping_connected() );
418
Harald Weltebeba4e52019-12-04 22:09:12 +0100419 execute( TC_createMapping_connectClient_changeMapping() );
420 execute( TC_createMapping_connectClient_recreateMapping() );
421
Harald Weltefaa42922019-03-04 18:31:11 +0100422 execute( TC_createMapping_exchangeTPDU() );
423}
424
425
426
427
428
429}