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"
47 int main(int argc, char **argv) {
48 int return_code = EXIT_SUCCESS;
50 framework_init(argc, argv);
52 if(framework_arguments.container_init) {
53 if(!docker_container_init()) {
54 log_error("docker_container_init() failed");
55 return_code = EXIT_FAILURE;
61 else { //not in container-init mode
62 sr_log_stderr(SR_LL_NONE);
67 log_error("session_init() failed");
68 return_code = EXIT_FAILURE;
69 goto non_container_init_cleanup;
72 rc = context_init(session_context);
74 log_error("context_init() failed");
75 return_code = EXIT_FAILURE;
76 goto non_container_init_cleanup;
81 if(framework_arguments.nc_server_init) {
82 //configure local netconf server
83 rc = netconf_configure();
85 log_error("netconf_configure() failed");
86 return_code = EXIT_FAILURE;
87 goto non_container_init_cleanup;
91 if(framework_arguments.manager) {
93 if(manager_run() != NTS_ERR_OK) {
94 return_code = EXIT_FAILURE;
95 goto non_container_init_cleanup;
98 else if(framework_arguments.network_function) {
99 //run in network function mode
100 if(network_function_run() != NTS_ERR_OK) {
101 return_code = EXIT_FAILURE;
102 goto non_container_init_cleanup;
106 if(framework_arguments.test_mode) {
107 if(test_mode_run() != NTS_ERR_OK) {
108 return_code = EXIT_FAILURE;
109 goto non_container_init_cleanup;
112 else if(framework_arguments.exhaustive_test) {
114 if(exhaustive_test_run() != NTS_ERR_OK) {
115 return_code = EXIT_FAILURE;
116 goto non_container_init_cleanup;
120 if(framework_arguments.print_root_paths) {
121 //print all root paths with their attributes
122 if(schema_print_root_paths() != NTS_ERR_OK) {
123 return_code = EXIT_FAILURE;
124 goto non_container_init_cleanup;
128 if(framework_arguments.print_structure_xpath != 0) {
129 //print the associated structure
130 if(schema_print_xpath(framework_arguments.print_structure_xpath) != NTS_ERR_OK) {
131 return_code = EXIT_FAILURE;
132 goto non_container_init_cleanup;
136 if(framework_arguments.populate_all) {
138 if(schema_populate() != NTS_ERR_OK) {
139 return_code = EXIT_FAILURE;
140 goto non_container_init_cleanup;
144 if(framework_arguments.enable_features) {
145 // check if PNF registration is enabled and send PNF registration message if so
146 rc = ves_pnf_registration_feature_start(session_running);
148 log_error("ves_pnf_registration_feature_start() failed");
149 return_code = EXIT_FAILURE;
150 goto non_container_init_cleanup;
153 // start feature for handling the heartbeat VES message
154 rc = ves_heartbeat_feature_start(session_running);
156 log_error("ves_heartbeat_feature_start() failed");
157 return_code = EXIT_FAILURE;
158 goto non_container_init_cleanup;
161 // start feature for handling the fileReady VES message
162 rc = ves_file_ready_feature_start(session_running);
164 log_error("ves_file_ready_feature_start() failed");
165 return_code = EXIT_FAILURE;
166 goto non_container_init_cleanup;
169 // start feature for manual notification
170 rc = manual_notification_feature_start(session_running);
172 log_error("manual_notification_feature_start() failed");
173 return_code = EXIT_FAILURE;
174 goto non_container_init_cleanup;
177 // start feature for NETCONF Call Home
178 rc = netconf_call_home_feature_start(session_running);
180 log_error("netconf_call_home_feature_start() failed");
181 return_code = EXIT_FAILURE;
182 goto non_container_init_cleanup;
186 if(framework_arguments.loop) {
187 while(!framework_sigint) {
193 non_container_init_cleanup:
194 log_message(1, LOG_COLOR_BOLD_RED"\nstopping now...\n"LOG_COLOR_RESET);