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 | |
| 23 | import from IPA_Emulation all; |
| 24 | |
| 25 | import from HTTPmsg_Types all; |
| 26 | import from HTTPmsg_PortType all; |
| 27 | import from JSON_Types all; |
| 28 | |
| 29 | type component http_CT { |
| 30 | port HTTPmsg_PT HTTP; |
| 31 | var charstring g_http_host; |
| 32 | var integer g_http_port; |
| 33 | }; |
| 34 | |
| 35 | function f_http_init(charstring host, integer http_port) runs on http_CT { |
| 36 | map(self:HTTP, system:HTTP); |
| 37 | g_http_host := host; |
| 38 | g_http_port := http_port; |
| 39 | } |
| 40 | |
| 41 | template (value) Connect ts_HTTP_Connect(template (value) charstring hostname, |
| 42 | template (value) integer http_port := 80, |
| 43 | template (value) boolean use_ssl := false) := { |
| 44 | hostname := hostname, |
| 45 | portnumber := http_port, |
| 46 | use_ssl := use_ssl |
| 47 | } |
| 48 | template (value) Close ts_HTTP_Close := { client_id := omit }; |
| 49 | |
| 50 | template (value) HeaderLines ts_HTTP_Header(charstring body) := { |
| 51 | { header_name := "Content-Type", header_value := "application/json" }, |
| 52 | { header_name := "Content-Length", header_value := int2str(lengthof(body)) } |
| 53 | } |
| 54 | |
| 55 | template (value) HTTPMessage ts_HTTP_Req(charstring url, |
| 56 | charstring method := "GET", |
| 57 | charstring body := "", |
| 58 | integer v_maj := 1, integer v_min := 1) := { |
| 59 | request := { |
| 60 | client_id := omit, |
| 61 | method := method, |
| 62 | uri := url, |
| 63 | version_major := v_maj, |
| 64 | version_minor := v_min, |
| 65 | header := ts_HTTP_Header(body), |
| 66 | body := body |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := { |
| 71 | response := { |
| 72 | client_id := ?, |
| 73 | version_major := ?, |
| 74 | version_minor := ?, |
| 75 | statuscode := sts, |
| 76 | statustext := ?, |
| 77 | header := ?, |
| 78 | body := ? |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299)); |
| 83 | |
| 84 | /* run a HTTP request and return the response */ |
| 85 | function f_http_transact(charstring url, charstring method := "GET", |
| 86 | charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx) |
| 87 | runs on http_CT return HTTPMessage { |
| 88 | var HTTPMessage resp; |
| 89 | timer T := 2.0; |
| 90 | |
| 91 | HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port)); |
| 92 | //HTTP.receive(Connect_result:?); |
| 93 | HTTP.send(ts_HTTP_Req(url, method, body)); |
| 94 | T.start; |
| 95 | alt { |
| 96 | [] HTTP.receive(exp) -> value resp { |
| 97 | setverdict(pass); |
| 98 | } |
| 99 | [] HTTP.receive(tr_HTTP_Resp) -> value resp { |
| 100 | setverdict(fail, "Unexpected HTTP response ", resp); |
| 101 | } |
| 102 | [] T.timeout { |
| 103 | setverdict(fail, "Timeout waiting for HTTP response"); |
| 104 | self.stop; |
| 105 | } |
| 106 | } |
| 107 | HTTP.send(ts_HTTP_Close); |
| 108 | return resp; |
| 109 | } |
| 110 | |
| 111 | /* run a HTTP GET on specified URL expecting json in RSRES format as response */ |
| 112 | function f_rsres_get(charstring url, template integer exp_sts := 200) |
| 113 | runs on http_CT return JsRoot { |
| 114 | var HTTPMessage http_resp; |
| 115 | http_resp := f_http_transact(url, exp := tr_HTTP_Resp(exp_sts)); |
| 116 | return f_dec_JsRoot(char2oct(http_resp.response.body)); |
| 117 | } |
| 118 | |
| 119 | /* run a HTTP PUT to add a new slotmap to the remsim-server */ |
| 120 | function f_rsres_post_slotmap(JsSlotmap slotmap, template integer exp_sts := 201) |
| 121 | runs on http_CT return HTTPResponse { |
| 122 | var charstring body := oct2char(f_enc_JsSlotmap(slotmap)); |
| 123 | var HTTPMessage http_resp; |
| 124 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 125 | body := body, exp := tr_HTTP_Resp(exp_sts)) |
| 126 | return http_resp.response; |
| 127 | } |
| 128 | |
| 129 | /* run a HTTP PUT to add a new slotmap to the remsim-server */ |
| 130 | function f_rsres_post_reset(template integer exp_sts := 200) |
| 131 | runs on http_CT return HTTPResponse { |
| 132 | var HTTPMessage http_resp; |
| 133 | http_resp := f_http_transact(url := "/api/backend/v1/global-reset", method := "POST", |
| 134 | body := "", exp := tr_HTTP_Resp(exp_sts)) |
| 135 | return http_resp.response; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* run a HTTP DELETE to remove a slotmap from te remsim-server */ |
| 140 | function f_rsres_delete_slotmap(BankSlot bs, template integer exp_sts := 200) |
| 141 | runs on http_CT return HTTPResponse { |
| 142 | var HTTPMessage http_resp; |
| 143 | var integer slotmap_id := bs.bankId * 65536 + bs.slotNr; |
| 144 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps/" & int2str(slotmap_id), |
| 145 | method := "DELETE", exp := tr_HTTP_Resp(exp_sts)); |
| 146 | return http_resp.response; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | function f_rsres_init() runs on http_CT { |
| 151 | f_http_init(mp_server_ip, mp_rsres_port); |
| 152 | f_rsres_post_reset(); |
| 153 | } |
| 154 | |
| 155 | type component test_CT extends rspro_client_CT, http_CT { |
| 156 | }; |
| 157 | |
| 158 | |
| 159 | testcase TC_connect_and_nothing() runs on rspro_client_CT { |
| 160 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 161 | timer T := 20.0; |
| 162 | |
| 163 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 164 | T.start; |
| 165 | /* expect that we're disconnected if we never send a ConnectClientReq */ |
| 166 | alt { |
Vadim Yanitskiy | 61564be | 2020-05-18 20:44:14 +0700 | [diff] [blame] | 167 | [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { repeat; } |
| 168 | [] RSPRO[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) { |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 169 | setverdict(pass); |
| 170 | } |
| 171 | [] T.timeout { |
| 172 | setverdict(fail, "Timeout waiting for disconnect"); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | testcase TC_connect_client() runs on test_CT { |
| 178 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, "foobar")); |
| 179 | var JsRoot js; |
| 180 | |
| 181 | f_rsres_init(); |
| 182 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 183 | rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 184 | |
| 185 | js := f_rsres_get("/api/backend/v1/clients"); |
| 186 | if (not match(js.clients, JsClients:{})) { |
| 187 | setverdict(fail, "Initial state not empty"); |
| 188 | mtc.stop; |
| 189 | } |
| 190 | f_rspro_connect_client(0); |
| 191 | js := f_rsres_get("/api/backend/v1/clients"); |
| 192 | if (not match(js.clients[0], tr_JsClient(CONNECTED_CLIENT, rspro[0].rspro_id))) { |
| 193 | setverdict(fail, "Non-matching JSON response"); |
| 194 | mtc.stop; |
| 195 | } |
| 196 | //as_rspro_cfg_client_id(0, cslot); |
| 197 | setverdict(pass); |
| 198 | } |
| 199 | |
| 200 | testcase TC_connect_bank() runs on test_CT { |
| 201 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, "foobar")); |
| 202 | var JsRoot js; |
| 203 | |
| 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 | setverdict(pass); |
| 222 | } |
| 223 | |
| 224 | function f_ensure_slotmaps(template JsSlotmaps maps) |
| 225 | runs on http_CT { |
| 226 | var JsRoot js; |
| 227 | |
| 228 | /* check that it is actually added */ |
| 229 | js := f_rsres_get("/api/backend/v1/slotmaps"); |
| 230 | if (match(js.slotmaps, maps)) { |
| 231 | setverdict(pass); |
| 232 | } else { |
| 233 | setverdict(fail, "Unexpected slotmaps: ", js); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /* verify that exactly only one slotmap exists (the specified one) */ |
| 238 | function f_ensure_slotmap_exists_only(template ClientSlot cslot, template BankSlot bslot, |
| 239 | template SlotmapState state := ?) |
| 240 | runs on http_CT { |
| 241 | f_ensure_slotmaps({ tr_JsSlotmap(bslot, cslot, state) } ); |
| 242 | } |
| 243 | |
| 244 | /* verify that exactly only one slotmap exists (possibly among others) */ |
| 245 | function f_ensure_slotmap_exists(template ClientSlot cslot, template BankSlot bslot, |
| 246 | template SlotmapState state := ?) |
| 247 | runs on http_CT { |
| 248 | f_ensure_slotmaps({ *, tr_JsSlotmap(bslot, cslot, state), * } ); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /* test adding a single slotmap */ |
| 253 | testcase TC_slotmap_add() runs on test_CT { |
| 254 | f_rsres_init(); |
| 255 | |
| 256 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 257 | var HTTPResponse res := f_rsres_post_slotmap(sm); |
| 258 | |
| 259 | /* check that it is actually added */ |
| 260 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 261 | } |
| 262 | |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 263 | /* test adding a single slotmap with out-of-range values */ |
| 264 | testcase TC_slotmap_add_out_of_range() runs on test_CT { |
| 265 | f_rsres_init(); |
| 266 | |
| 267 | var HTTPMessage http_resp; |
| 268 | var charstring body; |
| 269 | |
| 270 | body := "{ \"bank\": { \"bankId\": 10000, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }"; |
| 271 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 272 | body := body, exp := tr_HTTP_Resp(400)); |
| 273 | |
| 274 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2000 }, \"client\": { \"clientId\": 3, \"slotNr\": 4 } }"; |
| 275 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 276 | body := body, exp := tr_HTTP_Resp(400)); |
| 277 | |
| 278 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3000, \"slotNr\": 4 } }"; |
| 279 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 280 | body := body, exp := tr_HTTP_Resp(400)); |
| 281 | |
| 282 | body := "{ \"bank\": { \"bankId\": 100, \"slotNr\": 2 }, \"client\": { \"clientId\": 3, \"slotNr\": 4000 } }"; |
| 283 | http_resp := f_http_transact(url := "/api/backend/v1/slotmaps", method := "POST", |
| 284 | body := body, exp := tr_HTTP_Resp(400)); |
| 285 | } |
| 286 | |
| 287 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 288 | /* test adding a slotmap and then connecting a client + bankd */ |
| 289 | testcase TC_slotmap_add_conn_cl_b() runs on test_CT { |
| 290 | /* Simulate one client */ |
| 291 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 292 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 293 | rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 294 | |
| 295 | /* Simulate one bankd */ |
| 296 | var BankSlot bslot := valueof(ts_BankSlot(1,2)); |
| 297 | var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 298 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1); |
| 299 | rspro[1].rspro_bank_id := bslot.bankId; |
| 300 | rspro[1].rspro_bank_nslots := 8 |
| 301 | |
| 302 | f_rsres_init(); |
| 303 | var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot)); |
| 304 | var HTTPResponse res; |
| 305 | |
| 306 | /* 1) Create a new slotmap via HTTP */ |
| 307 | res := f_rsres_post_slotmap(sm); |
| 308 | |
| 309 | /* 2) verify that the slotmap exists and is NEW */ |
| 310 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 311 | |
| 312 | /* 3) connect a client for that slotmap */ |
| 313 | f_rspro_connect_client(0); |
| 314 | |
| 315 | /* 4) connect a bankd for that slotmap */ |
| 316 | f_rspro_connect_client(1); |
| 317 | |
| 318 | /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 319 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 320 | |
| 321 | /* 6) expect bankd to receive that mapping */ |
| 322 | as_rspro_create_mapping(1, sm.client, sm.bank); |
| 323 | |
| 324 | /* 7) verify that the slotmap exists and is ACTIVE */ |
| 325 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 326 | |
| 327 | /* 8) expect the client to be configured with bankd side settings */ |
| 328 | as_rspro_cfg_client_bank(0, bslot, ?); |
| 329 | } |
| 330 | |
| 331 | /* test connecting a client and later adding a slotmap for it */ |
| 332 | testcase TC_conn_cl_b_slotmap_add() runs on test_CT { |
| 333 | /* Simulate one client */ |
| 334 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 335 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 336 | rspro[0].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 337 | |
| 338 | /* Simulate one bankd */ |
| 339 | var BankSlot bslot := valueof(ts_BankSlot(1,2)); |
| 340 | var ComponentIdentity rspro_bank_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 341 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_bank_id, 1); |
| 342 | rspro[1].rspro_bank_id := bslot.bankId; |
| 343 | rspro[1].rspro_bank_nslots := 8 |
| 344 | |
| 345 | f_rsres_init(); |
| 346 | var JsSlotmap sm := valueof(ts_JsSlotmap(bslot, rspro[0].rspro_client_slot)); |
| 347 | var HTTPResponse res; |
| 348 | |
| 349 | /* 1) connect a client for that slotmap */ |
| 350 | f_rspro_connect_client(0); |
| 351 | |
| 352 | /* 2) Create a new slotmap via HTTP */ |
| 353 | res := f_rsres_post_slotmap(sm); |
| 354 | |
| 355 | /* 3) verify that the slotmap exists and is NEW */ |
| 356 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 357 | |
| 358 | /* 4) connect a bankd for that slotmap */ |
| 359 | f_rspro_connect_client(1); |
| 360 | |
| 361 | /* 5) verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 362 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 363 | |
| 364 | /* 6) expect bankd to receive that mapping */ |
| 365 | as_rspro_create_mapping(1, sm.client, sm.bank); |
| 366 | |
| 367 | /* 7) verify that the slotmap exists and is ACTIVE */ |
| 368 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 369 | |
| 370 | /* 8) expect the client to be configured with bankd IP/port */ |
| 371 | as_rspro_cfg_client_bank(0, bslot, ?); |
| 372 | } |
| 373 | |
| 374 | /* simple delete of a 'NEW' slotmap */ |
| 375 | testcase TC_slotmap_del_new() runs on test_CT { |
| 376 | f_rsres_init(); |
| 377 | |
| 378 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 379 | var HTTPResponse res := f_rsres_post_slotmap(sm); |
| 380 | log(res); |
| 381 | res := f_rsres_delete_slotmap(sm.bank); |
| 382 | log(res); |
| 383 | } |
| 384 | |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 385 | /* simple delete of a non-existant slotmap */ |
| 386 | testcase TC_slotmap_del_nonexistant() runs on test_CT { |
| 387 | f_rsres_init(); |
| 388 | |
| 389 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(11,12), ts_ClientSlot(13,14))); |
| 390 | var HTTPResponse res := f_rsres_delete_slotmap(sm.bank, exp_sts:=404); |
| 391 | log(res); |
| 392 | } |
| 393 | |
| 394 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 395 | /* simple delete of a 'UNACKNOWLEDGED' slotmap */ |
| 396 | testcase TC_slotmap_del_unack() runs on test_CT { |
| 397 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 398 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 399 | rspro[0].rspro_bank_id := 1; |
| 400 | rspro[0].rspro_bank_nslots := 8; |
| 401 | |
| 402 | f_rsres_init(); |
| 403 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 404 | var HTTPResponse res; |
| 405 | |
| 406 | /* Create a new slotmap via HTTP */ |
| 407 | res := f_rsres_post_slotmap(sm); |
| 408 | |
| 409 | /* verify that the slotmap exists and is NEW */ |
| 410 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 411 | |
| 412 | /* connect a bankd for that slotmap */ |
| 413 | f_rspro_connect_client(0); |
| 414 | |
| 415 | /* expect the slotmap to be pushed to bank but don't ACK it */ |
| 416 | f_rspro_exp(tr_RSPRO_CreateMappingReq(sm.client, sm.bank)); |
| 417 | |
| 418 | /* verify that the slotmap exists and is UNACKNOWLEDGED */ |
| 419 | f_ensure_slotmap_exists_only(sm.client, sm.bank, UNACKNOWLEDGED); |
| 420 | |
| 421 | /* delete the slotmap via REST */ |
| 422 | res := f_rsres_delete_slotmap(sm.bank); |
| 423 | |
| 424 | /* verify the slotmap is gone */ |
| 425 | f_ensure_slotmaps({}); |
| 426 | } |
| 427 | |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 428 | /* simple delete of a 'ACTIVE' slotmap from server + bankd */ |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 429 | testcase TC_slotmap_del_active() runs on test_CT { |
| 430 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 431 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 432 | rspro[0].rspro_bank_id := 1; |
| 433 | rspro[0].rspro_bank_nslots := 8; |
| 434 | |
| 435 | f_rsres_init(); |
| 436 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 437 | var HTTPResponse res; |
| 438 | |
| 439 | /* Create a new slotmap via HTTP */ |
| 440 | res := f_rsres_post_slotmap(sm); |
| 441 | |
| 442 | /* verify that the slotmap exists and is NEW */ |
| 443 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 444 | |
| 445 | /* connect a bankd for that slotmap */ |
| 446 | f_rspro_connect_client(0); |
| 447 | |
| 448 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 449 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 450 | |
| 451 | /* verify that the slotmap exists and is ACTIVE */ |
| 452 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 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 | |
| 466 | |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 467 | /* simple delete of a 'ACTIVE' slotmap from client */ |
| 468 | testcase TC_slotmap_del_active_client() runs on test_CT { |
| 469 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 470 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 471 | rspro[0].rspro_bank_id := 1; |
| 472 | rspro[0].rspro_bank_nslots := 8; |
| 473 | |
| 474 | rspro_id := valueof(ts_CompId(remsimClient, testcasename())); |
| 475 | f_rspro_init(rspro[1], mp_server_ip, mp_server_port, rspro_id, 1); |
| 476 | rspro[1].rspro_client_slot := valueof(ts_ClientSlot(3,4)); |
| 477 | |
| 478 | f_rsres_init(); |
| 479 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 480 | var HTTPResponse res; |
| 481 | |
| 482 | /* Create a new slotmap via HTTP */ |
| 483 | res := f_rsres_post_slotmap(sm); |
| 484 | |
| 485 | /* verify that the slotmap exists and is NEW */ |
| 486 | f_ensure_slotmap_exists_only(sm.client, sm.bank, NEW); |
| 487 | |
| 488 | /* connect a bankd for that slotmap */ |
| 489 | f_rspro_connect_client(0); |
| 490 | |
| 491 | /* connect a client for that slotmap */ |
| 492 | f_rspro_connect_client(1); |
| 493 | |
| 494 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 495 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 496 | |
| 497 | /* verify that the slotmap exists and is ACTIVE */ |
| 498 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 499 | |
| 500 | /* expect the client to be configured with bankd side settings */ |
| 501 | as_rspro_cfg_client_bank(1, sm.bank, ?/*FIXME*/); |
| 502 | |
| 503 | f_sleep(1.0); |
| 504 | |
| 505 | /* delete the slotmap via REST */ |
| 506 | res := f_rsres_delete_slotmap(sm.bank); |
| 507 | |
| 508 | /* verify the slotmap is gone from REST interface immediately */ |
| 509 | f_ensure_slotmaps({}); |
| 510 | |
| 511 | /* verify the slotmap is removed from bankd */ |
| 512 | as_rspro_remove_mapping(0, sm.client, sm.bank); |
| 513 | |
| 514 | /* verify the slotmap is removed from client by setting IP/port to '0' */ |
| 515 | as_rspro_cfg_client_bank(1, ?, tr_IpPort(ts_IPv4("0.0.0.0"), 0)); |
| 516 | } |
| 517 | |
| 518 | |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 519 | /* Add a slotmap to a currently active bank */ |
| 520 | testcase TC_slotmap_add_active_bank() runs on test_CT { |
| 521 | var ComponentIdentity rspro_id := valueof(ts_CompId(remsimBankd, testcasename())); |
| 522 | f_rspro_init(rspro[0], mp_server_ip, mp_server_port, rspro_id, 0); |
| 523 | rspro[0].rspro_bank_id := 1; |
| 524 | rspro[0].rspro_bank_nslots := 8; |
| 525 | |
| 526 | f_rsres_init(); |
| 527 | var JsSlotmap sm := valueof(ts_JsSlotmap(ts_BankSlot(1,2), ts_ClientSlot(3,4))); |
| 528 | var HTTPResponse res; |
| 529 | |
| 530 | /* connect a bankd for that slotmap */ |
| 531 | f_rspro_connect_client(0); |
| 532 | |
| 533 | /* Create a new slotmap via HTTP */ |
| 534 | res := f_rsres_post_slotmap(sm); |
| 535 | |
| 536 | /* expect the slotmap to be pushed to bank and ACK it */ |
| 537 | as_rspro_create_mapping(0, sm.client, sm.bank); |
| 538 | |
| 539 | /* verify that the slotmap exists and is ACTIVE */ |
| 540 | f_ensure_slotmap_exists_only(sm.client, sm.bank, ACTIVE); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | /* TODO |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 547 | * - connect client w/slotmap; delete slotmap via REST (see if it is deleted) |
| 548 | * - 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] | 549 | |
| 550 | * - connect from unknown client (name not known, no clientId provisioned? |
| 551 | * - add client name/ID mappings from REST API? |
| 552 | */ |
| 553 | |
| 554 | |
| 555 | control { |
| 556 | execute( TC_connect_and_nothing() ); |
| 557 | execute( TC_connect_client() ); |
| 558 | execute( TC_connect_bank() ); |
| 559 | execute( TC_slotmap_add() ); |
| 560 | execute( TC_slotmap_add_conn_cl_b() ); |
Harald Welte | b12a0ff | 2020-02-20 18:48:22 +0100 | [diff] [blame] | 561 | execute( TC_slotmap_add_out_of_range() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 562 | execute( TC_conn_cl_b_slotmap_add() ); |
| 563 | execute( TC_slotmap_del_new() ); |
Harald Welte | 3993c81 | 2020-02-20 10:12:28 +0100 | [diff] [blame] | 564 | execute( TC_slotmap_del_nonexistant() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 565 | execute( TC_slotmap_del_unack() ); |
| 566 | execute( TC_slotmap_del_active() ); |
Harald Welte | 77cde21 | 2020-02-16 15:35:07 +0100 | [diff] [blame] | 567 | execute( TC_slotmap_del_active_client() ); |
Harald Welte | faa4292 | 2019-03-04 18:31:11 +0100 | [diff] [blame] | 568 | execute( TC_slotmap_add_active_bank() ); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | } |