Add VES stndDefined PM and subscription for O-DU.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / main.c
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
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
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
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 ***************************************************************************/
17
18 #define _GNU_SOURCE
19
20 #include <stdio.h>
21 #include <stddef.h>
22 #include <string.h>
23 #include <assert.h>
24
25 #include "utils/log_utils.h"
26 #include "utils/nc_client.h"
27
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"
34
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"
41
42 int main(int argc, char **argv) {
43     int return_code = EXIT_SUCCESS;
44
45     if(framework_init(argc, argv) != NTS_ERR_OK) {
46         log_error(LOG_COLOR_BOLD_RED"framework_init() error\n");
47         framework_free();
48         return EXIT_FAILURE;
49     }
50
51     //common init
52     switch(framework_arguments.nts_mode) {
53         case NTS_MODE_MANAGER:
54         case NTS_MODE_NETWORK_FUNCTION:
55         case NTS_MODE_TEST:
56         case NTS_MODE_DEFAULT:
57             sr_log_stderr(SR_LL_INF);   //checkAL WRN
58         
59             if(session_init() != NTS_ERR_OK) {
60                 log_error("session_init() failed\n");
61                 return_code = EXIT_FAILURE;
62                 goto main_clean_session;
63             }
64
65             if(context_init(session_context) != 0) {
66                 log_error("context_init() failed\n");
67                 return_code = EXIT_FAILURE;
68                 goto main_clean_context;
69             }
70
71             nc_client_init();
72             break;
73
74         default:
75             break;
76     }
77
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;
87                 goto main_clean;
88             }
89             break;
90
91         default:
92             break;
93     }
94
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;
100             }
101
102             goto main_clean_framework;
103             break;
104
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;
110             }
111
112             goto main_clean_framework;
113             break;
114
115         case NTS_MODE_MANAGER:
116             if(manager_run() != NTS_ERR_OK) {
117                 log_error("manager_run() failed\n");
118                 return_code = EXIT_FAILURE;
119             }
120
121             goto main_clean;
122             break;
123
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;
128             }
129
130             goto main_clean;
131             break;
132
133         case NTS_MODE_BLANK:
134             if(blank_run() != NTS_ERR_OK) {
135                 log_error("blank_run() failed\n");
136                 return_code = EXIT_FAILURE;
137             }
138
139             goto main_clean_framework;
140             break;
141
142         case NTS_MODE_TEST:
143             if(exhaustive_test_run() != NTS_ERR_OK) {
144                 log_error("exhaustive_test_run() failed\n");
145                 return_code = EXIT_FAILURE;
146             }
147         
148             goto main_clean;
149             break;
150
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;
156                     goto main_clean;
157                 }
158             }
159             
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;
165                     goto main_clean;
166                 }
167             }
168
169             goto main_clean;
170             break;
171
172         default:
173             assert(0);
174             break;
175     }
176
177 main_clean:
178     log_add_verbose(1, LOG_COLOR_BOLD_RED"stopping now...\n"LOG_COLOR_RESET);
179     nc_client_destroy();
180 main_clean_context:
181     context_free();
182 main_clean_session:
183     session_free();
184 main_clean_framework:
185     framework_free();
186     return return_code;
187 }