Add SDN Controller and VES Collector addressing via a hostname instead of an IP.
[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_port = 0;
394     ret->auth_method = 0;
395     ret->username = 0;
396     ret->password = 0;
397
398     ret->auth_method = strdup("basic");
399
400     struct lyd_node *chd = 0;
401     LY_TREE_FOR(data->child, chd) {
402         const char *val = ((const struct lyd_node_leaf_list *)chd)->value_str;
403
404         if(strcmp(chd->schema->name, "controller-protocol") == 0) {
405             ret->protocol = strdup(val);
406         }
407         else if(strcmp(chd->schema->name, "controller-ip") == 0) {
408             ret->ip = strdup(val);
409         }
410         else if(strcmp(chd->schema->name, "controller-port") == 0) {
411             ret->port = ((const struct lyd_node_leaf_list *)chd)->value.uint16;
412         }
413         else if(strcmp(chd->schema->name, "controller-netconf-call-home-port") == 0) {
414             ret->nc_callhome_port = ((const struct lyd_node_leaf_list *)chd)->value.uint16;
415         }
416         else if(strcmp(chd->schema->name, "controller-username") == 0) {
417             ret->username = strdup(val);
418         }
419         else if(strcmp(chd->schema->name, "controller-password") == 0) {
420             ret->password = strdup(val);
421         }
422     }
423     lyd_free(data);
424
425     if (strstr(ret->ip, ":")) {
426         // IPv6 address
427         asprintf(&ret->base_url, "%s://[%s]:%d", ret->protocol, ret->ip, ret->port);
428     }
429     else {
430         if (framework_environment.sdn_controller.port_absent == true) {
431             // hostname without port addressing
432             asprintf(&ret->base_url, "%s://%s", ret->protocol, ret->ip);
433         }
434         else {
435             // normal IP and Port addressing
436             asprintf(&ret->base_url, "%s://%s:%d", ret->protocol, ret->ip, ret->port);
437         }
438     }
439
440     if((ret->protocol == 0) || (ret->ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->base_url == 0)) {
441         free(ret->protocol);
442         free(ret->ip);
443         free(ret->auth_method);
444         free(ret->username);
445         free(ret->password);
446         free(ret->base_url);
447         free(ret);
448         ret = 0;
449     }
450
451     return ret;
452 }
453
454 void controller_details_free(controller_details_t *instance) {
455     assert(instance);
456
457     free(instance->protocol);
458     free(instance->ip);
459     free(instance->base_url);
460     free(instance->auth_method);
461     free(instance->username);
462     free(instance->password);
463     free(instance);
464 }
465
466 int nts_vercmp(const char *ver1, const char *ver2) {
467     assert(ver1);
468     assert(ver2);
469
470     int i = 0;
471     int v1 = 0, v2 = 0, v3 = 0;
472     while(ver1[i] && (ver1[i] != '.')) {
473         v1 *= 10;
474         v1 += ver1[i] - '0';
475         i++;
476     }
477
478     if(ver1[i]) {
479         i++;
480         while(ver1[i] && (ver1[i] != '.')) {
481             v2 *= 10;
482             v2 += ver1[i] - '0';
483             i++;
484         }
485
486         if(ver1[i]) {
487             i++;
488             while(ver1[i] && (ver1[i] != '.')) {
489                 v3 *= 10;
490                 v3 += ver1[i] - '0';
491                 i++;
492             }
493         }
494     }
495
496
497     int V1 = 0, V2 = 0, V3 = 0;
498     i = 0;
499     while(ver2[i] && (ver2[i] != '.')) {
500         V1 *= 10;
501         V1 += ver2[i] - '0';
502         i++;
503     }
504
505     if(ver2[i]) {
506         i++;
507         while(ver2[i] && (ver2[i] != '.')) {
508             V2 *= 10;
509             V2 += ver2[i] - '0';
510             i++;
511         }
512
513         if(ver2[i]) {
514             i++;
515             while(ver2[i] && (ver2[i] != '.')) {
516                 V3 *= 10;
517                 V3 += ver2[i] - '0';
518                 i++;
519             }
520         }
521     }
522
523     if(v1 < V1) {
524         return -1;
525     }
526     else if(v1 > V1) {
527         return 1;
528     }
529
530     if(v2 < V2) {
531         return -1;
532     }
533     else if(v2 > V2) {
534         return 1;
535     }
536
537     if(v3 < V3) {
538         return -1;
539     }
540     else if(v3 > V3) {
541         return 1;
542     }
543
544     return 0;
545 }
546
547 int nts_utils_populate_info(sr_session_ctx_t *current_session, const char *function_type) {
548     assert(current_session);
549     assert(function_type);
550
551     bool manager = (strcmp(function_type, "NTS_FUNCTION_TYPE_MANAGER") == 0);
552
553     int rc;
554     char int_to_str[30];
555     //setup sdn-controller defaults
556     if(strlen(framework_environment.sdn_controller.protocol)) {
557         if(manager) {
558             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-protocol", (const char*)framework_environment.sdn_controller.protocol, 0, 0);
559         }
560         else {
561             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-protocol", (const char*)framework_environment.sdn_controller.protocol, 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     if(strlen(framework_environment.sdn_controller.ip)) {
570         if(manager) {
571             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-ip", (const char*)framework_environment.sdn_controller.ip, 0, 0);
572         }
573         else {
574             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-ip", (const char*)framework_environment.sdn_controller.ip, 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
582     sprintf(int_to_str, "%d", framework_environment.sdn_controller.port);
583     if(manager) {
584         rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-port", (const char*)int_to_str, 0, 0);
585     }
586     else {
587         rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-port", (const char*)int_to_str, 0, 0);
588     }
589     if(rc != SR_ERR_OK) {
590         log_error("sr_set_item_str failed\n");
591         return NTS_ERR_FAILED;
592     }
593
594     sprintf(int_to_str, "%d", framework_environment.sdn_controller.callhome_port);
595     if(manager) {
596         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);
597     }
598     else {
599         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);
600     }
601     if(rc != SR_ERR_OK) {
602         log_error("sr_set_item_str failed\n");
603         return NTS_ERR_FAILED;
604     }
605
606     if(strlen(framework_environment.sdn_controller.username)) {
607         if(manager) {
608             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-username", (const char*)framework_environment.sdn_controller.username, 0, 0);
609         }
610         else {
611             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-username", (const char*)framework_environment.sdn_controller.username, 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     if(strlen(framework_environment.sdn_controller.password)) {
620         if(manager) {
621             rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-password", (const char*)framework_environment.sdn_controller.password, 0, 0);
622         }
623         else {
624             rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-password", (const char*)framework_environment.sdn_controller.password, 0, 0);
625         }
626         if(rc != SR_ERR_OK) {
627             log_error("sr_set_item_str failed\n");
628             return NTS_ERR_FAILED;
629         }
630     }
631
632     //setup ves-endpoint details
633     if(strlen(framework_environment.ves_endpoint.protocol)) {
634         if(manager) {
635             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);
636         }
637         else {
638             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);
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     if(strlen(framework_environment.ves_endpoint.ip)) {
647         if(manager) {
648             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);
649         }
650         else {
651             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);
652         }
653         if(rc != SR_ERR_OK) {
654             log_error("sr_set_item_str failed\n");
655             return NTS_ERR_FAILED;
656         }
657     }
658
659     sprintf(int_to_str, "%d", framework_environment.ves_endpoint.port);
660     if(manager) {
661         rc = sr_set_item_str(current_session, NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-port", (const char*)int_to_str, 0, 0);
662     }
663     else {
664         rc = sr_set_item_str(current_session, NTS_NF_VES_ENDPOINT_CONFIG_XPATH"/ves-endpoint-port", (const char*)int_to_str, 0, 0);
665     }
666     if(rc != SR_ERR_OK) {
667         log_error("sr_set_item_str failed\n");
668         return NTS_ERR_FAILED;
669     }
670
671     if(strlen(framework_environment.ves_endpoint.auth_method)) {
672         if(manager) {
673             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);
674         }
675         else {
676             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);
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.username)) {
685         if(manager) {
686             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);
687         }
688         else {
689             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);
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.password)) {
698         if(manager) {
699             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);
700         }
701         else {
702             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);
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(strlen(framework_environment.ves_endpoint.certificate)) {
711         if(manager) {
712             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);
713         }
714         else {
715             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);
716         }
717         if(rc != SR_ERR_OK) {
718             log_error("sr_set_item_str failed\n");
719             return NTS_ERR_FAILED;
720         }
721     }
722
723     if(manager == false) {
724         //presence containers
725         rc = sr_set_item_str(current_session, NTS_NF_FAULT_GENERATION_SCHEMA_XPATH, 0, 0, 0);
726         if(rc != SR_ERR_OK) {
727             log_error("sr_set_item_str failed\n");
728             return NTS_ERR_FAILED;
729         }
730
731         rc = sr_set_item_str(current_session, NTS_NF_NETCONF_SCHEMA_XPATH, 0, 0, 0);
732         if(rc != SR_ERR_OK) {
733             log_error("sr_set_item_str failed\n");
734             return NTS_ERR_FAILED;
735         }
736
737         rc = sr_set_item_str(current_session, NTS_NF_VES_SCHEMA_XPATH, 0, 0, 0);
738         if(rc != SR_ERR_OK) {
739             log_error("sr_set_item_str failed\n");
740             return NTS_ERR_FAILED;
741         }
742     }
743
744     //also set the network-function module for easy identifying the function type
745     rc = sr_set_item_str(current_session, NTS_NF_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH, function_type, 0, 0);
746     if(rc != SR_ERR_OK) {
747         log_error("sr_set_item_str failed\n");
748         return NTS_ERR_FAILED;
749     }
750
751     //mount-point-addressing-method
752     rc = sr_set_item_str(current_session, NTS_NF_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, framework_environment.nts.nf_mount_point_addressing_method, 0, 0);
753     if(rc != SR_ERR_OK) {
754         log_error("sr_set_item_str failed\n");
755         return NTS_ERR_FAILED;
756     }
757
758     //apply all changes
759     rc = sr_apply_changes(current_session, 0, 0);
760     if(rc != SR_ERR_OK) {
761         log_error("sr_apply_changes failed: %s\n", sr_strerror(rc));
762         return NTS_ERR_FAILED;
763     }
764
765     return NTS_ERR_OK;
766 }