From: Alex Stancu Date: Thu, 9 Mar 2023 16:42:32 +0000 (+0200) Subject: Make cURL timeouts configurable. X-Git-Tag: 1.8.1~16 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=commitdiff_plain;h=32ee75567ef99fe24669b282297353eb1b6dd4f7 Make cURL timeouts configurable. Issue-ID: SIM-107 Change-Id: I25cca146e178afd1d45305b34fc9607d69b853b0 Signed-off-by: Alex Stancu --- diff --git a/ntsimulator/.env b/ntsimulator/.env index 638975b..21ded2a 100644 --- a/ntsimulator/.env +++ b/ntsimulator/.env @@ -30,3 +30,6 @@ VES_ENDPOINT_PORT=8443 VES_ENDPOINT_AUTH_METHOD=no-auth VES_ENDPOINT_USERNAME=sample1 VES_ENDPOINT_PASSWORD=sample1 + +CURL_CONNECT_TIMEOUT=1 +CURL_OPERATION_TIMEOUT=1 diff --git a/ntsimulator/docker-compose.yaml b/ntsimulator/docker-compose.yaml index e063030..cf15586 100644 --- a/ntsimulator/docker-compose.yaml +++ b/ntsimulator/docker-compose.yaml @@ -38,6 +38,9 @@ services: VES_ENDPOINT_USERNAME: ${VES_ENDPOINT_USERNAME} VES_ENDPOINT_PASSWORD: ${VES_ENDPOINT_PASSWORD} + CURL_CONNECT_TIMEOUT: ${CURL_CONNECT_TIMEOUT} + CURL_OPERATION_TIMEOUT: ${CURL_OPERATION_TIMEOUT} + ntsim-ng-o-ru: image: "${DOCKER_REPO}nts-ng-o-ran-ru-fh:${NTS_BUILD_VERSION}" cap_add: @@ -77,6 +80,9 @@ services: VES_ENDPOINT_USERNAME: ${VES_ENDPOINT_USERNAME} VES_ENDPOINT_PASSWORD: ${VES_ENDPOINT_PASSWORD} + CURL_CONNECT_TIMEOUT: ${CURL_CONNECT_TIMEOUT} + CURL_OPERATION_TIMEOUT: ${CURL_OPERATION_TIMEOUT} + ntsim-ng-o-du: image: "${DOCKER_REPO}nts-ng-o-ran-du:${NTS_BUILD_VERSION}" cap_add: @@ -116,6 +122,9 @@ services: VES_ENDPOINT_USERNAME: ${VES_ENDPOINT_USERNAME} VES_ENDPOINT_PASSWORD: ${VES_ENDPOINT_PASSWORD} + CURL_CONNECT_TIMEOUT: ${CURL_CONNECT_TIMEOUT} + CURL_OPERATION_TIMEOUT: ${CURL_OPERATION_TIMEOUT} + o-ran-sc-topology-service: image: "${DOCKER_REPO}o-ran-sc-topology-service:${NTS_BUILD_VERSION}" stop_grace_period: 5m @@ -130,4 +139,4 @@ services: networks: default: external: - name: smo_integration \ No newline at end of file + name: smo_integration diff --git a/ntsimulator/ntsim-ng/core/framework.h b/ntsimulator/ntsim-ng/core/framework.h index 21ea844..d5a93e7 100644 --- a/ntsimulator/ntsim-ng/core/framework.h +++ b/ntsimulator/ntsim-ng/core/framework.h @@ -82,7 +82,7 @@ typedef struct { bool no_rand; unsigned int fixed_seed; int verbosity_level; - + bool print_root_paths; char *print_structure_xpath; } framework_arguments_t; @@ -205,7 +205,7 @@ typedef struct { int preg_running_count; char **preg_running; - } datastore_populate; + } datastore_populate; } framework_config_t; extern framework_arguments_t framework_arguments; diff --git a/ntsimulator/ntsim-ng/utils/http_client.c b/ntsimulator/ntsim-ng/utils/http_client.c index dd15a6d..bc01d4f 100644 --- a/ntsimulator/ntsim-ng/utils/http_client.c +++ b/ntsimulator/ntsim-ng/utils/http_client.c @@ -33,7 +33,7 @@ struct memory { }; static size_t curl_write_cb(void *data, size_t size, size_t nmemb, void *userp); - + int http_request(const char *url, const char *username, const char* password, const char *method, const char *send_data, int *response_code, char **recv_data) { assert(url); assert(method); @@ -65,10 +65,13 @@ int http_request(const char *url, const char *username, const char* password, co return NTS_ERR_FAILED; } + int curl_connect_timeout = get_int_from_string_with_default(getenv("CURL_CONNECT_TIMEOUT"), 1); + int curl_operation_timeout = get_int_from_string_with_default(getenv("CURL_OPERATION_TIMEOUT"), 1); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L); //seconds timeout for a connection - curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L); //seconds timeout for an operation - curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, (long)curl_connect_timeout); //seconds timeout for a connection + curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)curl_operation_timeout); //seconds timeout for an operation + curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, (long)curl_connect_timeout); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); // disable SSL verifications @@ -99,7 +102,7 @@ int http_request(const char *url, const char *username, const char* password, co curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_cb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response_data); } - + log_add_verbose(2, "%s-ing cURL to url=\"%s\" with body=\"%s\"... ", method, url, send_data_good); CURLcode res = curl_easy_perform(curl); curl_slist_free_all(header); @@ -175,7 +178,7 @@ int http_socket_request(const char *url, const char *sock_fname, const char *met curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_cb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response_data); } - + log_add_verbose(2, "%s-ing cURL to url=\"%s\" with body=\"%s\"\n", method, url, send_data_good); CURLcode res = curl_easy_perform(curl); curl_slist_free_all(header);