Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 1 | module 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 | |
| 16 | import from Osmocom_Types all; |
| 17 | |
| 18 | import from RSPRO all; |
| 19 | import from RSRES all; |
| 20 | import from RSPRO_Types all; |
| 21 | import from REMSIM_Tests all; |
| 22 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 23 | import from Misc_Helpers all; |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 24 | import from IPA_Emulation all; |
| 25 | |
| 26 | import from HTTPmsg_Types all; |
| 27 | import from HTTPmsg_PortType all; |
Harald Welte | 55e879c | 2021-02-19 13:16:28 +0100 | [diff] [blame] | 28 | import from HTTP_Adapter all; |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 29 | import from JSON_Types all; |
| 30 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 31 | /* run a HTTP GET on specified URL expecting json in RSRES format as response */ |
| 32 | function f_rsres_get(charstring url, template integer exp_sts := 200) |
| 33 | runs 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 */ |
| 40 | function f_rsres_post_slotmap(JsSlotmap slotmap, template integer exp_sts := 201) |
| 41 | runs 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 */ |
| 50 | function f_rsres_post_reset(template integer exp_sts := 200) |
| 51 | runs 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 */ |
| 60 | function f_rsres_delete_slotmap(BankSlot bs, template integer exp_sts := 200) |
| 61 | runs 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 | |
| 70 | function f_rsres_init() runs on http_CT { |
Philipp Maier | 260f708 | 2024-04-19 13:12:49 +0200 | [diff] [blame^] | 71 | 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 77 | f_rsres_post_reset(); |
| 78 | } |
| 79 | |
| 80 | type component test_CT extends rspro_client_CT, http_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 81 | timer g_T_guard := 60.0; |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 84 | private 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 | |
| 91 | private function f_init() runs on test_CT { |
| 92 | /* Start the guard timer */ |
| 93 | g_T_guard.start; |
| 94 | activate(as_Tguard()); |
| 95 | } |
| 96 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 97 | |
Vadim Yanitskiy | 7d30c57 | 2021-02-28 16:46:13 +0100 | [diff] [blame] | 98 | testcase TC_connect_and_nothing() runs on test_CT { |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 99 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 100 | timer T := 20.0; |
| 101 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 102 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 103 | 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 Yanitskiy | 61564be | 2020-05-18 20:44:14 +0700 | [diff] [blame] | 107 | [] 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 109 | setverdict(pass); |
| 110 | } |
| 111 | [] T.timeout { |
| 112 | setverdict(fail, "Timeout waiting for disconnect"); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | testcase TC_connect_client() runs on test_CT { |
| 118 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 119 | var JsRoot js; |
| 120 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 121 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 122 | 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 Welte | 7c083af | 2022-05-03 17:46:25 +0200 | [diff] [blame] | 141 | /* duplicate connection from Same Client/Slot ID */ |
| 142 | testcase 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 179 | testcase TC_connect_bank() runs on test_CT { |
| 180 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar")); |
| 181 | var JsRoot js; |
| 182 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 183 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 184 | 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 Welte | 7c083af | 2022-05-03 17:46:25 +0200 | [diff] [blame] | 204 | testcase 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 248 | function f_ensure_slotmaps(template JsSlotmaps maps) |
| 249 | runs 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) */ |
| 262 | function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot, |
| 263 | template SlotmapState state := ?) |
| 264 | runs 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) */ |
| 269 | function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot, |
| 270 | template SlotmapState state := ?) |
| 271 | runs on http_CT { |
| 272 | f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } ); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | /* test adding a single slotmap */ |
| 277 | testcase TC_slotmap_add() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 278 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 279 | 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 Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 288 | /* test adding a single slotmap with out-of-range values */ |
| 289 | testcase TC_slotmap_add_out_of_range() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 290 | f_init(); |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 291 | 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 314 | /* test adding a slotmap and then connecting a client + bankd */ |
| 315 | testcase TC_slotmap_add_conn_cl_b() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 316 | f_init(); |
| 317 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 318 | /* 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 */ |
| 360 | testcase TC_conn_cl_b_slotmap_add() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 361 | f_init(); |
| 362 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 363 | /* 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 */ |
| 405 | testcase TC_slotmap_del_new() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 406 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 407 | 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 Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 416 | /* simple delete of a non-existant slotmap */ |
| 417 | testcase TC_slotmap_del_nonexistant() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 418 | f_init(); |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 419 | 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 427 | /* simple delete of a 'UNACKNOWLEDGED' slotmap */ |
| 428 | testcase TC_slotmap_del_unack() runs on test_CT { |
| 429 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 430 | |
| 431 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 432 | 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 Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 462 | /* simple delete of a 'ACTIVE' slotmap from server + bankd */ |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 463 | testcase TC_slotmap_del_active() runs on test_CT { |
| 464 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 465 | |
| 466 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 467 | 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 Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 503 | /* simple delete of a 'ACTIVE' slotmap from client */ |
| 504 | testcase TC_slotmap_del_active_client() runs on test_CT { |
| 505 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 506 | |
| 507 | f_init(); |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 508 | 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 557 | /* Add a slotmap to a currently active bank */ |
| 558 | testcase TC_slotmap_add_active_bank() runs on test_CT { |
| 559 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 560 | |
| 561 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 562 | 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 587 | * - 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 589 | |
| 590 | * - connect from unknown client (name not known, no clientId provisioned? |
| 591 | * - add client name/ID mappings from REST API? |
| 592 | */ |
| 593 | |
| 594 | |
| 595 | control { |
| 596 | execute( TC_connect_and_nothing() ); |
| 597 | execute( TC_connect_client() ); |
Harald Welte | 7c083af | 2022-05-03 17:46:25 +0200 | [diff] [blame] | 598 | execute( TC_connect_client_duplicate() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 599 | execute( TC_connect_bank() ); |
Harald Welte | 7c083af | 2022-05-03 17:46:25 +0200 | [diff] [blame] | 600 | execute( TC_connect_bank_duplicate() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 601 | execute( TC_slotmap_add() ); |
| 602 | execute( TC_slotmap_add_conn_cl_b() ); |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 603 | execute( TC_slotmap_add_out_of_range() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 604 | execute( TC_conn_cl_b_slotmap_add() ); |
| 605 | execute( TC_slotmap_del_new() ); |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 606 | execute( TC_slotmap_del_nonexistant() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 607 | execute( TC_slotmap_del_unack() ); |
| 608 | execute( TC_slotmap_del_active() ); |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 609 | execute( TC_slotmap_del_active_client() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 610 | execute( TC_slotmap_add_active_bank() ); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | } |