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 { |
| 71 | f_http_init(mp_server_ip, mp_rsres_port); |
| 72 | f_rsres_post_reset(); |
| 73 | } |
| 74 | |
| 75 | type component test_CT extends rspro_client_CT, http_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 76 | timer g_T_guard := 60.0; |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 79 | private 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 | |
| 86 | private function f_init() runs on test_CT { |
| 87 | /* Start the guard timer */ |
| 88 | g_T_guard.start; |
| 89 | activate(as_Tguard()); |
| 90 | } |
| 91 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 92 | |
Vadim Yanitskiy | 7d30c57 | 2021-02-28 16:46:13 +0100 | [diff] [blame] | 93 | testcase TC_connect_and_nothing() runs on test_CT { |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 94 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 95 | timer T := 20.0; |
| 96 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 97 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 98 | 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 Yanitskiy | 61564be | 2020-05-18 20:44:14 +0700 | [diff] [blame] | 102 | [] 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 Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 104 | setverdict(pass); |
| 105 | } |
| 106 | [] T.timeout { |
| 107 | setverdict(fail, "Timeout waiting for disconnect"); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | testcase TC_connect_client() runs on test_CT { |
| 113 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 114 | var JsRoot js; |
| 115 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 116 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 117 | 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 | |
| 136 | testcase TC_connect_bank() runs on test_CT { |
| 137 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar")); |
| 138 | var JsRoot js; |
| 139 | |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 140 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 141 | f_rsres_init(); |
| 142 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 143 | rspro[0].rspro_bank_id := 1; |
| 144 | rspro[0].rspro_bank_nslots := 8; |
| 145 | |
| 146 | js := f_rsres_get("/api/backend/v1/banks"); |
| 147 | if (not match(js.banks, JsBanks:{})) { |
| 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/banks"); |
| 153 | if (not match(js.banks[0], tr_JsBank(CONNECTED_BANKD, rspro[0].rspro_id, rspro[0].rspro_bank_id, |
| 154 | rspro[0].rspro_bank_nslots))) { |
| 155 | setverdict(fail, "Non-matching JSON response"); |
| 156 | mtc.stop; |
| 157 | } |
| 158 | setverdict(pass); |
| 159 | } |
| 160 | |
| 161 | function f_ensure_slotmaps(template JsSlotmaps maps) |
| 162 | runs on http_CT { |
| 163 | var JsRoot js; |
| 164 | |
| 165 | /* check that it is actually added */ |
| 166 | js := f_rsres_get("/api/backend/v1/slotmaps"); |
| 167 | if (match(js.slotmaps, maps)) { |
| 168 | setverdict(pass); |
| 169 | } else { |
| 170 | setverdict(fail, "Unexpected slotmaps: ", js); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* verify that exactly only one slotmap exists (the specified one) */ |
| 175 | function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot, |
| 176 | template SlotmapState state := ?) |
| 177 | runs on http_CT { |
| 178 | f_ensure_slotmaps({ tr_JsSlotmap(bslot, cslot, state) } ); |
| 179 | } |
| 180 | |
| 181 | /* verify that exactly only one slotmap exists (possibly among others) */ |
| 182 | function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot, |
| 183 | template SlotmapState state := ?) |
| 184 | runs on http_CT { |
| 185 | f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } ); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /* test adding a single slotmap */ |
| 190 | testcase TC_slotmap_add() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 191 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 192 | f_rsres_init(); |
| 193 | |
| 194 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 195 | var HTTPResponse res := f_rsres_post_slotmap(sm); |
| 196 | |
| 197 | /* check that it is actually added */ |
| 198 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 199 | } |
| 200 | |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 201 | /* test adding a single slotmap with out-of-range values */ |
| 202 | testcase TC_slotmap_add_out_of_range() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 203 | f_init(); |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 204 | f_rsres_init(); |
| 205 | |
| 206 | var HTTPMessage http_resp; |
| 207 | var charstring body; |
| 208 | |
| 209 | body := "{ \"bank\": { \"bankId\": 10000, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }"; |
| 210 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 211 | body := body, exp := tr_HTTP_Resp(400)); |
| 212 | |
| 213 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2000 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }"; |
| 214 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 215 | body := body, exp := tr_HTTP_Resp(400)); |
| 216 | |
| 217 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3000, \"slotNr\": 4 } }"; |
| 218 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 219 | body := body, exp := tr_HTTP_Resp(400)); |
| 220 | |
| 221 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4000 } }"; |
| 222 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 223 | body := body, exp := tr_HTTP_Resp(400)); |
| 224 | } |
| 225 | |
| 226 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 227 | /* test adding a slotmap and then connecting a client + bankd */ |
| 228 | testcase TC_slotmap_add_conn_cl_b() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 229 | f_init(); |
| 230 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 231 | /* Simulate one client */ |
| 232 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 233 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 234 | rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 235 | |
| 236 | /* Simulate one bankd */ |
| 237 | var BankSlot bslot := valueof(ts_BankSlot(1,2)); |
| 238 | var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 239 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1); |
| 240 | rspro[1].rspro_bank_id := bslot.bankId; |
| 241 | rspro[1].rspro_bank_nslots := 8 |
| 242 | |
| 243 | f_rsres_init(); |
| 244 | var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot)); |
| 245 | var HTTPResponse res; |
| 246 | |
| 247 | /* 1) Create a new slotmap via HTTP */ |
| 248 | res := f_rsres_post_slotmap(sm); |
| 249 | |
| 250 | /* 2) verify that the slotmap exists and is NEW */ |
| 251 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 252 | |
| 253 | /* 3) connect a client for that slotmap */ |
| 254 | f_rspro_connect_client(0); |
| 255 | |
| 256 | /* 4) connect a bankd for that slotmap */ |
| 257 | f_rspro_connect_client(1); |
| 258 | |
| 259 | /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 260 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 261 | |
| 262 | /* 6) expect bankd to receive that mapping */ |
| 263 | as_rspro_create_mapping(1, sm.client, sm.bank); |
| 264 | |
| 265 | /* 7) verify that the slotmap exists and is ACTIVE */ |
| 266 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 267 | |
| 268 | /* 8) expect the client to be configured with bankd side settings */ |
| 269 | as_rspro_cfg_client_bank(0, bslot, ?); |
| 270 | } |
| 271 | |
| 272 | /* test connecting a client and later adding a slotmap for it */ |
| 273 | testcase TC_conn_cl_b_slotmap_add() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 274 | f_init(); |
| 275 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 276 | /* Simulate one client */ |
| 277 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 278 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 279 | rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 280 | |
| 281 | /* Simulate one bankd */ |
| 282 | var BankSlot bslot := valueof(ts_BankSlot(1,2)); |
| 283 | var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 284 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1); |
| 285 | rspro[1].rspro_bank_id := bslot.bankId; |
| 286 | rspro[1].rspro_bank_nslots := 8 |
| 287 | |
| 288 | f_rsres_init(); |
| 289 | var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot)); |
| 290 | var HTTPResponse res; |
| 291 | |
| 292 | /* 1) connect a client for that slotmap */ |
| 293 | f_rspro_connect_client(0); |
| 294 | |
| 295 | /* 2) Create a new slotmap via HTTP */ |
| 296 | res := f_rsres_post_slotmap(sm); |
| 297 | |
| 298 | /* 3) verify that the slotmap exists and is NEW */ |
| 299 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 300 | |
| 301 | /* 4) connect a bankd for that slotmap */ |
| 302 | f_rspro_connect_client(1); |
| 303 | |
| 304 | /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 305 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 306 | |
| 307 | /* 6) expect bankd to receive that mapping */ |
| 308 | as_rspro_create_mapping(1, sm.client, sm.bank); |
| 309 | |
| 310 | /* 7) verify that the slotmap exists and is ACTIVE */ |
| 311 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 312 | |
| 313 | /* 8) expect the client to be configured with bankd IP/port */ |
| 314 | as_rspro_cfg_client_bank(0, bslot, ?); |
| 315 | } |
| 316 | |
| 317 | /* simple delete of a 'NEW' slotmap */ |
| 318 | testcase TC_slotmap_del_new() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 319 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 320 | f_rsres_init(); |
| 321 | |
| 322 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 323 | var HTTPResponse res := f_rsres_post_slotmap(sm); |
| 324 | log(res); |
| 325 | res := f_rsres_delete_slotmap(sm.bank); |
| 326 | log(res); |
| 327 | } |
| 328 | |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 329 | /* simple delete of a non-existant slotmap */ |
| 330 | testcase TC_slotmap_del_nonexistant() runs on test_CT { |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 331 | f_init(); |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 332 | f_rsres_init(); |
| 333 | |
| 334 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(11,12), ts_ClientSlot(13,14))); |
| 335 | var HTTPResponse res := f_rsres_delete_slotmap(sm.bank, exp_sts:=404); |
| 336 | log(res); |
| 337 | } |
| 338 | |
| 339 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 340 | /* simple delete of a 'UNACKNOWLEDGED' slotmap */ |
| 341 | testcase TC_slotmap_del_unack() runs on test_CT { |
| 342 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 343 | |
| 344 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 345 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 346 | rspro[0].rspro_bank_id := 1; |
| 347 | rspro[0].rspro_bank_nslots := 8; |
| 348 | |
| 349 | f_rsres_init(); |
| 350 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 351 | var HTTPResponse res; |
| 352 | |
| 353 | /* Create a new slotmap via HTTP */ |
| 354 | res := f_rsres_post_slotmap(sm); |
| 355 | |
| 356 | /* verify that the slotmap exists and is NEW */ |
| 357 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 358 | |
| 359 | /* connect a bankd for that slotmap */ |
| 360 | f_rspro_connect_client(0); |
| 361 | |
| 362 | /* expect the slotmap to be pushed to bank but don't ACK it */ |
| 363 | f_rspro_exp(tr_RSPRO_CreateMappingReq(sm.client, sm.bank)); |
| 364 | |
| 365 | /* verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 366 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 367 | |
| 368 | /* delete the slotmap via REST */ |
| 369 | res := f_rsres_delete_slotmap(sm.bank); |
| 370 | |
| 371 | /* verify the slotmap is gone */ |
| 372 | f_ensure_slotmaps({}); |
| 373 | } |
| 374 | |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 375 | /* simple delete of a 'ACTIVE' slotmap from server + bankd */ |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 376 | testcase TC_slotmap_del_active() runs on test_CT { |
| 377 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 378 | |
| 379 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 380 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 381 | rspro[0].rspro_bank_id := 1; |
| 382 | rspro[0].rspro_bank_nslots := 8; |
| 383 | |
| 384 | f_rsres_init(); |
| 385 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 386 | var HTTPResponse res; |
| 387 | |
| 388 | /* Create a new slotmap via HTTP */ |
| 389 | res := f_rsres_post_slotmap(sm); |
| 390 | |
| 391 | /* verify that the slotmap exists and is NEW */ |
| 392 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 393 | |
| 394 | /* connect a bankd for that slotmap */ |
| 395 | f_rspro_connect_client(0); |
| 396 | |
| 397 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 398 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 399 | |
| 400 | /* verify that the slotmap exists and is ACTIVE */ |
| 401 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 402 | |
| 403 | f_sleep(1.0); |
| 404 | |
| 405 | /* delete the slotmap via REST */ |
| 406 | res := f_rsres_delete_slotmap(sm.bank); |
| 407 | |
| 408 | /* verify the slotmap is gone from REST interface immediately */ |
| 409 | f_ensure_slotmaps({}); |
| 410 | |
| 411 | /* verify the slotmap is removed from bankd */ |
| 412 | as_rspro_remove_mapping(0, sm.client, sm.bank); |
| 413 | } |
| 414 | |
| 415 | |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 416 | /* simple delete of a 'ACTIVE' slotmap from client */ |
| 417 | testcase TC_slotmap_del_active_client() runs on test_CT { |
| 418 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 419 | |
| 420 | f_init(); |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 421 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 422 | rspro[0].rspro_bank_id := 1; |
| 423 | rspro[0].rspro_bank_nslots := 8; |
| 424 | |
| 425 | rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 426 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1); |
| 427 | rspro[1].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 428 | |
| 429 | f_rsres_init(); |
| 430 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 431 | var HTTPResponse res; |
| 432 | |
| 433 | /* Create a new slotmap via HTTP */ |
| 434 | res := f_rsres_post_slotmap(sm); |
| 435 | |
| 436 | /* verify that the slotmap exists and is NEW */ |
| 437 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 438 | |
| 439 | /* connect a bankd for that slotmap */ |
| 440 | f_rspro_connect_client(0); |
| 441 | |
| 442 | /* connect a client for that slotmap */ |
| 443 | f_rspro_connect_client(1); |
| 444 | |
| 445 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 446 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 447 | |
| 448 | /* verify that the slotmap exists and is ACTIVE */ |
| 449 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 450 | |
| 451 | /* expect the client to be configured with bankd side settings */ |
| 452 | as_rspro_cfg_client_bank(1, sm.bank, ?/*FIXME*/); |
| 453 | |
| 454 | f_sleep(1.0); |
| 455 | |
| 456 | /* delete the slotmap via REST */ |
| 457 | res := f_rsres_delete_slotmap(sm.bank); |
| 458 | |
| 459 | /* verify the slotmap is gone from REST interface immediately */ |
| 460 | f_ensure_slotmaps({}); |
| 461 | |
| 462 | /* verify the slotmap is removed from bankd */ |
| 463 | as_rspro_remove_mapping(0, sm.client, sm.bank); |
| 464 | |
| 465 | /* verify the slotmap is removed from client by setting IP/port to '0' */ |
| 466 | as_rspro_cfg_client_bank(1, ?, tr_IpPort(ts_IPv4("0.0.0.0"), 0)); |
| 467 | } |
| 468 | |
| 469 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 470 | /* Add a slotmap to a currently active bank */ |
| 471 | testcase TC_slotmap_add_active_bank() runs on test_CT { |
| 472 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
Vadim Yanitskiy | 0df27dc | 2021-02-28 17:08:52 +0100 | [diff] [blame] | 473 | |
| 474 | f_init(); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 475 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 476 | rspro[0].rspro_bank_id := 1; |
| 477 | rspro[0].rspro_bank_nslots := 8; |
| 478 | |
| 479 | f_rsres_init(); |
| 480 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 481 | var HTTPResponse res; |
| 482 | |
| 483 | /* connect a bankd for that slotmap */ |
| 484 | f_rspro_connect_client(0); |
| 485 | |
| 486 | /* Create a new slotmap via HTTP */ |
| 487 | res := f_rsres_post_slotmap(sm); |
| 488 | |
| 489 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 490 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 491 | |
| 492 | /* verify that the slotmap exists and is ACTIVE */ |
| 493 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 494 | } |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | /* TODO |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 500 | * - connect client w/slotmap; delete slotmap via REST (see if it is deleted) |
| 501 | * - 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] | 502 | |
| 503 | * - connect from unknown client (name not known, no clientId provisioned? |
| 504 | * - add client name/ID mappings from REST API? |
| 505 | */ |
| 506 | |
| 507 | |
| 508 | control { |
| 509 | execute( TC_connect_and_nothing() ); |
| 510 | execute( TC_connect_client() ); |
| 511 | execute( TC_connect_bank() ); |
| 512 | execute( TC_slotmap_add() ); |
| 513 | execute( TC_slotmap_add_conn_cl_b() ); |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 514 | execute( TC_slotmap_add_out_of_range() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 515 | execute( TC_conn_cl_b_slotmap_add() ); |
| 516 | execute( TC_slotmap_del_new() ); |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 517 | execute( TC_slotmap_del_nonexistant() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 518 | execute( TC_slotmap_del_unack() ); |
| 519 | execute( TC_slotmap_del_active() ); |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 520 | execute( TC_slotmap_del_active_client() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 521 | execute( TC_slotmap_add_active_bank() ); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | } |