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/docker.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/manager.h"
36 #include "core/app/network_function.h"
37 #include "core/datastore/schema.h"
38 #include "core/datastore/populate.h"
39 #include "core/faults/faults.h"
41 #include "features/ves_pnf_registration/ves_pnf_registration.h"
42 #include "features/ves_heartbeat/ves_heartbeat.h"
43 #include "features/ves_file_ready/ves_file_ready.h"
44 #include "features/manual_notification/manual_notification.h"
45 #include "features/netconf_call_home/netconf_call_home.h"
46 #include "features/web_cut_through/web_cut_through.h"
48 int main(int argc, char **argv) {
49 int return_code = EXIT_SUCCESS;
51 framework_init(argc, argv);
53 if(framework_arguments.container_init) {
54 if(!docker_container_init()) {
55 log_error("docker_container_init() failed");
56 return_code = EXIT_FAILURE;
62 else { //not in container-init mode
63 sr_log_stderr(SR_LL_NONE);
68 log_error("session_init() failed");
69 return_code = EXIT_FAILURE;
70 goto non_container_init_cleanup;
73 rc = context_init(session_context);
75 log_error("context_init() failed");
76 return_code = EXIT_FAILURE;
77 goto non_container_init_cleanup;
82 if(framework_arguments.nc_server_init) {
83 //configure local netconf server
84 rc = netconf_configure();
86 log_error("netconf_configure() failed");
87 return_code = EXIT_FAILURE;
88 goto non_container_init_cleanup;
92 if(framework_arguments.manager) {
94 if(manager_run() != NTS_ERR_OK) {
95 return_code = EXIT_FAILURE;
96 goto non_container_init_cleanup;
99 else if(framework_arguments.network_function) {
100 //run in network function mode
101 if(network_function_run() != NTS_ERR_OK) {
102 return_code = EXIT_FAILURE;
103 goto non_container_init_cleanup;
107 if(framework_arguments.test_mode) {
108 if(test_mode_run() != NTS_ERR_OK) {
109 return_code = EXIT_FAILURE;
110 goto non_container_init_cleanup;
113 else if(framework_arguments.exhaustive_test) {
115 if(exhaustive_test_run() != NTS_ERR_OK) {
116 return_code = EXIT_FAILURE;
117 goto non_container_init_cleanup;
121 if(framework_arguments.print_root_paths) {
122 //print all root paths with their attributes
123 if(schema_print_root_paths() != NTS_ERR_OK) {
124 return_code = EXIT_FAILURE;
125 goto non_container_init_cleanup;
129 if(framework_arguments.print_structure_xpath != 0) {
130 //print the associated structure
131 if(schema_print_xpath(framework_arguments.print_structure_xpath) != NTS_ERR_OK) {
132 return_code = EXIT_FAILURE;
133 goto non_container_init_cleanup;
137 if(framework_arguments.populate_all) {
139 if(schema_populate() != NTS_ERR_OK) {
140 return_code = EXIT_FAILURE;
141 goto non_container_init_cleanup;
145 if(framework_arguments.enable_features) {
146 // check if PNF registration is enabled and send PNF registration message if so
147 rc = ves_pnf_registration_feature_start(session_running);
149 log_error("ves_pnf_registration_feature_start() failed");
150 return_code = EXIT_FAILURE;
151 goto non_container_init_cleanup;
154 // start feature for handling the heartbeat VES message
155 rc = ves_heartbeat_feature_start(session_running);
157 log_error("ves_heartbeat_feature_start() failed");
158 return_code = EXIT_FAILURE;
159 goto non_container_init_cleanup;
162 // start feature for handling the fileReady VES message
163 rc = ves_file_ready_feature_start(session_running);
165 log_error("ves_file_ready_feature_start() failed");
166 return_code = EXIT_FAILURE;
167 goto non_container_init_cleanup;
170 // start feature for manual notification
171 rc = manual_notification_feature_start(session_running);
173 log_error("manual_notification_feature_start() failed");
174 return_code = EXIT_FAILURE;
175 goto non_container_init_cleanup;
178 // start feature for NETCONF Call Home
179 rc = netconf_call_home_feature_start(session_running);
181 log_error("netconf_call_home_feature_start() failed");
182 return_code = EXIT_FAILURE;
183 goto non_container_init_cleanup;
186 // start feature for web cut through
187 rc = web_cut_through_feature_start(session_running);
189 log_error("web_cut_through_feature_start() failed");
190 return_code = EXIT_FAILURE;
191 goto non_container_init_cleanup;
195 if(framework_arguments.loop) {
196 while(!framework_sigint) {
202 non_container_init_cleanup:
203 log_message(1, LOG_COLOR_BOLD_RED"\nstopping now...\n"LOG_COLOR_RESET);