Add NF addressing method as ENV.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / app / manager.h
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 #pragma once
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <semaphore.h>
23 #include <sysrepo.h>
24 #include <sysrepo/values.h>
25 #include "core/docker.h"
26
27
28 typedef struct {
29     //meta-data
30     const struct lys_ident *ft;
31     const char *function_type;
32     bool is_init;
33     bool is_configured;
34     bool is_mounted;
35
36     docker_container_t container;
37     char *mount_point_addressing_method;
38 } manager_network_function_instance_t;
39
40 typedef struct {
41     //manager_docker data
42     const struct lys_ident *ft;
43     char *function_type;
44     manager_network_function_instance_t *instance;
45     docker_context_t *docker;
46
47     //yang data
48     int started_instances;
49     int mounted_instances;
50
51     char *mount_point_addressing_method;
52     
53     char *docker_instance_name;
54     char *docker_version_tag;
55     char *docker_repository;
56 } manager_context_t;
57
58 typedef enum {
59     MANAGER_OPERATION_EDIT = 0,
60     MANAGER_OPERATION_RPC = 1,
61 } manager_operation_type_t;
62
63 typedef struct manager_operation {
64     manager_operation_type_t type;
65
66     int ft_index;
67     char *function_type;
68
69     int started_instances;
70     int mounted_instances;
71
72     char *docker_instance_name;
73     char *docker_repository;
74     char *docker_version_tag;
75
76     char *mount_point_addressing_method;
77
78     //not used by EDIT, as datastore will be automatically updated
79     struct {
80         int *delay_period;
81         int delay_period_count;
82     } fault_generation;
83
84     struct {
85         int faults_enabled;
86         int call_home;
87     } netconf;
88
89     struct {
90         int faults_enabled;
91         int pnf_registration;
92         int heartbeat_period;
93     } ves;
94
95     char *errmsg;
96     struct manager_operation *next;
97 } manager_operation_t;
98
99 extern manager_context_t *manager_context;
100 extern docker_context_t *docker_context;
101 extern int docker_context_count;
102
103 typedef enum {
104     MANAGER_PROTOCOL_UNUSED = 0,
105     MANAGER_PROTOCOL_UNAVAILABLE,
106
107     MANAGER_PROTOCOL_NETCONF_SSH,
108     MANAGER_PROTOCOL_NETCONF_TLS,
109     MANAGER_PROTOCOL_FTP,
110     MANAGER_PROTOCOL_SFTP,
111     MANAGER_PROTOCOL_HTTP,
112     MANAGER_PROTOCOL_HTTPS,
113 } manager_protocol_type_t;
114
115 extern manager_protocol_type_t manager_port[65536];
116
117 //manager.c
118 int manager_run(void);
119
120 //manager_context.c
121 int manager_context_init(void);
122 void manager_context_free(void);
123
124 //manager_operations.c
125 int manager_operations_init(void);
126 void manager_operations_loop(void);
127 void manager_operations_free(void);
128
129 manager_operation_t *manager_operations_new_oper(manager_operation_type_t type);
130 int manager_operations_free_oper(manager_operation_t *oper);
131
132 int manager_operations_begin(void);
133 int manager_operations_add(manager_operation_t *oper);
134 void manager_operations_finish_and_execute(void);
135 void manager_operations_finish_with_error(void);
136
137 int manager_operations_validate(manager_operation_t *oper);
138
139 //manager_actions.c
140 int manager_actions_start(manager_context_t *ctx);
141 int manager_actions_config_instance(manager_context_t *ctx, manager_network_function_instance_t *instance);
142 int manager_actions_stop(manager_context_t *ctx);
143 int manager_actions_mount(manager_context_t *ctx);
144 int manager_actions_unmount(manager_context_t *ctx);
145
146 //manager_sysrepo.c
147 int manager_sr_get_context_sync(void);
148 int manager_sr_update_context(manager_context_t *ctx);
149 int manager_sr_on_last_operation_status(const char *status, const char *errmsg);
150 int manager_sr_notif_send_instance_changed(const char *status, const char *function_type, const char *name, const manager_network_function_instance_t* instance);
151 int manager_sr_update_static_stats(void);
152 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);
153 int manager_sr_populate_networking(struct lyd_node *parent, const manager_network_function_instance_t* instance);