1 /*************************************************************************
3 * Copyright 2021 highstreet technologies GmbH and others
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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 ***************************************************************************/
19 #include "populate_internal.h"
21 #include "core/session.h"
22 #include "core/framework.h"
23 #include "utils/sys_utils.h"
24 #include "utils/log_utils.h"
25 #include "utils/type_utils.h"
26 #include "utils/rand_utils.h"
31 struct lyd_node *datastore_load_external(const char *filename, bool operational) {
32 struct lyd_node *data_tree = 0;
34 if(file_exists(filename)) {
35 LYD_FORMAT format = LYD_JSON;
36 if(strstr(filename, ".xml") != 0) {
40 int flags = LYD_OPT_TRUSTED | LYD_OPT_NOSIBLINGS;
42 flags |= LYD_OPT_DATA;
45 flags |= LYD_OPT_CONFIG;
48 data_tree = lyd_parse_path(session_context, filename, format, flags);
50 log_error("lyd_parse_path failed\n");
58 char populate_info_get_mandatory(const struct lys_node *schema) {
62 if((schema->flags & LYS_MAND_TRUE) != 0) {
65 if((schema->parent) && (schema->parent->nodetype == LYS_CASE)) {
66 if((schema->parent->flags & LYS_MAND_TRUE) != 0) {
74 const char* populate_leafref_test_val(int index) {
85 return "Fd:4D:63:A5:21:C5";
109 return "best-effort";
113 return "yes-fault:o-ran-sc-alarm-type";
121 log_error("index out of bounds\n");
127 int populate_instance_add_module(populate_instance_t *instance, const struct lys_module *module) {
131 for(int i = 0; i < instance->mod_count; i++) {
132 if(instance->modules[i] == module) {
137 instance->modules = (const struct lys_module **)realloc(instance->modules, sizeof(const struct lys_module *) * (instance->mod_count + 1));
138 if(!instance->modules) {
139 log_error("bad realloc\n");
140 return NTS_ERR_FAILED;
142 instance->modules[instance->mod_count] = module;
143 instance->mod_count++;
148 int populate_instance_get_count(const char *path) {
151 for(int i = 0; i < framework_config.datastore_generate.custom_list_instances_count; i++) {
152 if(strcmp(path, framework_config.datastore_generate.custom_list_instances[i].path) == 0) {
153 return framework_config.datastore_generate.custom_list_instances[i].count;
156 return framework_config.datastore_generate.default_list_instances;
159 char *populate_get_restrict_schema(const char *path) {
163 for(int i = 0; i < framework_config.datastore_generate.restrict_schema_count; i++) {
164 if(strcmp(path, framework_config.datastore_generate.restrict_schema[i].path) == 0) {
165 ret = strdup(framework_config.datastore_generate.restrict_schema[i].values[framework_config.datastore_generate.restrict_schema[i].index]);
166 framework_config.datastore_generate.restrict_schema[i].index++;
167 if(framework_config.datastore_generate.restrict_schema[i].index >= framework_config.datastore_generate.restrict_schema[i].values_count) {
168 framework_config.datastore_generate.restrict_schema[i].index = 0;