blob: 94529b293b1e716a11d4658ad43dfaee8e3f0b81 [file] [log] [blame]
Harald Weltefaa42922019-03-04 18:31:11 +01001module RemsimServer_Tests {
2
3/* Integration Tests for osmo-remsim-server
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-server by attaching to the external interfaces
13 * such as RSPRO for simulated clients + bankds and RSRES (REST backend interface).
14 */
15
16import from Osmocom_Types all;
17
18import from RSPRO all;
19import from RSRES all;
20import from RSPRO_Types all;
21import from REMSIM_Tests all;
22
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010023import from Misc_Helpers all;
Harald Weltefaa42922019-03-04 18:31:11 +010024import from IPA_Emulation all;
25
26import from HTTPmsg_Types all;
27import from HTTPmsg_PortType all;
Harald Welte55e879c2021-02-19 13:16:28 +010028import from HTTP_Adapter all;
Harald Weltefaa42922019-03-04 18:31:11 +010029import from JSON_Types all;
30
Harald Weltefaa42922019-03-04 18:31:11 +010031/* run a HTTP GET on specified URL expecting json in RSRES format as response */
32function f_rsres_get(charstring url, template integer exp_sts := 200)
33runs on http_CT return JsRoot {
34 var HTTPMessage http_resp;
35 http_resp := f_http_transact(url, exp := tr_HTTP_Resp(exp_sts));
36 return f_dec_JsRoot(char2oct(http_resp.response.body));
37}
38
39/* run a HTTP PUT to add a new slotmap to the remsim-server */
40function f_rsres_post_slotmap(JsSlotmap slotmap, template integer exp_sts := 201)
41runs on http_CT return HTTPResponse {
42 var charstring body := oct2char(f_enc_JsSlotmap(slotmap));
43 var HTTPMessage http_resp;
44 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
45 body := body, exp := tr_HTTP_Resp(exp_sts))
46 return http_resp.response;
47}
48
49/* run a HTTP PUT to add a new slotmap to the remsim-server */
50function f_rsres_post_reset(template integer exp_sts := 200)
51runs on http_CT return HTTPResponse {
52 var HTTPMessage http_resp;
53 http_resp := f_http_transact(url := "/api/backend/v1/global-reset", method := "POST",
54 body := "", exp := tr_HTTP_Resp(exp_sts))
55 return http_resp.response;
56}
57
58
59/* run a HTTP DELETE to remove a slotmap from te remsim-server */
60function f_rsres_delete_slotmap(BankSlot bs, template integer exp_sts := 200)
61runs on http_CT return HTTPResponse {
62 var HTTPMessage http_resp;
63 var integer slotmap_id := bs.bankId * 65536 + bs.slotNr;
64 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps/" & int2str(slotmap_id),
65 method := "DELETE", exp := tr_HTTP_Resp(exp_sts));
66 return http_resp.response;
67}
68
69
70function f_rsres_init() runs on http_CT {
Philipp Maier260f7082024-04-19 13:12:49 +020071 var HTTP_Adapter_Params http_adapter_pars;
72 http_adapter_pars := {
73 http_host := mp_server_ip,
74 http_port := mp_rsres_port
75 };
76 f_http_init(http_adapter_pars);
Harald Weltefaa42922019-03-04 18:31:11 +010077 f_rsres_post_reset();
78}
79
80type component test_CT extends rspro_client_CT, http_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010081 timer g_T_guard := 60.0;
Harald Weltefaa42922019-03-04 18:31:11 +010082};
83
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010084private altstep as_Tguard() runs on test_CT {
85 [] g_T_guard.timeout {
86 setverdict(fail, "Timeout of T_guard");
87 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
88 }
89}
90
91private function f_init() runs on test_CT {
92 /* Start the guard timer */
93 g_T_guard.start;
94 activate(as_Tguard());
95}
96
Harald Weltefaa42922019-03-04 18:31:11 +010097
Vadim Yanitskiy7d30c572021-02-28 16:46:13 +010098testcase TC_connect_and_nothing() runs on test_CT {
Harald Weltefaa42922019-03-04 18:31:11 +010099 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
100 timer T := 20.0;
101
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100102 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100103 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
104 T.start;
105 /* expect that we're disconnected if we never send a ConnectClientReq */
106 alt {
Vadim Yanitskiy61564be2020-05-18 20:44:14 +0700107 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { repeat; }
108 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Harald Weltefaa42922019-03-04 18:31:11 +0100109 setverdict(pass);
110 }
111 [] T.timeout {
112 setverdict(fail, "Timeout waiting for disconnect");
113 }
114 }
115}
116
117testcase TC_connect_client() runs on test_CT {
118 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
119 var JsRoot js;
120
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100121 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100122 f_rsres_init();
123 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
124 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
125
126 js := f_rsres_get("/api/backend/v1/clients");
127 if (not match(js.clients, JsClients:{})) {
128 setverdict(fail, "Initial state not empty");
129 mtc.stop;
130 }
131 f_rspro_connect_client(0);
132 js := f_rsres_get("/api/backend/v1/clients");
133 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
134 setverdict(fail, "Non-matching JSON response");
135 mtc.stop;
136 }
137 //as_rspro_cfg_client_id(0, cslot);
138 setverdict(pass);
139}
140
Harald Welte7c083af2022-05-03 17:46:25 +0200141/* duplicate connection from Same Client/Slot ID */
142testcase TC_connect_client_duplicate() runs on test_CT {
143 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
144 var JsRoot js;
145
146 f_init();
147 f_rsres_init();
148 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
149 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(13,1));
150
151 js := f_rsres_get("/api/backend/v1/clients");
152 if (not match(js.clients, JsClients:{})) {
153 setverdict(fail, "Initial state not empty");
154 mtc.stop;
155 }
156 f_rspro_connect_client(0);
157 js := f_rsres_get("/api/backend/v1/clients");
158 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
159 setverdict(fail, "Non-matching JSON response");
160 mtc.stop;
161 }
162
163 /* connect a second time for same Client ID */
164 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
165 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(13,1));
166 f_rspro_connect_client(1, identityInUse);
167 f_rspro_exp_disconnect(1);
168
169 /* expect the first connection still to be active */
170 js := f_rsres_get("/api/backend/v1/clients");
171 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
172 setverdict(fail, "Non-matching JSON response");
173 mtc.stop;
174 }
175
176 setverdict(pass);
177}
178
Harald Weltefaa42922019-03-04 18:31:11 +0100179testcase TC_connect_bank() runs on test_CT {
180 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
181 var JsRoot js;
182
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100183 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100184 f_rsres_init();
185 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
186 rspro[0].rspro_bank_id := 1;
187 rspro[0].rspro_bank_nslots := 8;
188
189 js := f_rsres_get("/api/backend/v1/banks");
190 if (not match(js.banks, JsBanks:{})) {
191 setverdict(fail, "Initial state not empty");
192 mtc.stop;
193 }
194 f_rspro_connect_client(0);
195 js := f_rsres_get("/api/backend/v1/banks");
196 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
197 rspro[0].rspro_bank_nslots))) {
198 setverdict(fail, "Non-matching JSON response");
199 mtc.stop;
200 }
201 setverdict(pass);
202}
203
Harald Welte7c083af2022-05-03 17:46:25 +0200204testcase TC_connect_bank_duplicate() runs on test_CT {
205 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
206 var JsRoot js;
207
208 f_init();
209 f_rsres_init();
210 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
211 rspro[0].rspro_bank_id := 1;
212 rspro[0].rspro_bank_nslots := 8;
213
214 js := f_rsres_get("/api/backend/v1/banks");
215 if (not match(js.banks, JsBanks:{})) {
216 setverdict(fail, "Initial state not empty");
217 mtc.stop;
218 }
219 f_rspro_connect_client(0);
220 js := f_rsres_get("/api/backend/v1/banks");
221 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
222 rspro[0].rspro_bank_nslots))) {
223 setverdict(fail, "Non-matching JSON response");
224 mtc.stop;
225 }
226
227 /* connect a second time for same Bank ID */
228 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
229 rspro[1].rspro_bank_id := 1;
230 rspro[1].rspro_bank_nslots := 23;
231 f_rspro_connect_client(1, identityInUse);
232
233 /* expect only the first bank to survive */
234 js := f_rsres_get("/api/backend/v1/banks");
235 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
236 rspro[0].rspro_bank_nslots))) {
237 setverdict(fail, "Non-matching JSON response");
238 mtc.stop;
239 }
240
241 /* wait for T2/rejected timer to expire in server */
242 f_sleep(2.0);
243
244 setverdict(pass);
245}
246
247
Harald Weltefaa42922019-03-04 18:31:11 +0100248function f_ensure_slotmaps(template JsSlotmaps maps)
249runs on http_CT {
250 var JsRoot js;
251
252 /* check that it is actually added */
253 js := f_rsres_get("/api/backend/v1/slotmaps");
254 if (match(js.slotmaps, maps)) {
255 setverdict(pass);
256 } else {
257 setverdict(fail, "Unexpected slotmaps: ", js);
258 }
259}
260
261/* verify that exactly only one slotmap exists (the specified one) */
262function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot,
263 template SlotmapState state := ?)
264runs on http_CT {
265 f_ensure_slotmaps({ tr_JsSlotmap(bslot, cslot, state) } );
266}
267
268/* verify that exactly only one slotmap exists (possibly among others) */
269function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot,
270 template SlotmapState state := ?)
271runs on http_CT {
272 f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } );
273}
274
275
276/* test adding a single slotmap */
277testcase TC_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100278 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100279 f_rsres_init();
280
281 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
282 var HTTPResponse res := f_rsres_post_slotmap(sm);
283
284 /* check that it is actually added */
285 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
286}
287
Harald Welteb12a0ff2020-02-20 18:48:22 +0100288/* test adding a single slotmap with out-of-range values */
289testcase TC_slotmap_add_out_of_range() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100290 f_init();
Harald Welteb12a0ff2020-02-20 18:48:22 +0100291 f_rsres_init();
292
293 var HTTPMessage http_resp;
294 var charstring body;
295
296 body := "{ \"bank\": { \"bankId\": 10000, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
297 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
298 body := body, exp := tr_HTTP_Resp(400));
299
300 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2000 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
301 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
302 body := body, exp := tr_HTTP_Resp(400));
303
304 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3000, \"slotNr\": 4 } }";
305 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
306 body := body, exp := tr_HTTP_Resp(400));
307
308 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4000 } }";
309 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
310 body := body, exp := tr_HTTP_Resp(400));
311}
312
313
Harald Weltefaa42922019-03-04 18:31:11 +0100314/* test adding a slotmap and then connecting a client + bankd */
315testcase TC_slotmap_add_conn_cl_b() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100316 f_init();
317
Harald Weltefaa42922019-03-04 18:31:11 +0100318 /* Simulate one client */
319 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
320 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
321 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
322
323 /* Simulate one bankd */
324 var BankSlot bslot := valueof(ts_BankSlot(1,2));
325 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
326 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
327 rspro[1].rspro_bank_id := bslot.bankId;
328 rspro[1].rspro_bank_nslots := 8
329
330 f_rsres_init();
331 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
332 var HTTPResponse res;
333
334 /* 1) Create a new slotmap via HTTP */
335 res := f_rsres_post_slotmap(sm);
336
337 /* 2) verify that the slotmap exists and is NEW */
338 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
339
340 /* 3) connect a client for that slotmap */
341 f_rspro_connect_client(0);
342
343 /* 4) connect a bankd for that slotmap */
344 f_rspro_connect_client(1);
345
346 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
347 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
348
349 /* 6) expect bankd to receive that mapping */
350 as_rspro_create_mapping(1, sm.client, sm.bank);
351
352 /* 7) verify that the slotmap exists and is ACTIVE */
353 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
354
355 /* 8) expect the client to be configured with bankd side settings */
356 as_rspro_cfg_client_bank(0, bslot, ?);
357}
358
359/* test connecting a client and later adding a slotmap for it */
360testcase TC_conn_cl_b_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100361 f_init();
362
Harald Weltefaa42922019-03-04 18:31:11 +0100363 /* Simulate one client */
364 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
365 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
366 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
367
368 /* Simulate one bankd */
369 var BankSlot bslot := valueof(ts_BankSlot(1,2));
370 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
371 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
372 rspro[1].rspro_bank_id := bslot.bankId;
373 rspro[1].rspro_bank_nslots := 8
374
375 f_rsres_init();
376 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
377 var HTTPResponse res;
378
379 /* 1) connect a client for that slotmap */
380 f_rspro_connect_client(0);
381
382 /* 2) Create a new slotmap via HTTP */
383 res := f_rsres_post_slotmap(sm);
384
385 /* 3) verify that the slotmap exists and is NEW */
386 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
387
388 /* 4) connect a bankd for that slotmap */
389 f_rspro_connect_client(1);
390
391 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
392 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
393
394 /* 6) expect bankd to receive that mapping */
395 as_rspro_create_mapping(1, sm.client, sm.bank);
396
397 /* 7) verify that the slotmap exists and is ACTIVE */
398 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
399
400 /* 8) expect the client to be configured with bankd IP/port */
401 as_rspro_cfg_client_bank(0, bslot, ?);
402}
403
404/* simple delete of a 'NEW' slotmap */
405testcase TC_slotmap_del_new() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100406 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100407 f_rsres_init();
408
409 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
410 var HTTPResponse res := f_rsres_post_slotmap(sm);
411 log(res);
412 res := f_rsres_delete_slotmap(sm.bank);
413 log(res);
414}
415
Harald Welte3993c812020-02-20 10:12:28 +0100416/* simple delete of a non-existant slotmap */
417testcase TC_slotmap_del_nonexistant() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100418 f_init();
Harald Welte3993c812020-02-20 10:12:28 +0100419 f_rsres_init();
420
421 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(11,12), ts_ClientSlot(13,14)));
422 var HTTPResponse res := f_rsres_delete_slotmap(sm.bank, exp_sts:=404);
423 log(res);
424}
425
426
Harald Weltefaa42922019-03-04 18:31:11 +0100427/* simple delete of a 'UNACKNOWLEDGED' slotmap */
428testcase TC_slotmap_del_unack() runs on test_CT {
429 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100430
431 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100432 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
433 rspro[0].rspro_bank_id := 1;
434 rspro[0].rspro_bank_nslots := 8;
435
436 f_rsres_init();
437 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
438 var HTTPResponse res;
439
440 /* Create a new slotmap via HTTP */
441 res := f_rsres_post_slotmap(sm);
442
443 /* verify that the slotmap exists and is NEW */
444 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
445
446 /* connect a bankd for that slotmap */
447 f_rspro_connect_client(0);
448
449 /* expect the slotmap to be pushed to bank but don't ACK it */
450 f_rspro_exp(tr_RSPRO_CreateMappingReq(sm.client, sm.bank));
451
452 /* verify that the slotmap exists and is UNACKNOWLEDGED */
453 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
454
455 /* delete the slotmap via REST */
456 res := f_rsres_delete_slotmap(sm.bank);
457
458 /* verify the slotmap is gone */
459 f_ensure_slotmaps({});
460}
461
Harald Welte77cde212020-02-16 15:35:07 +0100462/* simple delete of a 'ACTIVE' slotmap from server + bankd */
Harald Weltefaa42922019-03-04 18:31:11 +0100463testcase TC_slotmap_del_active() runs on test_CT {
464 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100465
466 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100467 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
468 rspro[0].rspro_bank_id := 1;
469 rspro[0].rspro_bank_nslots := 8;
470
471 f_rsres_init();
472 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
473 var HTTPResponse res;
474
475 /* Create a new slotmap via HTTP */
476 res := f_rsres_post_slotmap(sm);
477
478 /* verify that the slotmap exists and is NEW */
479 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
480
481 /* connect a bankd for that slotmap */
482 f_rspro_connect_client(0);
483
484 /* expect the slotmap to be pushed to bank and ACK it */
485 as_rspro_create_mapping(0, sm.client, sm.bank);
486
487 /* verify that the slotmap exists and is ACTIVE */
488 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
489
490 f_sleep(1.0);
491
492 /* delete the slotmap via REST */
493 res := f_rsres_delete_slotmap(sm.bank);
494
495 /* verify the slotmap is gone from REST interface immediately */
496 f_ensure_slotmaps({});
497
498 /* verify the slotmap is removed from bankd */
499 as_rspro_remove_mapping(0, sm.client, sm.bank);
500}
501
502
Harald Welte77cde212020-02-16 15:35:07 +0100503/* simple delete of a 'ACTIVE' slotmap from client */
504testcase TC_slotmap_del_active_client() runs on test_CT {
505 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100506
507 f_init();
Harald Welte77cde212020-02-16 15:35:07 +0100508 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
509 rspro[0].rspro_bank_id := 1;
510 rspro[0].rspro_bank_nslots := 8;
511
512 rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
513 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
514 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(3,4));
515
516 f_rsres_init();
517 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
518 var HTTPResponse res;
519
520 /* Create a new slotmap via HTTP */
521 res := f_rsres_post_slotmap(sm);
522
523 /* verify that the slotmap exists and is NEW */
524 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
525
526 /* connect a bankd for that slotmap */
527 f_rspro_connect_client(0);
528
529 /* connect a client for that slotmap */
530 f_rspro_connect_client(1);
531
532 /* expect the slotmap to be pushed to bank and ACK it */
533 as_rspro_create_mapping(0, sm.client, sm.bank);
534
535 /* verify that the slotmap exists and is ACTIVE */
536 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
537
538 /* expect the client to be configured with bankd side settings */
539 as_rspro_cfg_client_bank(1, sm.bank, ?/*FIXME*/);
540
541 f_sleep(1.0);
542
543 /* delete the slotmap via REST */
544 res := f_rsres_delete_slotmap(sm.bank);
545
546 /* verify the slotmap is gone from REST interface immediately */
547 f_ensure_slotmaps({});
548
549 /* verify the slotmap is removed from bankd */
550 as_rspro_remove_mapping(0, sm.client, sm.bank);
551
552 /* verify the slotmap is removed from client by setting IP/port to '0' */
553 as_rspro_cfg_client_bank(1, ?, tr_IpPort(ts_IPv4("0.0.0.0"), 0));
554}
555
556
Harald Weltefaa42922019-03-04 18:31:11 +0100557/* Add a slotmap to a currently active bank */
558testcase TC_slotmap_add_active_bank() runs on test_CT {
559 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100560
561 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100562 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
563 rspro[0].rspro_bank_id := 1;
564 rspro[0].rspro_bank_nslots := 8;
565
566 f_rsres_init();
567 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
568 var HTTPResponse res;
569
570 /* connect a bankd for that slotmap */
571 f_rspro_connect_client(0);
572
573 /* Create a new slotmap via HTTP */
574 res := f_rsres_post_slotmap(sm);
575
576 /* expect the slotmap to be pushed to bank and ACK it */
577 as_rspro_create_mapping(0, sm.client, sm.bank);
578
579 /* verify that the slotmap exists and is ACTIVE */
580 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
581}
582
583
584
585
586/* TODO
Harald Weltefaa42922019-03-04 18:31:11 +0100587 * - connect client w/slotmap; delete slotmap via REST (see if it is deleted)
588 * - don't acknowledge delete from client, disconnect client (see if slotmap is deleted)
Harald Weltefaa42922019-03-04 18:31:11 +0100589
590 * - connect from unknown client (name not known, no clientId provisioned?
591 * - add client name/ID mappings from REST API?
592 */
593
594
595control {
596 execute( TC_connect_and_nothing() );
597 execute( TC_connect_client() );
Harald Welte7c083af2022-05-03 17:46:25 +0200598 execute( TC_connect_client_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100599 execute( TC_connect_bank() );
Harald Welte7c083af2022-05-03 17:46:25 +0200600 execute( TC_connect_bank_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100601 execute( TC_slotmap_add() );
602 execute( TC_slotmap_add_conn_cl_b() );
Harald Welteb12a0ff2020-02-20 18:48:22 +0100603 execute( TC_slotmap_add_out_of_range() );
Harald Weltefaa42922019-03-04 18:31:11 +0100604 execute( TC_conn_cl_b_slotmap_add() );
605 execute( TC_slotmap_del_new() );
Harald Welte3993c812020-02-20 10:12:28 +0100606 execute( TC_slotmap_del_nonexistant() );
Harald Weltefaa42922019-03-04 18:31:11 +0100607 execute( TC_slotmap_del_unack() );
608 execute( TC_slotmap_del_active() );
Harald Welte77cde212020-02-16 15:35:07 +0100609 execute( TC_slotmap_del_active_client() );
Harald Weltefaa42922019-03-04 18:31:11 +0100610 execute( TC_slotmap_add_active_bank() );
611}
612
613
614}