Bug fix.
[sim/o1-interface.git] / ntsimulator / src / ntsimulator-manager / simulator-operations.h
1 /*************************************************************************
2 *
3 * Copyright 2019 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 #ifndef SRC_NTSIMULATOR_MANAGER_SIMULATOR_OPERATIONS_H_
19 #define SRC_NTSIMULATOR_MANAGER_SIMULATOR_OPERATIONS_H_
20
21 #include <curl/curl.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25
26 #include "sysrepo.h"
27 #include "sysrepo/values.h"
28
29 #include <cjson/cJSON.h>
30
31 #define CURL_MEM_SIZE 2048
32
33
34 /**
35  * Storing the device information
36 */
37
38 typedef struct device {
39         char *device_id;
40         int netconf_port;
41     int device_number;
42         bool is_mounted;
43         char *operational_state;
44         struct device *next;
45 } device_t;
46
47 typedef struct device_stack {
48         device_t *head;
49         size_t stack_size;
50 } device_stack_t;
51
52 #define URL_AND_CREDENTIALS_MAX_LEN 400
53
54 typedef struct controller
55 {
56         char url[URL_AND_CREDENTIALS_MAX_LEN];
57         char credentials[URL_AND_CREDENTIALS_MAX_LEN];
58         char url_for_keystore_add[URL_AND_CREDENTIALS_MAX_LEN];
59         char url_for_private_key_add[URL_AND_CREDENTIALS_MAX_LEN];
60         char url_for_trusted_ca_add[URL_AND_CREDENTIALS_MAX_LEN];
61 } controller_t;
62
63
64 device_stack_t *new_device_stack(void);
65 void push_device(device_stack_t *theStack, char *dev_id, int port, int dev_num);
66 void pop_device(device_stack_t *theStack);
67 int get_netconf_port_next(device_stack_t *theStack);
68 int get_netconf_port_base(void);
69 int get_device_number_next(device_stack_t *theStack);
70 char *get_id_last_device(device_stack_t *theStack);
71 int get_current_number_of_devices(device_stack_t *theStack);
72 int get_current_number_of_mounted_devices(device_stack_t *theStack);
73
74
75 /**
76  * cURL utilities
77 */
78
79 struct MemoryStruct {
80   char *memory;
81   size_t size;
82 };
83
84 int _init_curl(void);
85 int cleanup_curl(void);
86
87 int _init_curl_odl(void);
88 int cleanup_curl_odl(void);
89
90 int _init_curl_k8s(void);
91 int cleanup_curl_k8s(void);
92
93 int start_device(device_stack_t *theStack);
94 int stop_device(device_stack_t *theStack);
95
96 int mount_device(device_stack_t *theStack, controller_t controller_details);
97 int unmount_device(device_stack_t *theStack, controller_t controller_details);
98
99 char* get_docker_container_operational_state(device_stack_t *theStack, char *container_id);
100 int get_docker_containers_operational_state_curl(device_stack_t *theStack);
101
102 char* get_docker_container_resource_stats();
103
104 int notification_delay_period_changed(sr_val_t *val, size_t count);
105 int ves_heartbeat_period_changed(int period);
106 int ves_ip_changed(char *new_ip);
107 int ves_port_changed(int new_port);
108 int ves_username_changed(char *new_username);
109 int ves_password_changed(char *new_password);
110 int ves_auth_method_changed(char *new_auth_method);
111 int ves_registration_changed(cJSON_bool new_bool);
112 int is_netconf_available_changed(cJSON_bool new_bool);
113 int is_ves_available_changed(cJSON_bool new_bool);
114 int ssh_connections_changed(int number);
115 int tls_connections_changed(int number);
116
117 int controller_ip_changed(char *new_ip);
118 int controller_port_changed(int new_port);
119 int controller_netconf_call_home_port_changed(int new_port);
120 int controller_username_changed(char *new_username);
121 int controller_password_changed(char *new_password);
122 int netconf_call_home_changed(cJSON_bool new_bool);
123
124
125 int add_key_pair_to_odl(controller_t *controller_list, int controller_list_size);
126
127 int send_k8s_scale(int number_of_devices);
128 int send_k8s_extend_port(void);
129
130 int invoke_device_notification(char *device_id, char *module_name, char *notification_string);
131
132 int pull_docker_image_of_simulated_device(void);
133
134 #endif /* SRC_NTSIMULATOR_MANAGER_SIMULATOR_OPERATIONS_H_ */