blob: 6d2b27d4af426f5e02c1ebcac953aaf9e6f2c74c [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 {
71 f_http_init(mp_server_ip, mp_rsres_port);
72 f_rsres_post_reset();
73}
74
75type component test_CT extends rspro_client_CT, http_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010076 timer g_T_guard := 60.0;
Harald Weltefaa42922019-03-04 18:31:11 +010077};
78
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010079private altstep as_Tguard() runs on test_CT {
80 [] g_T_guard.timeout {
81 setverdict(fail, "Timeout of T_guard");
82 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
83 }
84}
85
86private function f_init() runs on test_CT {
87 /* Start the guard timer */
88 g_T_guard.start;
89 activate(as_Tguard());
90}
91
Harald Weltefaa42922019-03-04 18:31:11 +010092
Vadim Yanitskiy7d30c572021-02-28 16:46:13 +010093testcase TC_connect_and_nothing() runs on test_CT {
Harald Weltefaa42922019-03-04 18:31:11 +010094 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
95 timer T := 20.0;
96
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +010097 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +010098 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
99 T.start;
100 /* expect that we're disconnected if we never send a ConnectClientReq */
101 alt {
Vadim Yanitskiy61564be2020-05-18 20:44:14 +0700102 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { repeat; }
103 [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Harald Weltefaa42922019-03-04 18:31:11 +0100104 setverdict(pass);
105 }
106 [] T.timeout {
107 setverdict(fail, "Timeout waiting for disconnect");
108 }
109 }
110}
111
112testcase TC_connect_client() runs on test_CT {
113 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
114 var JsRoot js;
115
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100116 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100117 f_rsres_init();
118 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
119 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
120
121 js := f_rsres_get("/api/backend/v1/clients");
122 if (not match(js.clients, JsClients:{})) {
123 setverdict(fail, "Initial state not empty");
124 mtc.stop;
125 }
126 f_rspro_connect_client(0);
127 js := f_rsres_get("/api/backend/v1/clients");
128 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
129 setverdict(fail, "Non-matching JSON response");
130 mtc.stop;
131 }
132 //as_rspro_cfg_client_id(0, cslot);
133 setverdict(pass);
134}
135
Harald Welte7c083af2022-05-03 17:46:25 +0200136/* duplicate connection from Same Client/Slot ID */
137testcase TC_connect_client_duplicate() runs on test_CT {
138 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar"));
139 var JsRoot js;
140
141 f_init();
142 f_rsres_init();
143 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
144 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(13,1));
145
146 js := f_rsres_get("/api/backend/v1/clients");
147 if (not match(js.clients, JsClients:{})) {
148 setverdict(fail, "Initial state not empty");
149 mtc.stop;
150 }
151 f_rspro_connect_client(0);
152 js := f_rsres_get("/api/backend/v1/clients");
153 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
154 setverdict(fail, "Non-matching JSON response");
155 mtc.stop;
156 }
157
158 /* connect a second time for same Client ID */
159 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
160 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(13,1));
161 f_rspro_connect_client(1, identityInUse);
162 f_rspro_exp_disconnect(1);
163
164 /* expect the first connection still to be active */
165 js := f_rsres_get("/api/backend/v1/clients");
166 if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) {
167 setverdict(fail, "Non-matching JSON response");
168 mtc.stop;
169 }
170
171 setverdict(pass);
172}
173
Harald Weltefaa42922019-03-04 18:31:11 +0100174testcase TC_connect_bank() runs on test_CT {
175 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
176 var JsRoot js;
177
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100178 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100179 f_rsres_init();
180 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
181 rspro[0].rspro_bank_id := 1;
182 rspro[0].rspro_bank_nslots := 8;
183
184 js := f_rsres_get("/api/backend/v1/banks");
185 if (not match(js.banks, JsBanks:{})) {
186 setverdict(fail, "Initial state not empty");
187 mtc.stop;
188 }
189 f_rspro_connect_client(0);
190 js := f_rsres_get("/api/backend/v1/banks");
191 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
192 rspro[0].rspro_bank_nslots))) {
193 setverdict(fail, "Non-matching JSON response");
194 mtc.stop;
195 }
196 setverdict(pass);
197}
198
Harald Welte7c083af2022-05-03 17:46:25 +0200199testcase TC_connect_bank_duplicate() runs on test_CT {
200 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar"));
201 var JsRoot js;
202
203 f_init();
204 f_rsres_init();
205 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
206 rspro[0].rspro_bank_id := 1;
207 rspro[0].rspro_bank_nslots := 8;
208
209 js := f_rsres_get("/api/backend/v1/banks");
210 if (not match(js.banks, JsBanks:{})) {
211 setverdict(fail, "Initial state not empty");
212 mtc.stop;
213 }
214 f_rspro_connect_client(0);
215 js := f_rsres_get("/api/backend/v1/banks");
216 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
217 rspro[0].rspro_bank_nslots))) {
218 setverdict(fail, "Non-matching JSON response");
219 mtc.stop;
220 }
221
222 /* connect a second time for same Bank ID */
223 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
224 rspro[1].rspro_bank_id := 1;
225 rspro[1].rspro_bank_nslots := 23;
226 f_rspro_connect_client(1, identityInUse);
227
228 /* expect only the first bank to survive */
229 js := f_rsres_get("/api/backend/v1/banks");
230 if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id,
231 rspro[0].rspro_bank_nslots))) {
232 setverdict(fail, "Non-matching JSON response");
233 mtc.stop;
234 }
235
236 /* wait for T2/rejected timer to expire in server */
237 f_sleep(2.0);
238
239 setverdict(pass);
240}
241
242
Harald Weltefaa42922019-03-04 18:31:11 +0100243function f_ensure_slotmaps(template JsSlotmaps maps)
244runs on http_CT {
245 var JsRoot js;
246
247 /* check that it is actually added */
248 js := f_rsres_get("/api/backend/v1/slotmaps");
249 if (match(js.slotmaps, maps)) {
250 setverdict(pass);
251 } else {
252 setverdict(fail, "Unexpected slotmaps: ", js);
253 }
254}
255
256/* verify that exactly only one slotmap exists (the specified one) */
257function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot,
258 template SlotmapState state := ?)
259runs on http_CT {
260 f_ensure_slotmaps({ tr_JsSlotmap(bslot, cslot, state) } );
261}
262
263/* verify that exactly only one slotmap exists (possibly among others) */
264function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot,
265 template SlotmapState state := ?)
266runs on http_CT {
267 f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } );
268}
269
270
271/* test adding a single slotmap */
272testcase TC_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100273 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100274 f_rsres_init();
275
276 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
277 var HTTPResponse res := f_rsres_post_slotmap(sm);
278
279 /* check that it is actually added */
280 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
281}
282
Harald Welteb12a0ff2020-02-20 18:48:22 +0100283/* test adding a single slotmap with out-of-range values */
284testcase TC_slotmap_add_out_of_range() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100285 f_init();
Harald Welteb12a0ff2020-02-20 18:48:22 +0100286 f_rsres_init();
287
288 var HTTPMessage http_resp;
289 var charstring body;
290
291 body := "{ \"bank\": { \"bankId\": 10000, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
292 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
293 body := body, exp := tr_HTTP_Resp(400));
294
295 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2000 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }";
296 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
297 body := body, exp := tr_HTTP_Resp(400));
298
299 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3000, \"slotNr\": 4 } }";
300 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
301 body := body, exp := tr_HTTP_Resp(400));
302
303 body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4000 } }";
304 http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST",
305 body := body, exp := tr_HTTP_Resp(400));
306}
307
308
Harald Weltefaa42922019-03-04 18:31:11 +0100309/* test adding a slotmap and then connecting a client + bankd */
310testcase TC_slotmap_add_conn_cl_b() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100311 f_init();
312
Harald Weltefaa42922019-03-04 18:31:11 +0100313 /* Simulate one client */
314 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
315 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
316 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
317
318 /* Simulate one bankd */
319 var BankSlot bslot := valueof(ts_BankSlot(1,2));
320 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
321 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
322 rspro[1].rspro_bank_id := bslot.bankId;
323 rspro[1].rspro_bank_nslots := 8
324
325 f_rsres_init();
326 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
327 var HTTPResponse res;
328
329 /* 1) Create a new slotmap via HTTP */
330 res := f_rsres_post_slotmap(sm);
331
332 /* 2) verify that the slotmap exists and is NEW */
333 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
334
335 /* 3) connect a client for that slotmap */
336 f_rspro_connect_client(0);
337
338 /* 4) connect a bankd for that slotmap */
339 f_rspro_connect_client(1);
340
341 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
342 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
343
344 /* 6) expect bankd to receive that mapping */
345 as_rspro_create_mapping(1, sm.client, sm.bank);
346
347 /* 7) verify that the slotmap exists and is ACTIVE */
348 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
349
350 /* 8) expect the client to be configured with bankd side settings */
351 as_rspro_cfg_client_bank(0, bslot, ?);
352}
353
354/* test connecting a client and later adding a slotmap for it */
355testcase TC_conn_cl_b_slotmap_add() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100356 f_init();
357
Harald Weltefaa42922019-03-04 18:31:11 +0100358 /* Simulate one client */
359 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
360 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
361 rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4));
362
363 /* Simulate one bankd */
364 var BankSlot bslot := valueof(ts_BankSlot(1,2));
365 var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename()));
366 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1);
367 rspro[1].rspro_bank_id := bslot.bankId;
368 rspro[1].rspro_bank_nslots := 8
369
370 f_rsres_init();
371 var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot));
372 var HTTPResponse res;
373
374 /* 1) connect a client for that slotmap */
375 f_rspro_connect_client(0);
376
377 /* 2) Create a new slotmap via HTTP */
378 res := f_rsres_post_slotmap(sm);
379
380 /* 3) verify that the slotmap exists and is NEW */
381 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
382
383 /* 4) connect a bankd for that slotmap */
384 f_rspro_connect_client(1);
385
386 /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */
387 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
388
389 /* 6) expect bankd to receive that mapping */
390 as_rspro_create_mapping(1, sm.client, sm.bank);
391
392 /* 7) verify that the slotmap exists and is ACTIVE */
393 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
394
395 /* 8) expect the client to be configured with bankd IP/port */
396 as_rspro_cfg_client_bank(0, bslot, ?);
397}
398
399/* simple delete of a 'NEW' slotmap */
400testcase TC_slotmap_del_new() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100401 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100402 f_rsres_init();
403
404 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
405 var HTTPResponse res := f_rsres_post_slotmap(sm);
406 log(res);
407 res := f_rsres_delete_slotmap(sm.bank);
408 log(res);
409}
410
Harald Welte3993c812020-02-20 10:12:28 +0100411/* simple delete of a non-existant slotmap */
412testcase TC_slotmap_del_nonexistant() runs on test_CT {
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100413 f_init();
Harald Welte3993c812020-02-20 10:12:28 +0100414 f_rsres_init();
415
416 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(11,12), ts_ClientSlot(13,14)));
417 var HTTPResponse res := f_rsres_delete_slotmap(sm.bank, exp_sts:=404);
418 log(res);
419}
420
421
Harald Weltefaa42922019-03-04 18:31:11 +0100422/* simple delete of a 'UNACKNOWLEDGED' slotmap */
423testcase TC_slotmap_del_unack() runs on test_CT {
424 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100425
426 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100427 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
428 rspro[0].rspro_bank_id := 1;
429 rspro[0].rspro_bank_nslots := 8;
430
431 f_rsres_init();
432 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
433 var HTTPResponse res;
434
435 /* Create a new slotmap via HTTP */
436 res := f_rsres_post_slotmap(sm);
437
438 /* verify that the slotmap exists and is NEW */
439 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
440
441 /* connect a bankd for that slotmap */
442 f_rspro_connect_client(0);
443
444 /* expect the slotmap to be pushed to bank but don't ACK it */
445 f_rspro_exp(tr_RSPRO_CreateMappingReq(sm.client, sm.bank));
446
447 /* verify that the slotmap exists and is UNACKNOWLEDGED */
448 f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED);
449
450 /* delete the slotmap via REST */
451 res := f_rsres_delete_slotmap(sm.bank);
452
453 /* verify the slotmap is gone */
454 f_ensure_slotmaps({});
455}
456
Harald Welte77cde212020-02-16 15:35:07 +0100457/* simple delete of a 'ACTIVE' slotmap from server + bankd */
Harald Weltefaa42922019-03-04 18:31:11 +0100458testcase TC_slotmap_del_active() runs on test_CT {
459 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100460
461 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100462 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
463 rspro[0].rspro_bank_id := 1;
464 rspro[0].rspro_bank_nslots := 8;
465
466 f_rsres_init();
467 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
468 var HTTPResponse res;
469
470 /* Create a new slotmap via HTTP */
471 res := f_rsres_post_slotmap(sm);
472
473 /* verify that the slotmap exists and is NEW */
474 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
475
476 /* connect a bankd for that slotmap */
477 f_rspro_connect_client(0);
478
479 /* expect the slotmap to be pushed to bank and ACK it */
480 as_rspro_create_mapping(0, sm.client, sm.bank);
481
482 /* verify that the slotmap exists and is ACTIVE */
483 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
484
485 f_sleep(1.0);
486
487 /* delete the slotmap via REST */
488 res := f_rsres_delete_slotmap(sm.bank);
489
490 /* verify the slotmap is gone from REST interface immediately */
491 f_ensure_slotmaps({});
492
493 /* verify the slotmap is removed from bankd */
494 as_rspro_remove_mapping(0, sm.client, sm.bank);
495}
496
497
Harald Welte77cde212020-02-16 15:35:07 +0100498/* simple delete of a 'ACTIVE' slotmap from client */
499testcase TC_slotmap_del_active_client() runs on test_CT {
500 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100501
502 f_init();
Harald Welte77cde212020-02-16 15:35:07 +0100503 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
504 rspro[0].rspro_bank_id := 1;
505 rspro[0].rspro_bank_nslots := 8;
506
507 rspro_id := valueof(ts_CompId(remsimClient, testcasename()));
508 f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1);
509 rspro[1].rspro_client_slot := valueof(ts_ClientSlot(3,4));
510
511 f_rsres_init();
512 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
513 var HTTPResponse res;
514
515 /* Create a new slotmap via HTTP */
516 res := f_rsres_post_slotmap(sm);
517
518 /* verify that the slotmap exists and is NEW */
519 f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW);
520
521 /* connect a bankd for that slotmap */
522 f_rspro_connect_client(0);
523
524 /* connect a client for that slotmap */
525 f_rspro_connect_client(1);
526
527 /* expect the slotmap to be pushed to bank and ACK it */
528 as_rspro_create_mapping(0, sm.client, sm.bank);
529
530 /* verify that the slotmap exists and is ACTIVE */
531 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
532
533 /* expect the client to be configured with bankd side settings */
534 as_rspro_cfg_client_bank(1, sm.bank, ?/*FIXME*/);
535
536 f_sleep(1.0);
537
538 /* delete the slotmap via REST */
539 res := f_rsres_delete_slotmap(sm.bank);
540
541 /* verify the slotmap is gone from REST interface immediately */
542 f_ensure_slotmaps({});
543
544 /* verify the slotmap is removed from bankd */
545 as_rspro_remove_mapping(0, sm.client, sm.bank);
546
547 /* verify the slotmap is removed from client by setting IP/port to '0' */
548 as_rspro_cfg_client_bank(1, ?, tr_IpPort(ts_IPv4("0.0.0.0"), 0));
549}
550
551
Harald Weltefaa42922019-03-04 18:31:11 +0100552/* Add a slotmap to a currently active bank */
553testcase TC_slotmap_add_active_bank() runs on test_CT {
554 var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename()));
Vadim Yanitskiy0df27dc2021-02-28 17:08:52 +0100555
556 f_init();
Harald Weltefaa42922019-03-04 18:31:11 +0100557 f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0);
558 rspro[0].rspro_bank_id := 1;
559 rspro[0].rspro_bank_nslots := 8;
560
561 f_rsres_init();
562 var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4)));
563 var HTTPResponse res;
564
565 /* connect a bankd for that slotmap */
566 f_rspro_connect_client(0);
567
568 /* Create a new slotmap via HTTP */
569 res := f_rsres_post_slotmap(sm);
570
571 /* expect the slotmap to be pushed to bank and ACK it */
572 as_rspro_create_mapping(0, sm.client, sm.bank);
573
574 /* verify that the slotmap exists and is ACTIVE */
575 f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE);
576}
577
578
579
580
581/* TODO
Harald Weltefaa42922019-03-04 18:31:11 +0100582 * - connect client w/slotmap; delete slotmap via REST (see if it is deleted)
583 * - don't acknowledge delete from client, disconnect client (see if slotmap is deleted)
Harald Weltefaa42922019-03-04 18:31:11 +0100584
585 * - connect from unknown client (name not known, no clientId provisioned?
586 * - add client name/ID mappings from REST API?
587 */
588
589
590control {
591 execute( TC_connect_and_nothing() );
592 execute( TC_connect_client() );
Harald Welte7c083af2022-05-03 17:46:25 +0200593 execute( TC_connect_client_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100594 execute( TC_connect_bank() );
Harald Welte7c083af2022-05-03 17:46:25 +0200595 execute( TC_connect_bank_duplicate() );
Harald Weltefaa42922019-03-04 18:31:11 +0100596 execute( TC_slotmap_add() );
597 execute( TC_slotmap_add_conn_cl_b() );
Harald Welteb12a0ff2020-02-20 18:48:22 +0100598 execute( TC_slotmap_add_out_of_range() );
Harald Weltefaa42922019-03-04 18:31:11 +0100599 execute( TC_conn_cl_b_slotmap_add() );
600 execute( TC_slotmap_del_new() );
Harald Welte3993c812020-02-20 10:12:28 +0100601 execute( TC_slotmap_del_nonexistant() );
Harald Weltefaa42922019-03-04 18:31:11 +0100602 execute( TC_slotmap_del_unack() );
603 execute( TC_slotmap_del_active() );
Harald Welte77cde212020-02-16 15:35:07 +0100604 execute( TC_slotmap_del_active_client() );
Harald Weltefaa42922019-03-04 18:31:11 +0100605 execute( TC_slotmap_add_active_bank() );
606}
607
608
609}