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