blob: c5f2dddcf1b1828a94b433960d4ab3d5041dd52e [file] [log] [blame]
danielhanrahanf66694a2024-06-10 21:32:12 +01001/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
19 */
20
21import http from 'k6/http';
danielhanrahanf2e1e252024-08-25 21:35:19 +010022import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
23import { TOTAL_CM_HANDLES, CONTENT_TYPE_JSON_PARAM, NCMP_BASE_URL, TOPIC_DATA_OPERATIONS_BATCH_READ } from './utils.js';
danielhanrahanf66694a2024-06-10 21:32:12 +010024
danielhanrahanf2e1e252024-08-25 21:35:19 +010025export function passthroughRead(useAlternateId) {
26 const cmHandleReference = getRandomCmHandleReference(useAlternateId);
danielhanrahanf66694a2024-06-10 21:32:12 +010027 const resourceIdentifier = 'my-resource-identifier';
28 const includeDescendants = true;
29 const datastoreName = 'ncmp-datastore:passthrough-operational';
danielhanrahanf2e1e252024-08-25 21:35:19 +010030 const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}`
danielhanrahanf66694a2024-06-10 21:32:12 +010031 const response = http.get(url);
danielhanrahanf66694a2024-06-10 21:32:12 +010032 return response;
33}
halil.cakalfcc81ee2024-07-11 14:54:57 +010034
danielhanrahanf2e1e252024-08-25 21:35:19 +010035export function passthroughWrite(useAlternateId) {
36 const cmHandleReference = getRandomCmHandleReference(useAlternateId);
halil.cakalfcc81ee2024-07-11 14:54:57 +010037 const resourceIdentifier = 'my-resource-identifier';
38 const datastoreName = 'ncmp-datastore:passthrough-running';
danielhanrahanf2e1e252024-08-25 21:35:19 +010039 const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}`
halil.cakalfcc81ee2024-07-11 14:54:57 +010040 const body = `{"neType": "BaseStation"}`
41 const response = http.post(url, JSON.stringify(body), CONTENT_TYPE_JSON_PARAM);
42 return response;
43}
halil.cakal65b870b2024-07-25 11:12:29 +010044
45export function batchRead(cmHandleIds) {
46 const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}`
47 const payload = {
48 "operations": [
49 {
50 "resourceIdentifier": "parent/child",
51 "targetIds": cmHandleIds,
52 "datastore": "ncmp-datastore:passthrough-operational",
53 "options": "(fields=schemas/schema)",
54 "operationId": "12",
55 "operation": "read"
56 }
57 ]
58 };
59 const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM);
60 return response;
danielhanrahanf2e1e252024-08-25 21:35:19 +010061}
62
63function getRandomCmHandleReference(useAlternateId) {
64 const prefix = useAlternateId ? 'alt' : 'ch';
65 return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`;
66}