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/populate.h"
42 int main(int argc, char **argv) {
43 int return_code = EXIT_SUCCESS;
45 if(framework_init(argc, argv) != NTS_ERR_OK) {
46 log_error(LOG_COLOR_BOLD_RED"framework_init() error\n");
52 switch(framework_arguments.nts_mode) {
53 case NTS_MODE_MANAGER:
54 case NTS_MODE_NETWORK_FUNCTION:
56 case NTS_MODE_DEFAULT:
57 sr_log_stderr(SR_LL_INF); //checkAL WRN
59 if(session_init() != NTS_ERR_OK) {
60 log_error("session_init() failed\n");
61 return_code = EXIT_FAILURE;
62 goto main_clean_session;
65 if(context_init(session_context) != 0) {
66 log_error("context_init() failed\n");
67 return_code = EXIT_FAILURE;
68 goto main_clean_context;
78 //netconf server configure
79 switch(framework_arguments.nts_mode) {
80 case NTS_MODE_MANAGER:
81 case NTS_MODE_NETWORK_FUNCTION:
82 case NTS_MODE_TEST: //checkAL remove this
83 //configure local netconf server
84 if(netconf_configure() != NTS_ERR_OK) {
85 log_error("netconf_configure() failed\n")
86 return_code = EXIT_FAILURE;
95 switch(framework_arguments.nts_mode) {
96 case NTS_MODE_CONTAINER_INIT:
97 if(!container_self_init()) {
98 log_error("container_self_init() failed\n");
99 return_code = EXIT_FAILURE;
102 goto main_clean_framework;
105 case NTS_MODE_SUPERVISOR:
106 //run in supervisor mode
107 if(supervisor_run(argc, argv) != NTS_ERR_OK) {
108 log_error("supervisor_run() failed\n");
109 return_code = EXIT_FAILURE;
112 goto main_clean_framework;
115 case NTS_MODE_MANAGER:
116 if(manager_run() != NTS_ERR_OK) {
117 log_error("manager_run() failed\n");
118 return_code = EXIT_FAILURE;
124 case NTS_MODE_NETWORK_FUNCTION:
125 if(network_function_run() != NTS_ERR_OK) {
126 log_error("network_function_run() failed\n");
127 return_code = EXIT_FAILURE;
134 if(blank_run() != NTS_ERR_OK) {
135 log_error("blank_run() failed\n");
136 return_code = EXIT_FAILURE;
139 goto main_clean_framework;
143 if(exhaustive_test_run() != NTS_ERR_OK) {
144 log_error("exhaustive_test_run() failed\n");
145 return_code = EXIT_FAILURE;
151 case NTS_MODE_DEFAULT:
152 if(framework_arguments.print_root_paths) {
153 if(datastore_schema_print_root_paths() != NTS_ERR_OK) {
154 log_error("datastore_schema_print_root_paths() failed\n");
155 return_code = EXIT_FAILURE;
160 if(framework_arguments.print_structure_xpath != 0) {
161 //print the associated structure
162 if(datastore_schema_print_xpath(framework_arguments.print_structure_xpath) != NTS_ERR_OK) {
163 log_error("datastore_schema_print_xpath() failed\n");
164 return_code = EXIT_FAILURE;
178 log_add_verbose(1, LOG_COLOR_BOLD_RED"stopping now...\n"LOG_COLOR_RESET);
184 main_clean_framework: