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