Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// ----------------------------------------------------------------------------------

#define TOOL_NAME "NTTTCP for Linux"
#define TOOL_VERSION "1.4.3"
#define TOOL_VERSION "1.4.6"
#define AUTHOR_NAME "Shihua (Simon) Xiao, sixiao@microsoft.com"

#define TCP SOCK_STREAM
Expand Down
22 changes: 21 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,23 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
reply_received = query_receiver_busy_state(tep->synch_socket);
if (reply_received == -1) {
PRINT_ERR("sender: failed to query receiver state");
if (test->no_synch == false)
close(tep->synch_socket);
return ERROR_GENERAL;
}
if (reply_received == 1) {
PRINT_ERR("sender: receiver is busy with another test");
if (test->no_synch == false)
close(tep->synch_socket);
return ERROR_GENERAL;
}

reply_received = negotiate_test_cycle_time(tep->synch_socket,
test->warmup + test->duration + test->cooldown);
if (reply_received == -1) {
PRINT_ERR("sender: failed to negotiate test cycle time with receiver");
if (test->no_synch == false)
close(tep->synch_socket);
return ERROR_GENERAL;
}
if (reply_received != test->duration) {
Expand Down Expand Up @@ -145,10 +151,14 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
tep->test->last_client ? (int)'L' : (int)'R');
if (reply_received == -1) {
PRINT_ERR("sender: failed to sync with receiver to start test");
if (test->no_synch == false)
close(tep->synch_socket);
return ERROR_GENERAL;
}
if (reply_received == 0) {
PRINT_ERR("sender: receiver refuse to start test right now");
if (test->no_synch == false)
close(tep->synch_socket);
return ERROR_GENERAL;
}

Expand All @@ -162,6 +172,8 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
if (tep->negotiated_test_cycle_time == 0) {
sleep(UINT_MAX);
/* either sleep has elapsed, or sleep was interrupted by a signal */
if (test->no_synch == false)
close(tep->synch_socket);
return err_code;
}

Expand Down Expand Up @@ -333,7 +345,15 @@ int main(int argc, char **argv)
exit(-1);
}

default_ntttcp_test(test);
// Handle error return from default_ntttcp_test
err_code = default_ntttcp_test(test);
if (err_code != NO_ERROR) {
PRINT_ERR("main: error when initializing default test parameters");
free(test->bind_address);
free(test);
exit(err_code);
}
Comment on lines +348 to +355

err_code = parse_arguments(test, argc, argv);
if (err_code != NO_ERROR) {
PRINT_ERR("main: error when parsing args");
Expand Down
14 changes: 12 additions & 2 deletions src/ntttcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ntttcp_test *new_ntttcp_test()
return test;
}

void default_ntttcp_test(struct ntttcp_test *test)
int default_ntttcp_test(struct ntttcp_test *test)
{
test->server_role = false;
test->client_role = false;
Expand All @@ -29,7 +29,6 @@ void default_ntttcp_test(struct ntttcp_test *test)
test->use_client_address = false;
test->exit_after_done = true;
test->mapping = "16,*,*";
test->bind_address = "0.0.0.0";
test->client_address = "0.0.0.0";
test->cpu_affinity = -1; /* no hard cpu affinity */
test->server_ports = DEFAULT_NUM_SERVER_PORTS; //default:16 */
Expand Down Expand Up @@ -59,6 +58,15 @@ void default_ntttcp_test(struct ntttcp_test *test)
test->json_log_filename = DEFAULT_JSON_LOG_FILE_NAME; /* "ntttcp-for-linux-log.json" */
test->quiet = false;
test->verbose = false;

/* Allocate bind_address last to ensure all other fields are initialized if allocation fails */
test->bind_address = strdup("0.0.0.0");
if (!test->bind_address) {
PRINT_ERR("failed to allocate memory for bind_address in defaults");
return ERROR_MEMORY_ALLOC;
}
Comment on lines +62 to +67

return NO_ERROR;
}

bool is_running_tty(void)
Expand Down Expand Up @@ -228,6 +236,8 @@ void free_ntttcp_test_endpoint_and_test(struct ntttcp_test_endpoint *e)

for (i = 0; i < total_threads; i++)
free(e->results->threads[i]);

free(e->results->threads);
free(e->results->init_cpu_usage);
free(e->results->init_cpu_ps);
free(e->results->init_tcp_retrans);
Expand Down
2 changes: 1 addition & 1 deletion src/ntttcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct ntttcp_stream_server{
};

struct ntttcp_test *new_ntttcp_test();
void default_ntttcp_test(struct ntttcp_test *test);
int default_ntttcp_test(struct ntttcp_test *test);

struct ntttcp_test_endpoint *new_ntttcp_test_endpoint(struct ntttcp_test *test, int endpoint_role);
void set_ntttcp_test_endpoint_test_continuous(struct ntttcp_test_endpoint* e);
Expand Down
62 changes: 39 additions & 23 deletions src/udpstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ void *run_ntttcp_sender_udp4_stream(struct ntttcp_stream_client *sc)
serv_addr.sin_addr.s_addr = inet_addr(sc->bind_address);
}

if (sc->use_client_address) {
/* get interface name using the interface ip address */
if (get_interface_name_by_ip(sc->client_address, sc->domain, if_name, IFNAMSIZ) != 0) {
ASPRINTF(&log, "failed to get interface name by address [%s]", sc->client_address);
PRINT_ERR(log);
return NULL;
}
}
if (sc->use_client_address) {
/* get interface name using the interface ip address */
if (get_interface_name_by_ip(sc->client_address, sc->domain, if_name, IFNAMSIZ) != 0) {
ASPRINTF(&log, "failed to get interface name by address [%s]", sc->client_address);
PRINT_ERR_FREE(log);
Comment on lines +54 to +58
return NULL;
}
}

/* update client information */
if (ntttcp_update_client_info(&client_addr, sc) < 0) {
ASPRINTF(&log, "failed to update udp client info [%s]", sc->client_address);
PRINT_ERR(log);
return NULL;
}
/* update client information */
if (ntttcp_update_client_info(&client_addr, sc) < 0) {
ASPRINTF(&log, "failed to update udp client info [%s]", sc->client_address);
PRINT_ERR_FREE(log);
return NULL;
}

for (i = 0; i < sc->num_connections; i++) {

if ((sockfd = socket(sc->domain, sc->domain, 0)) < 0) {
if ((sockfd = socket(sc->domain, UDP, 0)) < 0) {
PRINT_ERR("cannot create socket endpoint");
sockfds[i] = -1;
continue;
Expand All @@ -88,7 +88,7 @@ void *run_ntttcp_sender_udp4_stream(struct ntttcp_stream_client *sc)
if (ret != 0) {
ASPRINTF(&log, "failed to do udp socket bind : socket domain [%d] client_port [%d] errno [%d]",
sc->domain, client_port, errno);
PRINT_ERR(log);
PRINT_ERR_FREE(log);
close(sockfd);
sockfds[i] = -1;
continue;
Expand All @@ -100,7 +100,7 @@ void *run_ntttcp_sender_udp4_stream(struct ntttcp_stream_client *sc)
if (ret != NO_ERROR) {
ASPRINTF(&log, "failed to do udp socket bind to device : socket domain [%d] client_port [%d] errno [%d] if_name [%s]",
sc->domain, client_port, errno, if_name);
PRINT_ERR(log);
PRINT_ERR_FREE(log);
close(sockfd);
sockfds[i] = -1;
continue;
Expand All @@ -114,7 +114,7 @@ void *run_ntttcp_sender_udp4_stream(struct ntttcp_stream_client *sc)
if (connect(sockfd, &serv_addr, sa_size) == -1) {
ASPRINTF(&log,"failed to connect socket[%d] to remote: [%s:%d]. errno = %d.",
sockfd, sc->bind_address, sc->server_port, errno);
PRINT_ERR(log);
PRINT_ERR_FREE(log);
close(sockfd);
sockfds[i] = -1;
continue;
Expand Down Expand Up @@ -195,7 +195,7 @@ void *run_ntttcp_receiver_udp4_stream(struct ntttcp_stream_server *ss)
char *log;

int ret = 0; /* hold function return value */
int sockfd = 0; /* socket file descriptor */
int sockfd = -1; /* socket file descriptor */
char *buffer; /* receive buffer */
char *local_addr_str; /* used to get local ip address */
int ip_addr_max_size; /* used to get local ip address */
Expand All @@ -214,6 +214,7 @@ void *run_ntttcp_receiver_udp4_stream(struct ntttcp_stream_server *ss)
ASPRINTF(&port_str, "%d", ss->server_port);
if (getaddrinfo(ss->bind_address, port_str, &hints, &serv_info) != 0) {
PRINT_ERR("cannot get address info for receiver");
free(port_str);
return 0;
}
free(port_str);
Expand Down Expand Up @@ -248,20 +249,33 @@ void *run_ntttcp_receiver_udp4_stream(struct ntttcp_stream_server *ss)
"failed to bind the socket to local address: %s on socket: %d. return = %d",
local_addr_str = retrive_ip_address_str((struct sockaddr_storage *)p->ai_addr, local_addr_str, ip_addr_max_size), sockfd, ret);

if (ret == -1) /* append more info to log */
ASPRINTF(&log, "%s. errcode = %d", log, errno);
PRINT_DBG_FREE(log);
if (ret == -1 && log != NULL) { /* append more info to log */
char *old_log = log;
ASPRINTF(&log, "%s. errcode = %d", old_log, errno);
if (log != NULL) {
free(old_log);
} else {
log = old_log; /* restore original message if second ASPRINTF failed */
}
}
if (log != NULL)
PRINT_DBG_FREE(log);
close(sockfd);
sockfd = -1;
continue;
} else {
break; /* connected */
}
}

freeaddrinfo(serv_info);
free(local_addr_str);

if (p == NULL) {
ASPRINTF(&log, "cannot bind the socket on address: %s", ss->bind_address);
PRINT_ERR_FREE(log);
close(sockfd);
if (sockfd >= 0)
close(sockfd);
return 0;
}

Expand Down Expand Up @@ -291,5 +305,7 @@ void *run_ntttcp_receiver_udp4_stream(struct ntttcp_stream_server *ss)
}
}

free(buffer);
close(sockfd);
return (void *)nbytes;
}
Loading
Loading