1 /*************************************************************************
3 * Copyright 2020 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 ***************************************************************************/
25 #include "utils/log_utils.h"
26 #include "utils/nc_client.h"
28 #include "core/framework.h"
29 #include "core/container.h"
30 #include "core/session.h"
31 #include "core/context.h"
32 #include "core/test.h"
33 #include "core/nc_config.h"
35 #include "core/app/supervisor.h"
36 #include "core/app/manager.h"
37 #include "core/app/network_function.h"
38 #include "core/app/blank.h"
39 #include "core/datastore/schema.h"
40 #include "core/datastore/generate.h"
41 #include "core/datastore/populate.h"
43 int main(int argc, char **argv) {
44 int return_code = EXIT_SUCCESS;
46 if(framework_init(argc, argv) != NTS_ERR_OK) {
47 log_error(LOG_COLOR_BOLD_RED"framework_init() error\n");
53 switch(framework_arguments.nts_mode) {
54 case NTS_MODE_MANAGER:
55 case NTS_MODE_NETWORK_FUNCTION:
56 case NTS_MODE_GENERATE_DATA:
58 case NTS_MODE_DEFAULT:
59 sr_log_stderr(SR_LL_INF); //checkAL WRN
61 if(session_init() != NTS_ERR_OK) {
62 log_error("session_init() failed\n");
63 return_code = EXIT_FAILURE;
64 goto main_clean_session;
67 if(context_init(session_context) != 0) {
68 log_error("context_init() failed\n");
69 return_code = EXIT_FAILURE;
70 goto main_clean_context;
80 //netconf server configure
81 switch(framework_arguments.nts_mode) {
82 case NTS_MODE_MANAGER:
83 case NTS_MODE_NETWORK_FUNCTION:
84 //configure local netconf server
85 if(netconf_configure() != NTS_ERR_OK) {
86 log_error("netconf_configure() failed\n")
87 return_code = EXIT_FAILURE;
96 switch(framework_arguments.nts_mode) {
97 case NTS_MODE_CONTAINER_INIT:
98 if(!container_self_init()) {
99 log_error("container_self_init() failed\n");
100 return_code = EXIT_FAILURE;
103 goto main_clean_framework;
106 case NTS_MODE_SUPERVISOR:
107 //run in supervisor mode
108 if(supervisor_run(argc, argv) != NTS_ERR_OK) {
109 log_error("supervisor_run() failed\n");
110 return_code = EXIT_FAILURE;
113 goto main_clean_framework;
116 case NTS_MODE_MANAGER:
117 if(manager_run() != NTS_ERR_OK) {
118 log_error("manager_run() failed\n");
119 return_code = EXIT_FAILURE;
125 case NTS_MODE_NETWORK_FUNCTION:
126 if(network_function_run() != NTS_ERR_OK) {
127 log_error("network_function_run() failed\n");
128 return_code = EXIT_FAILURE;
135 if(blank_run() != NTS_ERR_OK) {
136 log_error("blank_run() failed\n");
137 return_code = EXIT_FAILURE;
140 goto main_clean_framework;
143 case NTS_MODE_GENERATE_DATA:
144 if(datastore_generate_data(DATASTORE_RUNNING_PATH, DATASTORE_OPERATIONAL_PATH) != NTS_ERR_OK) {
145 log_error("datastore_generate_data() failed\n");
146 return_code = EXIT_FAILURE;
153 if(exhaustive_test_run() != NTS_ERR_OK) {
154 log_error("exhaustive_test_run() failed\n");
155 return_code = EXIT_FAILURE;
161 case NTS_MODE_DEFAULT:
162 if(framework_arguments.print_root_paths) {
163 if(datastore_schema_print_root_paths() != NTS_ERR_OK) {
164 log_error("datastore_schema_print_root_paths() failed\n");
165 return_code = EXIT_FAILURE;
170 if(framework_arguments.print_structure_xpath != 0) {
171 //print the associated structure
172 if(datastore_schema_print_xpath(framework_arguments.print_structure_xpath) != NTS_ERR_OK) {
173 log_error("datastore_schema_print_xpath() failed\n");
174 return_code = EXIT_FAILURE;
188 log_add_verbose(1, LOG_COLOR_BOLD_RED"stopping now...\n"LOG_COLOR_RESET);
194 main_clean_framework: