Allow multiple NTS Manager instances to run on the same machine.
[sim/o1-interface.git] / ntsimulator / src / ntsimulator-manager / simulator-operations.c
index 872513a..a4adcc3 100644 (file)
@@ -1,9 +1,19 @@
-/*
- * simulator-operations.c
- *
- *  Created on: Mar 9, 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 "simulator-operations.h"
 #include "sysrepo.h"
@@ -82,8 +92,8 @@ static cJSON* get_docker_container_bindings(void)
        curl_easy_reset(curl);
        set_curl_common_info();
 
-       char url[100];
-       sprintf(url, "http:/v%s/containers/NTS_Manager/json", getenv("DOCKER_ENGINE_VERSION"));
+       char url[200];
+       sprintf(url, "http:/v%s/containers/%s/json", getenv("DOCKER_ENGINE_VERSION"), getenv("HOSTNAME"));
 
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
@@ -243,6 +253,12 @@ static char* create_docker_container_curl(int base_netconf_port, cJSON* managerB
        return NULL;
     }
 
+       if (cJSON_AddStringToObject(labels, "NTS_Manager", getenv("HOSTNAME")) == NULL)
+    {
+       printf("Could not create JSON object: NTS Manager\n");
+       return NULL;
+    }
+
     cJSON *env_variables_array = cJSON_CreateArray();
     if (env_variables_array == NULL)
        {
@@ -418,7 +434,7 @@ static int send_mount_device_instance_ssh(char *url, char *credentials, char *de
 
        curl_easy_setopt(curl_odl, CURLOPT_URL, url_for_curl);
 
-       char post_data_xml[1000];
+       char post_data_xml[1500];
 
        sprintf(post_data_xml,
                        "<node xmlns=\"urn:TBD:params:xml:ns:yang:network-topology\">"
@@ -429,6 +445,11 @@ static int send_mount_device_instance_ssh(char *url, char *credentials, char *de
                        "<password xmlns=\"urn:opendaylight:netconf-node-topology\">%s</password>"
                        "<tcp-only xmlns=\"urn:opendaylight:netconf-node-topology\">false</tcp-only>"
                        "<keepalive-delay xmlns=\"urn:opendaylight:netconf-node-topology\">120</keepalive-delay>"
+                       "<reconnect-on-changed-schema xmlns=\"urn:opendaylight:netconf-node-topology\">false</reconnect-on-changed-schema>"
+                       "<sleep-factor xmlns=\"urn:opendaylight:netconf-node-topology\">1.5</sleep-factor>"
+                       "<connection-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">20000</connection-timeout-millis>"
+                       "<max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">100</max-connection-attempts>"
+                       "<between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>"
                        "</node>",
                        device_name, device_port, getenv("NTS_IP"), device_port, "netconf", "netconf");
 
@@ -471,7 +492,7 @@ static int send_mount_device_instance_tls(char *url, char *credentials, char *de
 
        curl_easy_setopt(curl_odl, CURLOPT_URL, url_for_curl);
 
-       char post_data_xml[1000];
+       char post_data_xml[1500];
 
        sprintf(post_data_xml,
                        "<node xmlns=\"urn:TBD:params:xml:ns:yang:network-topology\">"
@@ -487,6 +508,11 @@ static int send_mount_device_instance_tls(char *url, char *credentials, char *de
                        "<port xmlns=\"urn:opendaylight:netconf-node-topology\">%d</port>"
                        "<tcp-only xmlns=\"urn:opendaylight:netconf-node-topology\">false</tcp-only>"
                        "<keepalive-delay xmlns=\"urn:opendaylight:netconf-node-topology\">120</keepalive-delay>"
+                       "<reconnect-on-changed-schema xmlns=\"urn:opendaylight:netconf-node-topology\">false</reconnect-on-changed-schema>"
+                       "<sleep-factor xmlns=\"urn:opendaylight:netconf-node-topology\">1.5</sleep-factor>"
+                       "<connection-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">20000</connection-timeout-millis>"
+                       "<max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">100</max-connection-attempts>"
+                       "<between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>"
                        "</node>",
                        device_name, device_port, getenv("NTS_IP"), "netconf", device_port);