Allign autogenerated device name device creation by VES and for RestConf requests
Issue-ID: SIM-63
Change-Id: Ie39348008bcf077ab81e10b0101f1b314a7dd657
Signed-off-by: Alex Stancu <alexandru.stancu@highstreet-technologies.com>
DOCKER_REPO=o-ran-sc/
NTS_MANAGER_PORT=8300
-NTS_BUILD_VERSION=1.2.0
+NTS_BUILD_VERSION=1.2.1
IPv6_ENABLED=true
SSH_CONNECTIONS=1
---
-tag: 1.2.0
\ No newline at end of file
+tag: 1.2.1
\ No newline at end of file
---
-tag: 1.2.0
\ No newline at end of file
+tag: 1.2.1
\ No newline at end of file
---
-tag: 1.2.0
\ No newline at end of file
+tag: 1.2.1
\ No newline at end of file
---
-tag: 1.2.0
\ No newline at end of file
+tag: 1.2.1
\ No newline at end of file
---
-tag: 1.2.0
\ No newline at end of file
+tag: 1.2.1
\ No newline at end of file
protocol = "SSH";
protocol_data = "\
\"network-topology:netconf-node-topology:username\": \"netconf\",\
- \"network-topology:netconf-node-topology:password\": \"netconf\"";
+ \"network-topology:netconf-node-topology:password\": \"netconf!\"";
if(instance->mount_point_addressing_method[0] == 'd') {
port = instance->container.docker_netconf_ssh_port + i;
char node_id[128];
char json[4096];
- sprintf(node_id, "%s-%d", instance->container.name, port);
+ if(framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections > 1) {
+ sprintf(node_id, "%s-%d", instance->container.name, port);
+ }
+ else {
+ sprintf(node_id, "%s", instance->container.name);
+ }
sprintf(json, json_template, node_id, ip, port, protocol, protocol_data);
char url[512];
}
}
char node_id[128];
- sprintf(node_id, "%s-%d", instance->container.name, port);
+ if(framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections > 1) {
+ sprintf(node_id, "%s-%d", instance->container.name, port);
+ }
+ else {
+ sprintf(node_id, "%s", instance->container.name);
+ }
char url[512];
sprintf(url, "%s/rests/data/network-topology:network-topology/topology=topology-netconf/node=%s", controller->base_url, node_id);
container->docker_ip = 0;
container->docker_netconf_ssh_port = STANDARD_NETCONF_PORT;
container->docker_netconf_tls_port = container->docker_netconf_ssh_port + framework_environment.settings.ssh_connections;
+ if(framework_environment.settings.ssh_connections == 0) {
+ container->docker_netconf_ssh_port = 0;
+ }
+ if(framework_environment.settings.tls_connections == 0) {
+ container->docker_netconf_tls_port = 0;
+ }
container->docker_ftp_port= STANDARD_FTP_PORT;
container->docker_sftp_port= STANDARD_SFTP_PORT;
#include "faults.h"
#include "utils/log_utils.h"
#include "utils/sys_utils.h"
+#include "core/framework.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
uint32_counter++;
return ret;
}
+ else if(strcmp(function, "$$hostname$$") == 0) {
+ char *ret = 0;
+ asprintf(&ret, "%s", framework_environment.settings.hostname);
+ return ret;
+ }
return 0;
}
tls_base_port = framework_environment.host.tls_base_port;
}
- for(int port = ssh_base_port; port < ssh_base_port + framework_environment.settings.ssh_connections; port++) {
- uint32_t *seq_id = &fault_ves_sequence_number[sequence_index++];
- int rc = ves_message_send_internal(session, condition, object, severity, date_time, specific_problem, port, seq_id);
- if(rc != NTS_ERR_OK) {
- log_error("ves_message_send_internal failed\n");
+ if((framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections) > 1) {
+ for(int port = ssh_base_port; port < ssh_base_port + framework_environment.settings.ssh_connections; port++) {
+ uint32_t *seq_id = &fault_ves_sequence_number[sequence_index++];
+ int rc = ves_message_send_internal(session, condition, object, severity, date_time, specific_problem, port, seq_id);
+ if(rc != NTS_ERR_OK) {
+ log_error("ves_message_send_internal failed\n");
+ }
}
- }
- for(int port = tls_base_port; port < tls_base_port + framework_environment.settings.tls_connections; port++) {
+ for(int port = tls_base_port; port < tls_base_port + framework_environment.settings.tls_connections; port++) {
+ uint32_t *seq_id = &fault_ves_sequence_number[sequence_index++];
+ int rc = ves_message_send_internal(session, condition, object, severity, date_time, specific_problem, port, seq_id);
+ if(rc != NTS_ERR_OK) {
+ log_error("ves_message_send_internal failed\n");
+ }
+ }
+ }
+ else {
uint32_t *seq_id = &fault_ves_sequence_number[sequence_index++];
- int rc = ves_message_send_internal(session, condition, object, severity, date_time, specific_problem, port, seq_id);
+ int rc = ves_message_send_internal(session, condition, object, severity, date_time, specific_problem, 0, seq_id);
if(rc != NTS_ERR_OK) {
log_error("ves_message_send_internal failed\n");
}
}
cJSON_AddItemToObject(post_data_json, "event", event);
- char *source_name = 0;
- if (framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections == 1) {
- // we don't want to append the port to the source name if we only expose one port
- asprintf(&source_name, "%s", hostname_string);
- }
- else {
- asprintf(&source_name, "%s_%d", hostname_string, port);
- }
- cJSON *common_event_header = ves_create_common_event_header("fault", "O_RAN_COMPONENT_Alarms", source_name, "Low", (*seq_id)++);
- free(source_name);
-
+ cJSON *common_event_header = ves_create_common_event_header("fault", "O_RAN_COMPONENT_Alarms", hostname_string, port, "Low", (*seq_id)++);
if(common_event_header == 0) {
log_error("ves_create_common_event_header failed\n");
cJSON_Delete(post_data_json);
}
log_add_verbose(2, "[framework-env] host.ip = %s\n", framework_environment.host.ip);
+ if(framework_environment.settings.ip_v6_enabled) {
+ if(strstr(framework_environment.host.ip, ".")) {
+ log_error("[framework-env] host.ip is an invalid IP v6\n");
+ }
+ }
+ else {
+ if(strstr(framework_environment.host.ip, ":")) {
+ log_error("[framework-env] host.ip is an invalid IP v4\n");
+ }
+ }
+
log_add_verbose(2, "[framework-env] host.base_port = %d\n", framework_environment.host.base_port);
log_add_verbose(2, "[framework-env] host.ssh_base_port = %d\n", framework_environment.host.ssh_base_port);
log_add_verbose(2, "[framework-env] host.tls_base_port = %d\n", framework_environment.host.tls_base_port);
}
else {
// if value is not set yet, feature enable means we want to start call-home
- callhome_enabled = true;
+ if(strlen(framework_environment.nts.nf_standalone_start_features)) {
+ callhome_enabled = true;
+ }
}
if(callhome_enabled == false) {
#define FILE_READY_RPC_SCHEMA_XPATH "/nts-network-function:invoke-ves-pm-file-ready"
static int ves_file_ready_invoke_pm_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data);
-static int ves_file_ready_send_message(sr_session_ctx_t *session, const char *file_location);
+static int ves_file_ready_send_message(sr_session_ctx_t *session, const char *file_location, int port);
static cJSON* ves_create_file_ready_fields(const char* file_location);
static void ves_file_ready_vsftp_daemon_init(void);
static void ves_file_ready_vsftp_daemon_deinit(void);
}
static int ves_file_ready_invoke_pm_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) {
- int rc;
+ int ssh_base_port = 0;
+ int tls_base_port = 0;
+ nts_mount_point_addressing_method_t mp = nts_mount_point_addressing_method_get(session);
+ if(mp == UNKNOWN_MAPPING) {
+ log_error("mount-point-addressing-method failed\n");
+ return NTS_ERR_FAILED;
+ }
+ else if(mp == DOCKER_MAPPING) {
+ ssh_base_port = STANDARD_NETCONF_PORT;
+ tls_base_port = ssh_base_port + framework_environment.settings.ssh_connections;
+ }
+ else {
+ ssh_base_port = framework_environment.host.ssh_base_port;
+ tls_base_port = framework_environment.host.tls_base_port;
+ }
+
+ int failed = 0;
+
+ if((framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections) > 1) {
+ for(int port = ssh_base_port; port < ssh_base_port + framework_environment.settings.ssh_connections; port++) {
+ int rc = ves_file_ready_send_message(session, input[0].data.string_val, port);
+ if(rc != NTS_ERR_OK) {
+ log_error("ves_file_ready_send_message failed\n");
+ failed++;
+ }
+ }
+
+ for(int port = tls_base_port; port < tls_base_port + framework_environment.settings.tls_connections; port++) {
+ int rc = ves_file_ready_send_message(session, input[0].data.string_val, port);
+ if(rc != NTS_ERR_OK) {
+ log_error("ves_file_ready_send_message failed\n");
+ failed++;
+ }
+ }
+ }
+ else {
+ int rc = ves_file_ready_send_message(session, input[0].data.string_val, 0);
+ if(rc != NTS_ERR_OK) {
+ log_error("ves_file_ready_send_message failed\n");
+ failed++;
+ }
+ }
+
*output_cnt = 1;
- rc = sr_new_values(*output_cnt, output);
+ int rc = sr_new_values(*output_cnt, output);
if(SR_ERR_OK != rc) {
return rc;
}
if(SR_ERR_OK != rc) {
return rc;
}
-
- rc = ves_file_ready_send_message(session, input[0].data.string_val);
- if(rc != NTS_ERR_OK) {
+
+ if(failed != 0) {
rc = sr_val_build_str_data(output[0], SR_ENUM_T, "%s", "ERROR");
}
else {
return rc;
}
-static int ves_file_ready_send_message(sr_session_ctx_t *session, const char *file_location) {
+static int ves_file_ready_send_message(sr_session_ctx_t *session, const char *file_location, int port) {
assert(session);
assert(file_location);
return NTS_ERR_FAILED;
}
- char *hostname_string = framework_environment.settings.hostname;
- cJSON *common_event_header = ves_create_common_event_header("notification", "Notification-gnb_Nokia-FileReady", hostname_string, "Normal", sequence_number++);
+ cJSON *common_event_header = ves_create_common_event_header("notification", "Notification-gnb_Nokia-FileReady", framework_environment.settings.hostname, port, "Normal", sequence_number++);
if(common_event_header == 0) {
log_error("could not create cJSON object\n");
cJSON_Delete(post_data_json);
static int ves_heartbeat_period_get(void);
static void ves_heartbeat_period_set(int new_period);
-static int ves_heartbeat_send_ves_message(void);
+static int ves_heartbeat_send_ves_message(int port);
static void *ves_heartbeat_thread_routine(void *arg);
static cJSON* ves_create_heartbeat_fields(int heartbeat_period);
static int heartbeat_change_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, uint32_t request_id, void *private_data);
pthread_mutex_unlock(&ves_heartbeat_lock);
}
-static int ves_heartbeat_send_ves_message(void) {
+static int ves_heartbeat_send_ves_message(int port) {
char *hostname_string = framework_environment.settings.hostname;
cJSON *post_data_json = cJSON_CreateObject();
if(post_data_json == 0) {
return NTS_ERR_FAILED;
}
- cJSON *common_event_header = ves_create_common_event_header("heartbeat", "Controller", hostname_string, "Low", ves_sequence_number++);
+ cJSON *common_event_header = ves_create_common_event_header("heartbeat", "Controller", hostname_string, port, "Low", ves_sequence_number++);
if(common_event_header == 0) {
log_error("ves_create_common_event_header failed\n");
cJSON_Delete(post_data_json);
}
static void *ves_heartbeat_thread_routine(void *arg) {
+ assert_session();
+
int current_heartbeat_period = 0;
unsigned int timer_counter = 0;
+ int ssh_base_port = 0;
+ int tls_base_port = 0;
+ nts_mount_point_addressing_method_t mp = nts_mount_point_addressing_method_get(0);
+ if(mp == UNKNOWN_MAPPING) {
+ log_error("mount-point-addressing-method failed, assuming DOCKER_MAPPING\n");
+ mp = DOCKER_MAPPING;
+ ssh_base_port = STANDARD_NETCONF_PORT;
+ tls_base_port = ssh_base_port + framework_environment.settings.ssh_connections;
+ }
+ else if(mp == DOCKER_MAPPING) {
+ ssh_base_port = STANDARD_NETCONF_PORT;
+ tls_base_port = ssh_base_port + framework_environment.settings.ssh_connections;
+ }
+ else {
+ ssh_base_port = framework_environment.host.ssh_base_port;
+ tls_base_port = framework_environment.host.tls_base_port;
+ }
+
+
while((!framework_sigint) && (!ves_heartbeat_stopsig)) {
current_heartbeat_period = ves_heartbeat_period_get();
timer_counter++;
if((timer_counter >= current_heartbeat_period) && (current_heartbeat_period > 0)) {
timer_counter = 0;
- int rc = ves_heartbeat_send_ves_message();
- if(rc != NTS_ERR_FAILED) {
- log_error("could not send VES heartbeat\n");
+ if((framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections) > 1) {
+ for(int port = ssh_base_port; port < ssh_base_port + framework_environment.settings.ssh_connections; port++) {
+ int rc = ves_heartbeat_send_ves_message(port);
+ if(rc != NTS_ERR_FAILED) {
+ log_error("could not send VES heartbeat\n");
+ }
+ }
+
+ for(int port = tls_base_port; port < tls_base_port + framework_environment.settings.tls_connections; port++) {
+ int rc = ves_heartbeat_send_ves_message(port);
+ if(rc != NTS_ERR_FAILED) {
+ log_error("could not send VES heartbeat\n");
+ }
+ }
+ }
+ else {
+ int rc = ves_heartbeat_send_ves_message(0);
+ if(rc != NTS_ERR_FAILED) {
+ log_error("could not send VES heartbeat\n");
+ }
}
+
}
sleep(1);
static int ves_pnf_sequence_number = 0;
-static int ves_pnf_registration_send(sr_session_ctx_t *current_session, const char *nf_ip_v4_address, const char *nf_ip_v6_address, int nf_port, bool is_tls);
+static int ves_pnf_registration_send(sr_session_ctx_t *current_session, const char *nf_ip_v4_address, const char *nf_ip_v6_address, int nf_port, nts_mount_point_addressing_method_t mp, bool is_tls);
static cJSON* ves_create_pnf_registration_fields(const char *nf_ip_v4_address, const char *nf_ip_v6_address, int nf_port, bool is_tls);
static int ves_pnf_registration_status = 0;
}
else {
// if value is not set yet, feature enable means we want to start pnf-registration
- pnf_registration_enabled = true;
+ if(strlen(framework_environment.nts.nf_standalone_start_features)) {
+ pnf_registration_enabled = true;
+ }
}
if(pnf_registration_enabled == false) {
return NTS_ERR_OK;
}
+ int ssh_base_port = 0;
+ int tls_base_port = 0;
char nf_ip_v4_address[128];
char nf_ip_v6_address[128];
- int nf_ssh_port;
- int nf_tls_port;
+ nf_ip_v4_address[0] = 0;
+ nf_ip_v6_address[0] = 0;
+
nts_mount_point_addressing_method_t mp = nts_mount_point_addressing_method_get(current_session);
if(mp == UNKNOWN_MAPPING) {
log_error("mount-point-addressing-method failed\n");
if (framework_environment.settings.ip_v6) {
strcpy(nf_ip_v6_address, framework_environment.settings.ip_v6);
}
- nf_ssh_port = STANDARD_NETCONF_PORT;
- nf_tls_port = nf_ssh_port + framework_environment.settings.ssh_connections;
+
+ ssh_base_port = STANDARD_NETCONF_PORT;
+ tls_base_port = ssh_base_port + framework_environment.settings.ssh_connections;
}
else {
- if (framework_environment.settings.ip_v6_enabled) {
+ if(framework_environment.settings.ip_v6_enabled) {
strcpy(nf_ip_v6_address, framework_environment.host.ip);
}
else {
strcpy(nf_ip_v4_address, framework_environment.host.ip);
}
- nf_ssh_port = framework_environment.host.ssh_base_port;
- nf_tls_port = framework_environment.host.tls_base_port;
+
+ ssh_base_port = framework_environment.host.ssh_base_port;
+ tls_base_port = framework_environment.host.tls_base_port;
}
- for(int i = 0; i < framework_environment.settings.ssh_connections; i++) {
- rc = ves_pnf_registration_send(current_session, nf_ip_v4_address, nf_ip_v6_address, nf_ssh_port + i, false);
- if(rc != NTS_ERR_OK) {
- log_error("could not send pnfRegistration message for IPv4=%s and IPv6=%s and port=%d and protocol SSH\n", nf_ip_v4_address, nf_ip_v6_address, nf_ssh_port + i);
- continue;
+ if((framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections) > 1) {
+ for(int port = ssh_base_port; port < ssh_base_port + framework_environment.settings.ssh_connections; port++) {
+ int rc = ves_pnf_registration_send(current_session, nf_ip_v4_address, nf_ip_v6_address, port, mp, false);
+ if(rc != NTS_ERR_OK) {
+ log_error("could not send pnfRegistration message for IPv4=%s and IPv6=%s and port=%d and protocol SSH\n", nf_ip_v4_address, nf_ip_v6_address, port);
+ }
+ }
+
+ for(int port = tls_base_port; port < tls_base_port + framework_environment.settings.tls_connections; port++) {
+ int rc = ves_pnf_registration_send(current_session, nf_ip_v4_address, nf_ip_v6_address, port, mp, true);
+ if(rc != NTS_ERR_OK) {
+ log_error("could not send pnfRegistration message for IPv4=%s and IPv6=%s and port=%d and protocol TLS\n", nf_ip_v4_address, nf_ip_v6_address, port);
+ }
}
}
+ else {
+ bool tls;
+ int port;
+ if(framework_environment.settings.tls_connections == 0) {
+ tls = false;
+ port = ssh_base_port;
+ }
+ else {
+ tls = true;
+ port = tls_base_port;
+ }
- for(int i = 0; i < framework_environment.settings.tls_connections; i++) {
- rc = ves_pnf_registration_send(current_session, nf_ip_v4_address, nf_ip_v6_address, nf_tls_port + i, true);
+ int rc = ves_pnf_registration_send(current_session, nf_ip_v4_address, nf_ip_v6_address, 0, mp, tls);
if(rc != NTS_ERR_OK) {
- log_error("could not send pnfRegistration message for IPv4=%s and IPv6=%s and port=%d and protocol TLS\n", nf_ip_v4_address, nf_ip_v6_address, nf_tls_port + i);
- continue;
+ log_error("could not send pnfRegistration message for IPv4=%s and IPv6=%s\n", nf_ip_v4_address, nf_ip_v6_address, port);
}
}
return NTS_ERR_OK;
}
-
-static int ves_pnf_registration_send(sr_session_ctx_t *current_session, const char *nf_ip_v4_address, const char *nf_ip_v6_address, int nf_port, bool is_tls) {
+static int ves_pnf_registration_send(sr_session_ctx_t *current_session, const char *nf_ip_v4_address, const char *nf_ip_v6_address, int nf_port, nts_mount_point_addressing_method_t mp, bool is_tls) {
assert(current_session);
cJSON *post_data_json = cJSON_CreateObject();
}
char *hostname_string = framework_environment.settings.hostname;
- char source_name[100];
-
- if (framework_environment.settings.ssh_connections + framework_environment.settings.tls_connections == 1) {
- // we don't want to append the port to the mountpoint name if we only expose one port
- sprintf(source_name, "%s", hostname_string);
- }
- else {
- sprintf(source_name, "%s_%d", hostname_string, nf_port);
- }
-
- cJSON *common_event_header = ves_create_common_event_header("pnfRegistration", "EventType5G", source_name, "Normal", ves_pnf_sequence_number++);
+ cJSON *common_event_header = ves_create_common_event_header("pnfRegistration", "EventType5G", hostname_string, nf_port, "Normal", ves_pnf_sequence_number++);
if(common_event_header == 0) {
log_error("could not create cJSON object\n");
cJSON_Delete(post_data_json);
return NTS_ERR_FAILED;
}
+
+ if(nf_port == 0) {
+ if(mp == DOCKER_MAPPING) {
+ nf_port = STANDARD_NETCONF_PORT;
+ }
+ else {
+ if(is_tls) {
+ nf_port = framework_environment.host.tls_base_port;
+ }
+ else {
+ nf_port = framework_environment.host.ssh_base_port;
+ }
+ }
+ }
if(cJSON_AddItemToObject(event, "commonEventHeader", common_event_header) == 0) {
log_error("cJSON_AddItemToObject failed\n");
#define NTS_NETWORK_FUNCTION_VES_SCHEMA_XPATH "/nts-network-function:simulation/network-function/ves"
-cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *source_name, const char *priority, int seq_id) {
+cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *hostname, int port, const char *priority, int seq_id) {
assert(domain);
assert(event_type);
- assert(source_name);
+ assert(hostname);
assert(priority);
char *eventId = 0;
return 0;
}
+ char source_name[512];
+ if(port) {
+ sprintf(source_name, "%s-%d", hostname, port);
+ }
+ else {
+ sprintf(source_name, "%s", hostname);
+ }
+
if(cJSON_AddStringToObject(common_event_header, "reportingEntityName", source_name) == 0) {
log_error("cJSON AddStringToObject error\n");
cJSON_Delete(common_event_header);
char *auth_method;
} controller_details_t;
-cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *source_name, const char *priority, int seq_id);
+cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *hostname, int port, const char *priority, int seq_id);
nts_mount_point_addressing_method_t nts_mount_point_addressing_method_get(sr_session_ctx_t *current_session);