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 ***************************************************************************/
22 #include <semaphore.h>
24 #include <sysrepo/values.h>
25 #include "core/docker.h"
27 #define NTS_MANAGER_MODULE "nts-manager"
28 #define NTS_SIMULATION_SCHEMA_XPATH "/nts-manager:simulation"
29 #define NTS_FUNCTION_LIST_SCHEMA_XPATH "/nts-manager:simulation/network-functions/network-function"
33 const struct lys_ident *ft;
34 const char *function_type;
39 docker_container_t container;
40 char *mount_point_addressing_method;
41 } manager_network_function_instance_t;
45 const struct lys_ident *ft;
47 manager_network_function_instance_t *instance;
48 docker_context_t *docker;
51 int started_instances;
52 int mounted_instances;
54 char *mount_point_addressing_method;
56 char *docker_instance_name;
57 char *docker_version_tag;
58 char *docker_repository;
62 MANAGER_OPERATION_EDIT = 0,
63 MANAGER_OPERATION_RPC = 1,
64 } manager_operation_type_t;
66 typedef struct manager_operation {
67 manager_operation_type_t type;
72 int started_instances;
73 int mounted_instances;
75 char *docker_instance_name;
76 char *docker_repository;
77 char *docker_version_tag;
79 char *mount_point_addressing_method;
81 //not used by EDIT, as datastore will be automatically updated
84 int delay_period_count;
99 struct manager_operation *next;
100 } manager_operation_t;
102 extern manager_context_t *manager_context;
103 extern docker_context_t *docker_context;
104 extern int docker_context_count;
107 MANAGER_PROTOCOL_UNUSED = 0,
108 MANAGER_PROTOCOL_UNAVAILABLE,
110 MANAGER_PROTOCOL_NETCONF_SSH,
111 MANAGER_PROTOCOL_NETCONF_TLS,
112 MANAGER_PROTOCOL_FTP,
113 MANAGER_PROTOCOL_SFTP,
114 MANAGER_PROTOCOL_HTTP,
115 MANAGER_PROTOCOL_HTTPS,
116 } manager_protocol_type_t;
118 extern manager_protocol_type_t manager_port[65536];
121 int manager_run(void);
124 int manager_context_init(void);
125 void manager_context_free(void);
127 //manager_operations.c
128 int manager_operations_init(void);
129 void manager_operations_loop(void);
130 void manager_operations_free(void);
132 manager_operation_t *manager_operations_new_oper(manager_operation_type_t type);
133 int manager_operations_free_oper(manager_operation_t *oper);
135 int manager_operations_begin(void);
136 int manager_operations_add(manager_operation_t *oper);
137 void manager_operations_finish_and_execute(void);
138 void manager_operations_finish_with_error(void);
140 int manager_operations_validate(manager_operation_t *oper);
143 int manager_actions_start(manager_context_t *ctx);
144 int manager_actions_config_instance(manager_context_t *ctx, manager_network_function_instance_t *instance);
145 int manager_actions_stop(manager_context_t *ctx);
146 int manager_actions_mount(manager_context_t *ctx);
147 int manager_actions_unmount(manager_context_t *ctx);
150 int manager_sr_get_context_sync(void);
151 int manager_sr_update_context(manager_context_t *ctx);
152 int manager_sr_on_last_operation_status(const char *status, const char *errmsg);
153 int manager_sr_notif_send_instance_changed(const char *status, const char *function_type, const char *name, const manager_network_function_instance_t* instance);
154 int manager_sr_update_static_stats(void);
155 int manager_sr_stats_get_items_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, const char *request_xpath, uint32_t request_id, struct lyd_node **parent, void *private_data);
156 int manager_sr_populate_networking(struct lyd_node *parent, const manager_network_function_instance_t* instance);