Refactor folder structure.
[sim/o1-interface.git] / ntsimulator / src / ntsimulator-manager / ntsimulator-manager.c
index 1e95497..e5312b1 100644 (file)
@@ -1,9 +1,19 @@
-/*
- * core-model.c
- *
- *  Created on: Feb 19, 2019
- *      Author: parallels
- */
+/*************************************************************************
+*
+* Copyright 2019 highstreet technologies GmbH and others
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+***************************************************************************/
 
 
 #include <stdio.h>
@@ -107,7 +117,7 @@ print_current_config(sr_session_ctx_t *session, const char *module_name)
    sr_free_val(odl_username);
    sr_free_val(odl_password);
 
-    sr_free_values(values, count);
+   sr_free_values(values, count);
 }
 
 static void clean_current_docker_configuration(void);
@@ -174,7 +184,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
     printf("\n\n ========== CONFIG HAS CHANGED, CURRENT RUNNING CONFIG %s: ==========\n\n", module_name);
     print_current_config(session, module_name);
 
-    sr_val_t *val;
+    sr_val_t *val = NULL;
 
     /* get the value from sysrepo, we do not care if the value did not change in our case */
     rc = sr_get_item(session, "/network-topology-simulator:simulator-config/simulated-devices", &val);
@@ -188,6 +198,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
     }
 
     sr_free_val(val);
+       val = NULL;
 
     /* get the value from sysrepo, we do not care if the value did not change in our case */
     rc = sr_get_item(session, "/network-topology-simulator:simulator-config/mounted-devices", &val);
@@ -201,6 +212,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        {
                printf("Cannot set mount value greater than number of simulated devices.\n");
                sr_free_val(val);
+                       val = NULL;
                return SR_ERR_OK;
        }
 
@@ -211,6 +223,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
     }
 
     sr_free_val(val);
+       val = NULL;
 
     /* get the value from sysrepo, we do not care if the value did not change in our case */
     rc = sr_get_item(session, "/network-topology-simulator:simulator-config/notification-config/fault-notification-delay-period", &val);
@@ -224,6 +237,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
     }
 
     sr_free_val(val);
+       val = NULL;
 
     /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/notification-config/ves-heartbeat-period", &val);
@@ -237,6 +251,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
        /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/ves-endpoint-details/ves-endpoint-ip", &val);
@@ -250,6 +265,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
        /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/ves-endpoint-details/ves-endpoint-port", &val);
@@ -263,6 +279,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
        /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/ves-endpoint-details/ves-registration", &val);
@@ -276,6 +293,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
        /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/notification-config/is-netconf-available", &val);
@@ -289,6 +307,7 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
        /* get the value from sysrepo, we do not care if the value did not change in our case */
        rc = sr_get_item(session, "/network-topology-simulator:simulator-config/notification-config/is-ves-available", &val);
@@ -302,11 +321,17 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
        }
 
        sr_free_val(val);
+       val = NULL;
 
     return SR_ERR_OK;
 
 sr_error:
        printf("NTSimulator config change callback failed: %s.", sr_strerror(rc));
+       if (val != NULL)
+       {
+               sr_free_val(val);
+               val = NULL;
+       }
        return rc;
 }
 
@@ -334,6 +359,7 @@ simulator_status_cb(const char *xpath, sr_val_t **values, size_t *values_cnt,
                if (rc != SR_ERR_OK)
                {
                        printf("Could not get the operational state for the devices simulated.\n");
+                       return SR_ERR_OPERATION_FAILED;
                }
 
                device_t *current_device = device_list->head;
@@ -435,7 +461,6 @@ int odl_add_key_pair_cb(const char *xpath, const sr_val_t *input, const size_t i
                sr_val_t **output, size_t *output_cnt, void *private_ctx)
 {
        int rc = SR_ERR_OK;
-    sr_session_ctx_t *session = (sr_session_ctx_t *)private_ctx;
        controller_t controller_list[CONTROLLER_LIST_MAX_LEN];
        int controller_list_size = 0;
 
@@ -451,6 +476,7 @@ int odl_add_key_pair_cb(const char *xpath, const sr_val_t *input, const size_t i
        if (rc != SR_ERR_OK)
        {
                printf("Failed to add key pair to ODL.\n");
+               return SR_ERR_OPERATION_FAILED;
        }
 
        return rc;