Add supoprt for D release use-case.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / utils / nts_utils.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 "nts_utils.h"
21 #include "utils/log_utils.h"
22 #include "utils/sys_utils.h"
23 #include "core/framework.h"
24 #include "core/session.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <assert.h>
28
29 #define NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH             "/nts-manager:simulation/sdn-controller"
30 #define NTS_NF_SDN_CONTROLLER_CONFIG_XPATH                  "/nts-network-function:simulation/sdn-controller"
31 #define NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH               "/nts-manager:simulation/ves-endpoint"
32 #define NTS_NF_VES_ENDPOINT_CONFIG_XPATH                    "/nts-network-function:simulation/ves-endpoint"
33
34 #define NTS_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH             "/nts-network-function:simulation/network-function/function-type"
35 #define NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH              "/nts-network-function:simulation/network-function/mount-point-addressing-method"
36 #define NTS_NETWORK_FUNCTION_FAULT_GENERATION_SCHEMA_XPATH  "/nts-network-function:simulation/network-function/fault-generation"
37 #define NTS_NETWORK_FUNCTION_NETCONF_SCHEMA_XPATH           "/nts-network-function:simulation/network-function/netconf"
38 #define NTS_NETWORK_FUNCTION_VES_SCHEMA_XPATH               "/nts-network-function:simulation/network-function/ves"
39
40
41 cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *source_name, const char *priority, int seq_id) {
42     assert(domain);
43     assert(event_type);
44     assert(source_name);
45     assert(priority);
46
47     char *eventId = 0;
48     long useconds = get_microseconds_since_epoch();
49
50     asprintf(&eventId, "%s-%d", event_type, seq_id);
51     if(eventId == 0) {
52         log_error("asprintf failed\n");
53         return 0;
54     }
55
56     cJSON *common_event_header = cJSON_CreateObject();
57     if(common_event_header == 0) {
58         log_error("could not create JSON object\n");
59         free(eventId);
60         return 0;
61     }
62
63     if(cJSON_AddStringToObject(common_event_header, "domain", domain) == 0) {
64         log_error("cJSON AddStringToObject error\n");
65         free(eventId);
66         cJSON_Delete(common_event_header);
67         return 0;
68     }
69
70     if(cJSON_AddStringToObject(common_event_header, "eventId", eventId) == 0) {
71         log_error("cJSON AddStringToObject error\n");
72         free(eventId);
73         cJSON_Delete(common_event_header);
74         return 0;
75     }
76
77     free(eventId);
78
79     if(cJSON_AddStringToObject(common_event_header, "eventName", event_type) == 0) {
80         log_error("cJSON AddStringToObject error\n");
81         cJSON_Delete(common_event_header);
82         return 0;
83     }
84
85     if(cJSON_AddNumberToObject(common_event_header, "sequence", (double)(seq_id)) == 0) {
86         log_error("cJSON AddNumberToObject error\n");
87         cJSON_Delete(common_event_header);
88         return 0;
89     }
90
91     if(cJSON_AddStringToObject(common_event_header, "priority", priority) == 0) {
92         log_error("cJSON AddStringToObject error\n");
93         cJSON_Delete(common_event_header);
94         return 0;
95     }
96
97     if(cJSON_AddStringToObject(common_event_header, "reportingEntityId", "") == 0) {
98         log_error("cJSON AddStringToObject error\n");
99         cJSON_Delete(common_event_header);
100         return 0;
101     }
102
103     if(cJSON_AddStringToObject(common_event_header, "reportingEntityName", source_name) == 0) {
104         log_error("cJSON AddStringToObject error\n");
105         cJSON_Delete(common_event_header);
106         return 0;
107     }
108
109     if(cJSON_AddStringToObject(common_event_header, "sourceId", "") == 0) {
110         log_error("cJSON AddStringToObject error\n");
111         cJSON_Delete(common_event_header);
112         return 0;
113     }
114
115     if(cJSON_AddStringToObject(common_event_header, "sourceName", source_name) == 0) {
116         log_error("cJSON AddStringToObject error\n");
117         cJSON_Delete(common_event_header);
118         return 0;
119     }
120
121     if(cJSON_AddNumberToObject(common_event_header, "startEpochMicrosec", (double)(useconds)) == 0) {
122         log_error("cJSON AddNumberToObject error\n");
123         cJSON_Delete(common_event_header);
124         return 0;
125     }
126
127     if(cJSON_AddNumberToObject(common_event_header, "lastEpochMicrosec", (double)(useconds)) == 0) {
128         log_error("cJSON AddNumberToObject error\n");
129         cJSON_Delete(common_event_header);
130         return 0;
131     }
132
133     if(cJSON_AddStringToObject(common_event_header, "nfNamingCode", "sdn controller") == 0) {
134         log_error("cJSON AddStringToObject error\n");
135         cJSON_Delete(common_event_header);
136         return 0;
137     }
138
139     if(cJSON_AddStringToObject(common_event_header, "nfVendorName", "sdn") == 0) {
140         log_error("cJSON AddStringToObject error\n");
141         cJSON_Delete(common_event_header);
142         return 0;
143     }
144
145     if(cJSON_AddStringToObject(common_event_header, "timeZoneOffset", "+00:00") == 0) {
146         log_error("cJSON AddStringToObject error\n");
147         cJSON_Delete(common_event_header);
148         return 0;
149     }
150
151     if(cJSON_AddStringToObject(common_event_header, "version", "4.1") == 0) {
152         log_error("cJSON AddStringToObject error\n");
153         cJSON_Delete(common_event_header);
154         return 0;
155     }
156
157     if(cJSON_AddStringToObject(common_event_header, "vesEventListenerVersion", framework_environment.ves_endpoint.common_header_version) == 0) {
158         log_error("cJSON AddStringToObject error\n");
159         cJSON_Delete(common_event_header);
160         return 0;
161     }
162
163     return common_event_header;
164 }
165
166 nts_mount_point_addressing_method_t nts_mount_point_addressing_method_get(sr_session_ctx_t *current_session) {
167     assert_session();
168
169     nts_mount_point_addressing_method_t ret = UNKNOWN_MAPPING;
170
171     int rc;
172     bool session_started = false;
173     if(current_session == 0) {
174         rc = sr_session_start(session_connection, SR_DS_RUNNING, &current_session);
175         if(rc != SR_ERR_OK) {
176             log_error("could not start sysrepo session\n");
177             return ret;
178         }
179         session_started = true;
180     }
181
182     sr_val_t *value = 0;
183     rc = sr_get_item(session_running, NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, 0, &value);
184     if(rc == SR_ERR_OK) {
185         if(strcmp(value->data.enum_val, "host-mapping") == 0) {
186             ret = HOST_MAPPING;
187         }
188         else {
189             ret = DOCKER_MAPPING;
190         }
191         sr_free_val(value);
192     }
193
194     if(session_started) {
195         rc = sr_session_stop(current_session);
196         if(rc != SR_ERR_OK) {
197             log_error("could not stop sysrepo session\n");
198             return ret;
199         }
200     }
201
202     return ret;
203 }
204
205 // checkAS authentication via certificate not supported yet
206 ves_details_t *ves_endpoint_details_get(sr_session_ctx_t *current_session) {
207     assert_session();
208
209     int rc;
210     bool session_started = false;
211     if(current_session == 0) {
212         rc = sr_session_start(session_connection, SR_DS_RUNNING, &current_session);
213         if(rc != SR_ERR_OK) {
214             log_error("could not start sysrepo session\n");
215             return 0;
216         }
217         session_started = true;
218     }
219
220     struct lyd_node *data = 0;
221     char *xpath_to_get;
222
223     if(framework_arguments.nts_mode == NTS_MODE_MANAGER) {
224         xpath_to_get = "/nts-manager:simulation/ves-endpoint";
225     }
226     else {
227         xpath_to_get = "/nts-network-function:simulation/ves-endpoint";
228     }
229
230     rc = sr_get_subtree(current_session, xpath_to_get, 0, &data);
231     if(rc != SR_ERR_OK) {
232         log_error("could not get value for xPath=%s from the running datastore\n", xpath_to_get);
233         if(session_started) {
234             sr_session_stop(current_session);
235         }
236         return 0;
237     }
238
239     if(session_started) {
240         rc = sr_session_stop(current_session);
241         if(rc != SR_ERR_OK) {
242             log_error("could not stop sysrepo session\n");
243             lyd_free(data);
244             return 0;
245         }
246     }
247
248     if(data->child == 0) {
249         log_error("ves-endpoint probably not set yet\n", xpath_to_get);
250         lyd_free(data);
251         return 0;
252     }
253
254     ves_details_t *ret = (ves_details_t *)malloc(sizeof(ves_details_t));
255     if(!ret) {
256         log_error("malloc failed\n");
257         lyd_free(data);
258         return 0;
259     }
260
261     ret->protocol = 0;
262     ret->ip = 0;
263     ret->port = 0;
264     ret->auth_method = 0;
265     ret->username = 0;
266     ret->password = 0;
267
268     struct lyd_node *chd = 0;
269     LY_TREE_FOR(data->child, chd) {
270         const char *val = ((const struct lyd_node_leaf_list *)chd)->value_str;
271
272         if(strcmp(chd->schema->name, "ves-endpoint-protocol") == 0) {
273             ret->protocol = strdup(val);
274         }
275         else if(strcmp(chd->schema->name, "ves-endpoint-ip") == 0) {
276             ret->ip = strdup(val);
277         }
278         else if(strcmp(chd->schema->name, "ves-endpoint-port") == 0) {
279             ret->port = ((const struct lyd_node_leaf_list *)chd)->value.uint16;
280         }
281         else if(strcmp(chd->schema->name, "ves-endpoint-auth-method") == 0) {
282             ret->auth_method = strdup(val);
283         }
284         else if(strcmp(chd->schema->name, "ves-endpoint-username") == 0) {
285             ret->username = strdup(val);
286         }
287         else if(strcmp(chd->schema->name, "ves-endpoint-password") == 0) {
288             ret->password = strdup(val);
289         }
290     }
291     lyd_free(data);
292
293     if (strstr(ret->ip, ":")) {
294         // IPv6 address
295         asprintf(&ret->url, "%s://[%s]:%d/eventListener/v7", ret->protocol, ret->ip, ret->port);
296     }
297     else {
298         asprintf(&ret->url, "%s://%s:%d/eventListener/v7", ret->protocol, ret->ip, ret->port);
299     }
300     
301     if((ret->protocol == 0) || (ret->ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->url == 0)) {
302         free(ret->protocol);
303         free(ret->ip);
304         free(ret->auth_method);
305         free(ret->username);
306         free(ret->password);
307         free(ret->url);
308         free(ret);
309         ret = 0;
310     }
311
312     return ret;
313 }
314
315 void ves_details_free(ves_details_t *instance) {
316     assert(instance);
317
318     free(instance->protocol);
319     free(instance->ip);
320     free(instance->url);
321     free(instance->auth_method);
322     free(instance->username);
323     free(instance->password);
324     free(instance);
325 }
326
327
328 // checkAS authentication via certificate not supported yet
329 controller_details_t *controller_details_get(sr_session_ctx_t *current_session) {
330     assert_session();
331
332     int rc;
333     bool session_started = false;
334     if(current_session == 0) {
335         rc = sr_session_start(session_connection, SR_DS_RUNNING, &current_session);
336         if(rc != SR_ERR_OK) {
337             log_error("could not start sysrepo session\n");
338             return 0;
339         }
340         session_started = true;
341     }
342
343     struct lyd_node *data = 0;
344     char *xpath_to_get;
345
346     if(framework_arguments.nts_mode == NTS_MODE_MANAGER) {
347         xpath_to_get = "/nts-manager:simulation/sdn-controller";
348     }
349     else {
350         xpath_to_get = "/nts-network-function:simulation/sdn-controller";
351     }
352
353     rc = sr_get_subtree(current_session, xpath_to_get, 0, &data);
354     if(rc != SR_ERR_OK) {
355         log_error("could not get value for xPath=%s from the running datastore\n", xpath_to_get);
356         if(session_started) {
357             sr_session_stop(current_session);
358         }
359         return 0;
360     }
361
362     if(session_started) {
363         rc = sr_session_stop(current_session);
364         if(rc != SR_ERR_OK) {
365             log_error("could not stop sysrepo session\n");
366             lyd_free(data);
367             return 0;
368         }
369     }
370
371     if(data->child == 0) {
372         log_error("sdn-controller probably not set yet\n");
373         lyd_free(data);
374         return 0;
375     }
376
377     controller_details_t *ret = (controller_details_t *)malloc(sizeof(controller_details_t));
378     if(!ret) {
379         log_error("malloc failed\n");
380         lyd_free(data);
381         return 0;
382     }
383
384     ret->protocol = 0;
385     ret->ip = 0;
386     ret->port = 0;
387     ret->nc_callhome_port = 0;
388     ret->auth_method = 0;
389     ret->username = 0;
390     ret->password = 0;
391
392     ret->auth_method = strdup("basic");
393
394     struct lyd_node *chd = 0;
395     LY_TREE_FOR(data->child, chd) {
396         const char *val = ((const struct lyd_node_leaf_list *)chd)->value_str;
397
398         if(strcmp(chd->schema->name, "controller-protocol") == 0) {
399             ret->protocol = strdup(val);
400         }
401         else if(strcmp(chd->schema->name, "controller-ip") == 0) {
402             ret->ip = strdup(val);
403         }
404         else if(strcmp(chd->schema->name, "controller-port") == 0) {
405             ret->port = ((const struct lyd_node_leaf_list *)chd)->value.uint16;
406         }
407         else if(strcmp(chd->schema->name, "controller-netconf-call-home-port") == 0) {
408             ret->nc_callhome_port = ((const struct lyd_node_leaf_list *)chd)->value.uint16;
409         }
410         else if(strcmp(chd->schema->name, "controller-username") == 0) {
411             ret->username = strdup(val);
412         }
413         else if(strcmp(chd->schema->name, "controller-password") == 0) {
414             ret->password = strdup(val);
415         }
416     }
417     lyd_free(data);
418
419     if (strstr(ret->ip, ":")) {
420         // IPv6 address
421         asprintf(&ret->base_url, "%s://[%s]:%d", ret->protocol, ret->ip, ret->port);
422     }
423     else {
424         asprintf(&ret->base_url, "%s://%s:%d", ret->protocol, ret->ip, ret->port);
425     }
426
427     if((ret->protocol == 0) || (ret->ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->base_url == 0)) {
428         free(ret->protocol);
429         free(ret->ip);
430         free(ret->auth_method);
431         free(ret->username);
432         free(ret->password);
433         free(ret->base_url);
434         free(ret);
435         ret = 0;
436     }
437
438     return ret;
439 }
440
441 void controller_details_free(controller_details_t *instance) {
442     assert(instance);
443
444     free(instance->protocol);
445     free(instance->ip);
446     free(instance->base_url);
447     free(instance->auth_method);
448     free(instance->username);
449     free(instance->password);
450     free(instance);
451 }
452
453 int nts_vercmp(const char *ver1, const char *ver2) {
454     assert(ver1);
455     assert(ver2);
456
457     int i = 0;
458     int v1 = 0, v2 = 0, v3 = 0;
459     while(ver1[i] && (ver1[i] != '.')) {
460         v1 *= 10;
461         v1 += ver1[i] - '0';
462         i++;
463     }
464
465     if(ver1[i]) {
466         i++;
467         while(ver1[i] && (ver1[i] != '.')) {
468             v2 *= 10;
469             v2 += ver1[i] - '0';
470             i++;
471         }
472
473         if(ver1[i]) {
474             i++;
475             while(ver1[i] && (ver1[i] != '.')) {
476                 v3 *= 10;
477                 v3 += ver1[i] - '0';
478                 i++;
479             }
480         }
481     }
482
483
484     int V1 = 0, V2 = 0, V3 = 0;
485     i = 0;
486     while(ver2[i] && (ver2[i] != '.')) {
487         V1 *= 10;
488         V1 += ver2[i] - '0';
489         i++;
490     }
491
492     if(ver2[i]) {
493         i++;
494         while(ver2[i] && (ver2[i] != '.')) {
495             V2 *= 10;
496             V2 += ver2[i] - '0';
497             i++;
498         }
499
500         if(ver2[i]) {
501             i++;
502             while(ver2[i] && (ver2[i] != '.')) {
503                 V3 *= 10;
504                 V3 += ver2[i] - '0';
505                 i++;
506             }
507         }
508     }
509
510     if(v1 < V1) {
511         return -1;
512     }
513     else if(v1 > V1) {
514         return 1;
515     }
516
517     if(v2 < V2) {
518         return -1;
519     }
520     else if(v2 > V2) {
521         return 1;
522     }
523
524     if(v3 < V3) {
525         return -1;
526     }
527     else if(v3 > V3) {
528         return 1;
529     }
530
531     return 0;
532 }
533
534 int nts_utils_populate_info(sr_session_ctx_t *current_session, const char *function_type) {
535     assert(current_session);
536     assert(function_type);
537
538     bool manager = (strcmp(function_type, "NTS_FUNCTION_TYPE_MANAGER") == 0);
539
540     int rc;
541     char int_to_str[30];
542     //setup sdn-controller defaults
543     if(strlen(framework_environment.sdn_controller.protocol)) {
544         if(manager) {
545             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-protocol", (const char*)framework_environment.sdn_controller.protocol, 0, 0);
546         }
547         else {
548             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-protocol", (const char*)framework_environment.sdn_controller.protocol, 0, 0);
549         }
550         if(rc != SR_ERR_OK) {
551             log_error("sr_set_item_str failed\n");
552             return NTS_ERR_FAILED;
553         }
554     }
555
556     if(strlen(framework_environment.sdn_controller.ip)) {
557         if(manager) {
558             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-ip", (const char*)framework_environment.sdn_controller.ip, 0, 0);
559         }
560         else {
561             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-ip", (const char*)framework_environment.sdn_controller.ip, 0, 0);
562         }
563         if(rc != SR_ERR_OK) {
564             log_error("sr_set_item_str failed\n");
565             return NTS_ERR_FAILED;
566         }
567     }
568
569     sprintf(int_to_str, "%d", framework_environment.sdn_controller.port);
570     if(manager) {
571         rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-port", (const char*)int_to_str, 0, 0);
572     }
573     else {
574         rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-port", (const char*)int_to_str, 0, 0);
575     }
576     if(rc != SR_ERR_OK) {
577         log_error("sr_set_item_str failed\n");
578         return NTS_ERR_FAILED;
579     }
580
581     sprintf(int_to_str, "%d", framework_environment.sdn_controller.callhome_port);
582     if(manager) {
583         rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-netconf-call-home-port", (const char*)int_to_str, 0, 0);
584     }
585     else {
586         rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-netconf-call-home-port", (const char*)int_to_str, 0, 0);
587     }
588     if(rc != SR_ERR_OK) {
589         log_error("sr_set_item_str failed\n");
590         return NTS_ERR_FAILED;
591     }
592
593     if(strlen(framework_environment.sdn_controller.username)) {
594         if(manager) {
595             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-username", (const char*)framework_environment.sdn_controller.username, 0, 0);
596         }
597         else {
598             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-username", (const char*)framework_environment.sdn_controller.username, 0, 0);
599         }
600         if(rc != SR_ERR_OK) {
601             log_error("sr_set_item_str failed\n");
602             return NTS_ERR_FAILED;
603         }
604     }
605
606     if(strlen(framework_environment.sdn_controller.password)) {
607         if(manager) {
608             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-password", (const char*)framework_environment.sdn_controller.password, 0, 0);
609         }
610         else {
611             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-password", (const char*)framework_environment.sdn_controller.password, 0, 0);
612         }
613         if(rc != SR_ERR_OK) {
614             log_error("sr_set_item_str failed\n");
615             return NTS_ERR_FAILED;
616         }
617     }
618
619     //setup ves-endpoint details
620     if(strlen(framework_environment.ves_endpoint.protocol)) {
621         if(manager) {
622             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-protocol", (const char*)framework_environment.ves_endpoint.protocol, 0, 0);
623         }
624         else {
625             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-protocol", (const char*)framework_environment.ves_endpoint.protocol, 0, 0);
626         }
627         if(rc != SR_ERR_OK) {
628             log_error("sr_set_item_str failed\n");
629             return NTS_ERR_FAILED;
630         }
631     }
632
633     if(strlen(framework_environment.ves_endpoint.ip)) {
634         if(manager) {
635             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-ip", (const char*)framework_environment.ves_endpoint.ip, 0, 0);
636         }
637         else {
638             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-ip", (const char*)framework_environment.ves_endpoint.ip, 0, 0);
639         }
640         if(rc != SR_ERR_OK) {
641             log_error("sr_set_item_str failed\n");
642             return NTS_ERR_FAILED;
643         }
644     }
645
646     sprintf(int_to_str, "%d", framework_environment.ves_endpoint.port);
647     if(manager) {
648         rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-port", (const char*)int_to_str, 0, 0);
649     }
650     else {
651         rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-port", (const char*)int_to_str, 0, 0);
652     }
653     if(rc != SR_ERR_OK) {
654         log_error("sr_set_item_str failed\n");
655         return NTS_ERR_FAILED;
656     }
657
658     if(strlen(framework_environment.ves_endpoint.auth_method)) {
659         if(manager) {
660             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-auth-method", (const char*)framework_environment.ves_endpoint.auth_method, 0, 0);
661         }
662         else {
663             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-auth-method", (const char*)framework_environment.ves_endpoint.auth_method, 0, 0);
664         }
665         if(rc != SR_ERR_OK) {
666             log_error("sr_set_item_str failed\n");
667             return NTS_ERR_FAILED;
668         }
669     }
670
671     if(strlen(framework_environment.ves_endpoint.username)) {
672         if(manager) {
673             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-username", (const char*)framework_environment.ves_endpoint.username, 0, 0);
674         }
675         else {
676             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-username", (const char*)framework_environment.ves_endpoint.username, 0, 0);
677         }
678         if(rc != SR_ERR_OK) {
679             log_error("sr_set_item_str failed\n");
680             return NTS_ERR_FAILED;
681         }
682     }
683
684     if(strlen(framework_environment.ves_endpoint.password)) {
685         if(manager) {
686             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-password", (const char*)framework_environment.ves_endpoint.password, 0, 0);
687         }
688         else {
689             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-password", (const char*)framework_environment.ves_endpoint.password, 0, 0);
690         }
691         if(rc != SR_ERR_OK) {
692             log_error("sr_set_item_str failed\n");
693             return NTS_ERR_FAILED;
694         }
695     }
696
697     if(strlen(framework_environment.ves_endpoint.certificate)) {
698         if(manager) {
699             rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-certificate", (const char*)framework_environment.ves_endpoint.certificate, 0, 0);
700         }
701         else {
702             rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-certificate", (const char*)framework_environment.ves_endpoint.certificate, 0, 0);
703         }
704         if(rc != SR_ERR_OK) {
705             log_error("sr_set_item_str failed\n");
706             return NTS_ERR_FAILED;
707         }
708     }
709
710     if(manager == false) {
711         //presence containers
712         rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_FAULT_GENERATION_SCHEMA_XPATH, 0, 0, 0);
713         if(rc != SR_ERR_OK) {
714             log_error("sr_set_item_str failed\n");
715             return NTS_ERR_FAILED;
716         }
717
718         rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_NETCONF_SCHEMA_XPATH, 0, 0, 0);
719         if(rc != SR_ERR_OK) {
720             log_error("sr_set_item_str failed\n");
721             return NTS_ERR_FAILED;
722         }
723
724         rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_VES_SCHEMA_XPATH, 0, 0, 0);
725         if(rc != SR_ERR_OK) {
726             log_error("sr_set_item_str failed\n");
727             return NTS_ERR_FAILED;
728         }
729     }
730
731     //also set the network-function module for easy identifying the function type
732     rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH, function_type, 0, 0);
733     if(rc != SR_ERR_OK) {
734         log_error("sr_set_item_str failed\n");
735         return NTS_ERR_FAILED;
736     }
737
738     //mount-point-addressing-method
739     rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, "docker-mapping", 0, 0);
740     if(rc != SR_ERR_OK) {
741         log_error("sr_set_item_str failed\n");
742         return NTS_ERR_FAILED;
743     }
744
745     //apply all changes
746     rc = sr_apply_changes(current_session, 0, 0);
747     if(rc != SR_ERR_OK) {
748         log_error("sr_apply_changes failed: %s\n", sr_strerror(rc));
749         return NTS_ERR_FAILED;
750     }
751
752     return NTS_ERR_OK;
753 }