blob: 23ea8cb2b9e6deffa63610aa1f75b55d60f50f6a [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,
Vadim Yanitskiy11f8ac82024-04-25 15:55:10 +070074 http_port := mp_rsres_port,
75 use_ssl := false
Philipp Maier260f7082024-04-19 13:12:49 +020076 };
77 f_http_init(http_adapter_pars);
Harald Weltefaa42922019-03-04 18:31:11 +010078 f_rsres_post_reset();
79}
80
81type component test_CT extends rspro_client_CT, http_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010082 timer g_T_guard := 60.0;
Harald Weltefaa42922019-03-04 18:31:11 +010083};
84
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010085private altstep as_Tguard() runs on test_CT {
86 [] g_T_guard.timeout {
87 setverdict(fail, "Timeout of T_guard");
88 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
89 }
90}
91
92private function f_init() runs on test_CT {
93 /* Start the guard timer */
94 g_T_guard.start;
95 activate(as_Tguard());
96}
97
Harald Weltefaa42922019-03-04 18:31:11 +010098
Vadim Yanitskiy7d30c572021-02-28 16:46:13 +010099testcase TC_connect_and_nothing() runs on test_CT {
Harald Weltefaa42922019-03-04 18:31:11 +0100100 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
101 timer T := 20.0;
102
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100103 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100104 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
105 T.start;
106 /* expect that we're disconnected if we never send a ConnectClientReq */
107 alt {
Vadim Yanitskiy61564be2020-05-18 20:44:14 +0700108 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { repeat; }
109 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Harald Weltefaa42922019-03-04 18:31:11 +0100110 setverdict(pass);
111 }
112 [] T.timeout {
113 setverdict(fail, "Timeout waiting for disconnect");
114 }
115 }
116}
117
118testcase TC_connect_client() runs on test_CT {
119 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
120 var JsRoot js;
121
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100122 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100123 f_rsres_init();
124 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
125 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
126
127 js := f_rsres_get("/api/backend/v1/clients");
128 if (not match(js.clients, JsClients:{})) {
129 setverdict(fail, "Initial state not empty");
130 mtc.stop;
131 }
132 f_rspro_connect_client(0);
133 js := f_rsres_get("/api/backend/v1/clients");
134 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
135 setverdict(fail, "Non-matching JSON response");
136 mtc.stop;
137 }
138 //as_rspro_cfg_client_id(0, cslot);
139 setverdict(pass);
140}
141
Harald Welte7c083af2022-05-03 17:46:25 +0200142/* duplicate connection from Same Client/Slot ID */
143testcase TC_connect_client_duplicate() runs on test_CT {
144 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
145 var JsRoot js;
146
147 f_init();
148 f_rsres_init();
149 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
150 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(13,1));
151
152 js := f_rsres_get("/api/backend/v1/clients");
153 if (not match(js.clients, JsClients:{})) {
154 setverdict(fail, "Initial state not empty");
155 mtc.stop;
156 }
157 f_rspro_connect_client(0);
158 js := f_rsres_get("/api/backend/v1/clients");
159 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
160 setverdict(fail, "Non-matching JSON response");
161 mtc.stop;
162 }
163
164 /* connect a second time for same Client ID */
165 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
166 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(13,1));
167 f_rspro_connect_client(1, identityInUse);
168 f_rspro_exp_disconnect(1);
169
170 /* expect the first connection still to be active */
171 js := f_rsres_get("/api/backend/v1/clients");
172 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
173 setverdict(fail, "Non-matching JSON response");
174 mtc.stop;
175 }
176
177 setverdict(pass);
178}
179
Harald Weltefaa42922019-03-04 18:31:11 +0100180testcase TC_connect_bank() runs on test_CT {
181 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
182 var JsRoot js;
183
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100184 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100185 f_rsres_init();
186 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
187 rspro[0].rspro_bank_id := 1;
188 rspro[0].rspro_bank_nslots := 8;
189
190 js := f_rsres_get("/api/backend/v1/banks");
191 if (not match(js.banks, JsBanks:{})) {
192 setverdict(fail, "Initial state not empty");
193 mtc.stop;
194 }
195 f_rspro_connect_client(0);
196 js := f_rsres_get("/api/backend/v1/banks");
197 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
198 rspro[0].rspro_bank_nslots))) {
199 setverdict(fail, "Non-matching JSON response");
200 mtc.stop;
201 }
202 setverdict(pass);
203}
204
Harald Welte7c083af2022-05-03 17:46:25 +0200205testcase TC_connect_bank_duplicate() runs on test_CT {
206 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
207 var JsRoot js;
208
209 f_init();
210 f_rsres_init();
211 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
212 rspro[0].rspro_bank_id := 1;
213 rspro[0].rspro_bank_nslots := 8;
214
215 js := f_rsres_get("/api/backend/v1/banks");
216 if (not match(js.banks, JsBanks:{})) {
217 setverdict(fail, "Initial state not empty");
218 mtc.stop;
219 }
220 f_rspro_connect_client(0);
221 js := f_rsres_get("/api/backend/v1/banks");
222 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
223 rspro[0].rspro_bank_nslots))) {
224 setverdict(fail, "Non-matching JSON response");
225 mtc.stop;
226 }
227
228 /* connect a second time for same Bank ID */
229 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
230 rspro[1].rspro_bank_id := 1;
231 rspro[1].rspro_bank_nslots := 23;
232 f_rspro_connect_client(1, identityInUse);
233
234 /* expect only the first bank to survive */
235 js := f_rsres_get("/api/backend/v1/banks");
236 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
237 rspro[0].rspro_bank_nslots))) {
238 setverdict(fail, "Non-matching JSON response");
239 mtc.stop;
240 }
241
242 /* wait for T2/rejected timer to expire in server */
243 f_sleep(2.0);
244
245 setverdict(pass);
246}
247
248
Harald Weltefaa42922019-03-04 18:31:11 +0100249function f_ensure_slotmaps(template JsSlotmaps maps)
250runs on http_CT {
251 var JsRoot js;
252
253 /* check that it is actually added */
254 js := f_rsres_get("/api/backend/v1/slotmaps");
255 if (match(js.slotmaps, maps)) {
256 setverdict(pass);
257 } else {
258 setverdict(fail, "Unexpected slotmaps: ", js);
259 }
260}
261
262/* verify that exactly only one slotmap exists (the specified one) */
263function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot,
264 template SlotmapState state := ?)
265runs on http_CT {
266 f_ensure_slotmaps({ tr_JsSlotmap(bslot, cslot, state) } );
267}
268
269/* verify that exactly only one slotmap exists (possibly among others) */
270function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot,
271 template SlotmapState state := ?)
272runs on http_CT {
273 f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } );
274}
275
276
277/* test adding a single slotmap */
278testcase TC_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100279 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100280 f_rsres_init();
281
282 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
283 var HTTPResponse res := f_rsres_post_slotmap(sm);
284
285 /* check that it is actually added */
286 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
287}
288
Harald Welteb12a0ff2020-02-20 18:48:22 +0100289/* test adding a single slotmap with out-of-range values */
290testcase TC_slotmap_add_out_of_range() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100291 f_init();
Harald Welteb12a0ff2020-02-20 18:48:22 +0100292 f_rsres_init();
293
294 var HTTPMessage http_resp;
295 var charstring body;
296
297 body := "{ \"bank\": { \"bankId\": 10000, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
298 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
299 body := body, exp := tr_HTTP_Resp(400));
300
301 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2000 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
302 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
303 body := body, exp := tr_HTTP_Resp(400));
304
305 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3000, \"slotNr\": 4 } }";
306 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
307 body := body, exp := tr_HTTP_Resp(400));
308
309 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4000 } }";
310 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
311 body := body, exp := tr_HTTP_Resp(400));
312}
313
314
Harald Weltefaa42922019-03-04 18:31:11 +0100315/* test adding a slotmap and then connecting a client + bankd */
316testcase TC_slotmap_add_conn_cl_b() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100317 f_init();
318
Harald Weltefaa42922019-03-04 18:31:11 +0100319 /* Simulate one client */
320 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
321 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
322 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
323
324 /* Simulate one bankd */
325 var BankSlot bslot := valueof(ts_BankSlot(1,2));
326 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
327 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
328 rspro[1].rspro_bank_id := bslot.bankId;
329 rspro[1].rspro_bank_nslots := 8
330
331 f_rsres_init();
332 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
333 var HTTPResponse res;
334
335 /* 1) Create a new slotmap via HTTP */
336 res := f_rsres_post_slotmap(sm);
337
338 /* 2) verify that the slotmap exists and is NEW */
339 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
340
341 /* 3) connect a client for that slotmap */
342 f_rspro_connect_client(0);
343
344 /* 4) connect a bankd for that slotmap */
345 f_rspro_connect_client(1);
346
347 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
348 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
349
350 /* 6) expect bankd to receive that mapping */
351 as_rspro_create_mapping(1, sm.client, sm.bank);
352
353 /* 7) verify that the slotmap exists and is ACTIVE */
354 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
355
356 /* 8) expect the client to be configured with bankd side settings */
357 as_rspro_cfg_client_bank(0, bslot, ?);
358}
359
360/* test connecting a client and later adding a slotmap for it */
361testcase TC_conn_cl_b_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100362 f_init();
363
Harald Weltefaa42922019-03-04 18:31:11 +0100364 /* Simulate one client */
365 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
366 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
367 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
368
369 /* Simulate one bankd */
370 var BankSlot bslot := valueof(ts_BankSlot(1,2));
371 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
372 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
373 rspro[1].rspro_bank_id := bslot.bankId;
374 rspro[1].rspro_bank_nslots := 8
375
376 f_rsres_init();
377 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
378 var HTTPResponse res;
379
380 /* 1) connect a client for that slotmap */
381 f_rspro_connect_client(0);
382
383 /* 2) Create a new slotmap via HTTP */
384 res := f_rsres_post_slotmap(sm);
385
386 /* 3) verify that the slotmap exists and is NEW */
387 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
388
389 /* 4) connect a bankd for that slotmap */
390 f_rspro_connect_client(1);
391
392 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
393 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
394
395 /* 6) expect bankd to receive that mapping */
396 as_rspro_create_mapping(1, sm.client, sm.bank);
397
398 /* 7) verify that the slotmap exists and is ACTIVE */
399 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
400
401 /* 8) expect the client to be configured with bankd IP/port */
402 as_rspro_cfg_client_bank(0, bslot, ?);
403}
404
405/* simple delete of a 'NEW' slotmap */
406testcase TC_slotmap_del_new() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100407 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100408 f_rsres_init();
409
410 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
411 var HTTPResponse res := f_rsres_post_slotmap(sm);
412 log(res);
413 res := f_rsres_delete_slotmap(sm.bank);
414 log(res);
415}
416
Harald Welte3993c812020-02-20 10:12:28 +0100417/* simple delete of a non-existant slotmap */
418testcase TC_slotmap_del_nonexistant() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100419 f_init();
Harald Welte3993c812020-02-20 10:12:28 +0100420 f_rsres_init();
421
422 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(11,12), ts_ClientSlot(13,14)));
423 var HTTPResponse res := f_rsres_delete_slotmap(sm.bank, exp_sts:=404);
424 log(res);
425}
426
427
Harald Weltefaa42922019-03-04 18:31:11 +0100428/* simple delete of a 'UNACKNOWLEDGED' slotmap */
429testcase TC_slotmap_del_unack() runs on test_CT {
430 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100431
432 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100433 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
434 rspro[0].rspro_bank_id := 1;
435 rspro[0].rspro_bank_nslots := 8;
436
437 f_rsres_init();
438 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
439 var HTTPResponse res;
440
441 /* Create a new slotmap via HTTP */
442 res := f_rsres_post_slotmap(sm);
443
444 /* verify that the slotmap exists and is NEW */
445 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
446
447 /* connect a bankd for that slotmap */
448 f_rspro_connect_client(0);
449
450 /* expect the slotmap to be pushed to bank but don't ACK it */
451 f_rspro_exp(tr_RSPRO_CreateMappingReq(sm.client, sm.bank));
452
453 /* verify that the slotmap exists and is UNACKNOWLEDGED */
454 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
455
456 /* delete the slotmap via REST */
457 res := f_rsres_delete_slotmap(sm.bank);
458
459 /* verify the slotmap is gone */
460 f_ensure_slotmaps({});
461}
462
Harald Welte77cde212020-02-16 15:35:07 +0100463/* simple delete of a 'ACTIVE' slotmap from server + bankd */
Harald Weltefaa42922019-03-04 18:31:11 +0100464testcase TC_slotmap_del_active() runs on test_CT {
465 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100466
467 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100468 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
469 rspro[0].rspro_bank_id := 1;
470 rspro[0].rspro_bank_nslots := 8;
471
472 f_rsres_init();
473 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
474 var HTTPResponse res;
475
476 /* Create a new slotmap via HTTP */
477 res := f_rsres_post_slotmap(sm);
478
479 /* verify that the slotmap exists and is NEW */
480 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
481
482 /* connect a bankd for that slotmap */
483 f_rspro_connect_client(0);
484
485 /* expect the slotmap to be pushed to bank and ACK it */
486 as_rspro_create_mapping(0, sm.client, sm.bank);
487
488 /* verify that the slotmap exists and is ACTIVE */
489 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
490
491 f_sleep(1.0);
492
493 /* delete the slotmap via REST */
494 res := f_rsres_delete_slotmap(sm.bank);
495
496 /* verify the slotmap is gone from REST interface immediately */
497 f_ensure_slotmaps({});
498
499 /* verify the slotmap is removed from bankd */
500 as_rspro_remove_mapping(0, sm.client, sm.bank);
501}
502
503
Harald Welte77cde212020-02-16 15:35:07 +0100504/* simple delete of a 'ACTIVE' slotmap from client */
505testcase TC_slotmap_del_active_client() runs on test_CT {
506 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100507
508 f_init();
Harald Welte77cde212020-02-16 15:35:07 +0100509 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
510 rspro[0].rspro_bank_id := 1;
511 rspro[0].rspro_bank_nslots := 8;
512
513 rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
514 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
515 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(3,4));
516
517 f_rsres_init();
518 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
519 var HTTPResponse res;
520
521 /* Create a new slotmap via HTTP */
522 res := f_rsres_post_slotmap(sm);
523
524 /* verify that the slotmap exists and is NEW */
525 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
526
527 /* connect a bankd for that slotmap */
528 f_rspro_connect_client(0);
529
530 /* connect a client for that slotmap */
531 f_rspro_connect_client(1);
532
533 /* expect the slotmap to be pushed to bank and ACK it */
534 as_rspro_create_mapping(0, sm.client, sm.bank);
535
536 /* verify that the slotmap exists and is ACTIVE */
537 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
538
539 /* expect the client to be configured with bankd side settings */
540 as_rspro_cfg_client_bank(1, sm.bank, ?/*FIXME*/);
541
542 f_sleep(1.0);
543
544 /* delete the slotmap via REST */
545 res := f_rsres_delete_slotmap(sm.bank);
546
547 /* verify the slotmap is gone from REST interface immediately */
548 f_ensure_slotmaps({});
549
550 /* verify the slotmap is removed from bankd */
551 as_rspro_remove_mapping(0, sm.client, sm.bank);
552
553 /* verify the slotmap is removed from client by setting IP/port to '0' */
554 as_rspro_cfg_client_bank(1, ?, tr_IpPort(ts_IPv4("0.0.0.0"), 0));
555}
556
557
Harald Weltefaa42922019-03-04 18:31:11 +0100558/* Add a slotmap to a currently active bank */
559testcase TC_slotmap_add_active_bank() runs on test_CT {
560 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100561
562 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100563 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
564 rspro[0].rspro_bank_id := 1;
565 rspro[0].rspro_bank_nslots := 8;
566
567 f_rsres_init();
568 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
569 var HTTPResponse res;
570
571 /* connect a bankd for that slotmap */
572 f_rspro_connect_client(0);
573
574 /* Create a new slotmap via HTTP */
575 res := f_rsres_post_slotmap(sm);
576
577 /* expect the slotmap to be pushed to bank and ACK it */
578 as_rspro_create_mapping(0, sm.client, sm.bank);
579
580 /* verify that the slotmap exists and is ACTIVE */
581 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
582}
583
584
585
586
587/* TODO
Harald Weltefaa42922019-03-04 18:31:11 +0100588 * - connect client w/slotmap; delete slotmap via REST (see if it is deleted)
589 * - don't acknowledge delete from client, disconnect client (see if slotmap is deleted)
Harald Weltefaa42922019-03-04 18:31:11 +0100590
591 * - connect from unknown client (name not known, no clientId provisioned?
592 * - add client name/ID mappings from REST API?
593 */
594
595
596control {
597 execute( TC_connect_and_nothing() );
598 execute( TC_connect_client() );
Harald Welte7c083af2022-05-03 17:46:25 +0200599 execute( TC_connect_client_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100600 execute( TC_connect_bank() );
Harald Welte7c083af2022-05-03 17:46:25 +0200601 execute( TC_connect_bank_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100602 execute( TC_slotmap_add() );
603 execute( TC_slotmap_add_conn_cl_b() );
Harald Welteb12a0ff2020-02-20 18:48:22 +0100604 execute( TC_slotmap_add_out_of_range() );
Harald Weltefaa42922019-03-04 18:31:11 +0100605 execute( TC_conn_cl_b_slotmap_add() );
606 execute( TC_slotmap_del_new() );
Harald Welte3993c812020-02-20 10:12:28 +0100607 execute( TC_slotmap_del_nonexistant() );
Harald Weltefaa42922019-03-04 18:31:11 +0100608 execute( TC_slotmap_del_unack() );
609 execute( TC_slotmap_del_active() );
Harald Welte77cde212020-02-16 15:35:07 +0100610 execute( TC_slotmap_del_active_client() );
Harald Weltefaa42922019-03-04 18:31:11 +0100611 execute( TC_slotmap_add_active_bank() );
612}
613
614
615}